comparison tests/test_command_manager.py @ 28:cff69f571315

Added two unit test suites; one of the tests in one of the suites (for command suggestions) strangely fails at present.
author Atul Varma <varmaa@toolness.com>
date Sat, 23 Feb 2008 09:21:00 -0600
parents
children
comparison
equal deleted inserted replaced
27:943e412a8bd9 28:cff69f571315
1 """
2 Tests for the Command Manager.
3 """
4
5 # ----------------------------------------------------------------------------
6 # Imports
7 # ----------------------------------------------------------------------------
8
9 import unittest
10 import os
11
12 from enso.ui.commands.manager import CommandObjectRegistry
13 from enso.ui.commands.manager import CommandAlreadyRegisteredError
14 from enso.ui.commands.interfaces import CommandExpression
15
16
17 # ----------------------------------------------------------------------------
18 # Object Registry Unit Tests
19 # ----------------------------------------------------------------------------
20
21 class FakeCommand:
22 def __init__( self, name ):
23 self.name = name
24
25 class RegistryTester( unittest.TestCase ):
26 def setUp( self ):
27 self.TESTS = range( ord("a"), ord("z") )
28 self.TESTS = [ chr(i) for i in self.TESTS ]
29
30 self.registry = CommandObjectRegistry()
31 for name in self.TESTS:
32 expr = CommandExpression( name )
33 self.registry.addCommandObj( FakeCommand(name), expr )
34
35
36 def tearDown( self ):
37 self.registry = None
38
39 def testAlreadyRegistered( self ):
40 for name in self.TESTS:
41 expr = CommandExpression( name )
42 self.failUnlessRaises( CommandAlreadyRegisteredError,
43 self.registry.addCommandObj,
44 FakeCommand(name), expr )
45
46 def testRegistered( self ):
47 for name in self.TESTS:
48 cmd = self.registry.getCommandObj( name )
49 self.failUnlessEqual( name, cmd.name )
50
51 self.failUnlessEqual( set( self.registry.getCommandList() ),
52 set( self.TESTS ) )
53
54 # TODO: Match testing.
55 # TODO: Suggestion testing.
56
57
58 # ----------------------------------------------------------------------------
59 # Script
60 # ----------------------------------------------------------------------------
61
62 if __name__ == "__main__":
63 unittest.main()