Changeset 5
- Timestamp:
- 11/18/07 21:08:56 (1 year ago)
- Files:
-
- trunk/src/Pyxoo/commands/locator.py (modified) (1 diff)
- trunk/src/Pyxoo/model (added)
- trunk/src/Pyxoo/model/__init__.py (added)
- trunk/src/Pyxoo/model/locator.py (added)
- trunk/src/Pyxoo/model/model.py (added)
- trunk/src/Pyxoo/view (added)
- trunk/src/Pyxoo/view/__init__.py (added)
- trunk/src/Pyxoo/view/locator.py (added)
- trunk/src/Pyxoo/view/view.py (added)
- trunk/test/commands/TestCommandLocator.py (modified) (2 diffs)
- trunk/test/model (added)
- trunk/test/model/TestModelLocator.py (added)
- trunk/test/model/__init__.py (added)
- trunk/test/view (added)
- trunk/test/view/TestViewLocator.py (added)
- trunk/test/view/__init__.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/Pyxoo/commands/locator.py
r4 r5 39 39 40 40 def locate(self, key): 41 """locate(string): list42 Returns commands list associatedthe passed-in key or None value if key not know by the locator."""41 """locate(string):Command 42 Returns Command associated to the passed-in key or None value if key not know by the locator.""" 43 43 return self.__commands.get(key) 44 44 45 def registerCommand(self, key, commandClass ): 46 """registerCommand(string, class):void 47 Registers passed-in command associated to passed-in key.""" 48 if not Type.isClass( commandClass ): 49 raise TypeError("commandClass param must be a class implementation of Command interface") 50 if not issubclass(commandClass, Command): 51 raise TypeError("commandClass param must be a class implementation of Command interface") 52 if self.isRegistered( key ): 53 if not self.__commands.get(key).__contains__(commandClass): 54 self.__commands.get(key).append(commandClass) 55 else: 56 l = list() 57 l.append(commandClass) 58 self.__commands.__setitem__(key, l) 45 def registerCommand(self, key, command): 46 """registerCommand(string, Command):void 47 Registers passed-in command associated to passed-in key.""" 48 if Type.isClass(command): 49 if not issubclass(command, Command): 50 raise TypeError("command param must be a class implementation of Command interface or Command implementation instance.") 51 elif not isinstance(command, Command): 52 raise TypeError("command param must be a class implementation of Command interface or Command implementation instance.") 53 self.__commands.__setitem__(key, command) 59 54 60 def unregisterCommand(self, key, commandClass): 61 """unregisterCommand(string, class):boolean 62 Unregisters passed-in command associated to passed-in key.""" 63 if not Type.isClass( commandClass ): 64 raise TypeError("commandClass param must be a class implementation of Command interface") 65 if not issubclass(commandClass, Command): 66 raise TypeError("commandClass param must be a class implementation of Command interface") 67 if self.isRegistered( key ): 68 if self.__commands.get(key).__contains__(commandClass): 69 self.__commands.get(key).remove(commandClass) 70 if self.__commands.get(key).__len__() == 0: 71 self.__commands.__delitem__(key) 72 return True 73 return False 74 75 def unregisterCommands(self, key): 76 """unregisterCommands(string):boolean 77 Unregisters all commands associated to the passed-in key.""" 55 def unregisterCommand(self, key): 56 """unregisterCommand(string):void 57 Unregisters command associated to passed-in key.""" 78 58 if self.isRegistered( key ): 79 59 self.__commands.__delitem__(key) 80 return True81 return False82 60 83 61 def __str__(self): trunk/test/commands/TestCommandLocator.py
r4 r5 28 28 class MyCommand2(Command): 29 29 def execute(self, event=None): 30 pass 31 30 pass 31 32 class A:pass 32 33 33 34 class TestCommandLocator(unittest.TestCase): 34 35 def setUp(self): 35 36 self.instance = CommandLocator() 37 self.c1 = MyCommand1() 38 self.c2 = MyCommand2() 36 39 37 40 def testRegisterCommand(self): … … 40 43 self.assertTrue( self.instance.isRegistered("run") ) 41 44 self.instance.registerCommand("run", MyCommand2) 42 self.assertTrue( self.instance.isRegistered("run") ) 45 self.assertTrue( self.instance.isRegistered("run") ) 46 self.instance.registerCommand("run", self.c1) 47 self.assertRaises( TypeError, self.instance.registerCommand, "run", A ) 48 self.assertRaises( TypeError, self.instance.registerCommand, "run", A() ) 43 49 44 50 def testUnregisterCommand(self): 45 51 self.instance.registerCommand("run", MyCommand1) 46 self.instance.registerCommand("run", MyCommand2) 47 self.assertEquals( 2, self.instance.locate("run").__len__() ) 48 self.assertTrue(self.instance.unregisterCommand("run", MyCommand1)) 49 self.assertTrue( self.instance.isRegistered("run") ) 50 self.assertFalse(self.instance.unregisterCommand("run", MyCommand1)) 51 self.assertEquals( 1, self.instance.locate("run").__len__() ) 52 self.assertTrue(self.instance.unregisterCommand("run", MyCommand2)) 53 self.assertFalse( self.instance.isRegistered("run") ) 54 self.assertFalse(self.instance.unregisterCommand("run", MyCommand2)) 55 56 def testUnregisterCommands(self): 57 self.instance.registerCommand("run", MyCommand1) 58 self.instance.registerCommand("run", MyCommand2) 59 self.instance.registerCommand("yop", MyCommand1) 60 self.instance.registerCommand("yop", MyCommand2) 61 self.assertTrue( self.instance.unregisterCommands("run") ) 62 self.assertFalse( self.instance.unregisterCommands("run") ) 63 self.assertFalse( self.instance.isRegistered("run") ) 64 self.assertTrue( self.instance.isRegistered("yop") ) 52 self.instance.registerCommand("plop", MyCommand2) 53 self.assertTrue( self.instance.isRegistered("run") ) 54 self.instance.unregisterCommand("run") 55 self.assertFalse( self.instance.isRegistered("run") ) 56 self.assertTrue(self.instance.isRegistered("plop")) 65 57 66 58 def testLocate(self): 67 59 self.instance.registerCommand("run", MyCommand1) 60 self.assertEquals( MyCommand1, self.instance.locate("run") ) 68 61 self.instance.registerCommand("run", MyCommand2) 69 self.instance.registerCommand("run", MyCommand2) 70 result = self.instance.locate("run") 71 self.assertEquals( 2, result.__len__()) 72 self.assertEquals( MyCommand1, result[0] ) 73 self.assertEquals( MyCommand2, result[1] ) 62 self.assertEquals( MyCommand2, self.instance.locate("run") ) 74 63 self.assertEquals( None, self.instance.locate("plop") ) 64 65 self.instance.registerCommand("c1", self.c1) 66 self.assertEquals( self.c1, self.instance.locate("c1") ) 75 67 76 68 77 69 78
