/[thuban]/branches/WIP-pyshapelib-bramz/test/test_command.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/test/test_command.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2734 - (hide annotations)
Thu Mar 1 12:42:59 2007 UTC (18 years ago) by bramz
File MIME type: text/x-python
File size: 3760 byte(s)
made a copy
1 bh 537 # Copyright (c) 2002, 2003 by Intevation GmbH
2 bh 360 # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Test the Command class
10     """
11    
12     __version__ = "$Revision$"
13     # $Source$
14     # $Id$
15    
16    
17     import unittest
18    
19     import support
20     support.initthuban()
21    
22     from Thuban.UI.command import Command, ToolCommand
23    
24     class MockContext:
25    
26     pass
27    
28    
29     class BaseCommandTest(unittest.TestCase):
30    
31     def setUp(self):
32     self.command_args = None
33    
34     def command(self, *args):
35     """Method to use as the command function.
36    
37     Bind all args except self to self.command_args as a tuple.
38     """
39     self.command_args = args
40    
41     def context(self):
42     """Return a context object"""
43     return MockContext()
44    
45     class TestCommand(BaseCommandTest):
46    
47     def test_static_command(self):
48     """Test Command object with no callbacks"""
49     cmd = Command("do_something", "Do Something", self.command)
50     self.assertEquals(cmd.Name(), "do_something")
51     self.assertEquals(cmd.Title(), "Do Something")
52     self.assertEquals(cmd.HelpText(), "")
53     self.assertEquals(cmd.Icon(), "")
54     self.failIf(cmd.IsDynamic())
55     self.failIf(cmd.IsTool())
56    
57     context = self.context()
58     self.assert_(cmd.Sensitive(context))
59     self.failIf(cmd.Checked(context))
60    
61     # Execute the command with just the context
62     cmd.Execute(context)
63     self.assertEquals(self.command_args, (context,))
64    
65     # Execute the command with additional parameters
66     cmd.Execute(context, "abc")
67     self.assertEquals(self.command_args, (context, "abc"))
68    
69     class TestDynamicCommand(BaseCommandTest):
70    
71     def setUp(self):
72     BaseCommandTest.setUp(self)
73     self.is_sensitive = 0
74     self.is_checked = 0
75     self.dynamic_text = ""
76    
77     def sensitive(self, context):
78     return self.is_sensitive
79    
80     def checked(self, context):
81     return self.is_checked
82    
83     def dyntext(self, context):
84     return self.dynamic_text
85    
86     def context(self):
87     """Return a context object"""
88     return MockContext()
89    
90     def test_dynamic_sensitivity(self):
91     """Test Command object with dynamic sensitivity"""
92     cmd = Command("do_something", "Do Something", self.command,
93     sensitive = self.sensitive)
94     self.assert_(cmd.IsDynamic())
95    
96     context = self.context()
97     self.failIf(cmd.Sensitive(context))
98     self.is_sensitive = 1
99     self.assert_(cmd.Sensitive(context))
100    
101     def test_dynamic_checked(self):
102     """Test Command object with dynamic checked flag"""
103     cmd = Command("do_something", "Do Something", self.command,
104     checked = self.checked)
105     self.assert_(cmd.IsDynamic())
106    
107     context = self.context()
108     self.failIf(cmd.Checked(context))
109     self.is_checked = 1
110     self.assert_(cmd.Checked(context))
111    
112     def test_dynamic_title(self):
113     """Test Command object with dynamic title"""
114     cmd = Command("do_something", "Do Something", self.command,
115     dyntext = self.dyntext)
116     self.assert_(cmd.IsDynamic())
117     self.assert_(cmd.HasDynText())
118    
119     context = self.context()
120     self.assertEquals(cmd.DynText(context), "")
121     self.dynamic_text = "A Dynamic Title"
122     self.assertEquals(cmd.DynText(context), "A Dynamic Title")
123    
124     def test_tool_command(self):
125     """Test ToolCommand object"""
126     cmd = ToolCommand("do_something", "Do Something", self.command,
127     checked = self.checked)
128     self.assert_(cmd.IsDynamic())
129     self.assert_(cmd.IsTool())
130    
131 bh 537 if __name__ == "__main__":
132     unittest.main()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26