[Zodb-checkins] CVS: ZODB3/zdaemon/tests - testzdoptions.py:1.4

Fred L. Drake, Jr. fred@zope.com
Mon, 20 Jan 2003 15:23:24 -0500


Update of /cvs-repository/ZODB3/zdaemon/tests
In directory cvs.zope.org:/tmp/cvs-serv10968

Modified Files:
	testzdoptions.py 
Log Message:
Add tests of the interaction with handler functions.


=== ZODB3/zdaemon/tests/testzdoptions.py 1.3 => 1.4 ===
--- ZODB3/zdaemon/tests/testzdoptions.py:1.3	Mon Jan 20 15:12:30 2003
+++ ZODB3/zdaemon/tests/testzdoptions.py	Mon Jan 20 15:23:21 2003
@@ -110,6 +110,28 @@
         options.add("setting", None, "b", flag=2)
         self.check_exit_code(options, ["-a", "-b"])
 
+    def test_handler_simple(self):
+        # Test that a handler is called; use one that doesn't return None.
+        options = self.OptionsClass()
+        options.add("setting", None, "a:", handler=int)
+        options.realize(["-a2"])
+        self.assertEqual(options.setting, 2)
+
+    def test_handler_side_effect(self):
+        # Test that a handler is called and conflicts are not
+        # signalled when it returns None.
+        options = self.OptionsClass()
+        L = []
+        options.add("setting", None, "a:", "append=", handler=L.append)
+        options.realize(["-a2", "--append", "3"])
+        self.assert_(options.setting is None)
+        self.assertEqual(L, ["2", "3"])
+
+    def test_handler_with_bad_value(self):
+        options = self.OptionsClass()
+        options.add("setting", None, "a:", handler=int)
+        self.check_exit_code(options, ["-afoo"])
+
     def check_exit_code(self, options, args):
         save_sys_stderr = sys.stderr
         try: