1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
import unittest
from unittests import wtc
import wx
#---------------------------------------------------------------------------
class cmdproc_Tests(wtc.WidgetTestCase):
def test_cmdproc1(self):
with self.assertRaises(TypeError):
cmd = wx.Command()
def test_cmdproc2(self):
class MyCommand(wx.Command):
def Do(self):
return True
def Undo(self):
return True
cmd = MyCommand(name='TestCommand')
def test_cmdproc3(self):
class MyCommand(wx.Command):
def __init__(self, *args, **kw):
wx.Command.__init__(self, *args, **kw)
self.value = False
def Do(self):
self.value = True
return True
def Undo(self):
self.value = False
return True
def CanUndo(self):
return True
cmdproc = wx.CommandProcessor()
for name in 'one two three four five'.split():
cmd = MyCommand(name=name)
cmdproc.Submit(cmd)
cmds = cmdproc.GetCommands()
self.assertEqual(len(cmds), 5)
self.assertEqual([x.value for x in cmds], [True]*5)
self.assertTrue(cmdproc.CanUndo())
self.assertFalse(cmdproc.CanRedo())
cmdproc.Undo()
cmdproc.Undo()
self.assertEqual([x.value for x in cmds], [True]*3 + [False]*2)
self.assertTrue(cmdproc.CanRedo())
cmdproc.Redo()
cmdproc.Redo()
self.assertEqual([x.value for x in cmds], [True]*5)
cmdproc.Undo()
cmdproc.Undo()
cmdproc.Submit(MyCommand(name='NewCmd'))
self.assertEqual(len(cmds), 4)
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
|