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

Fred L. Drake, Jr. fred@zope.com
Mon, 20 Jan 2003 14:40:22 -0500


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

Modified Files:
	testzdoptions.py 
Log Message:
- move general ZDOptions tests here from testzdrun.py
- factor out the exception handling for command line errors
- add test for conflicting flag-setting options


=== ZODB3/zdaemon/tests/testzdoptions.py 1.1 => 1.2 ===
--- ZODB3/zdaemon/tests/testzdoptions.py:1.1	Fri Jan 17 22:51:46 2003
+++ ZODB3/zdaemon/tests/testzdoptions.py	Mon Jan 20 14:40:19 2003
@@ -75,6 +75,36 @@
             else:
                 self.fail("%s didn't call sys.exit()" % repr(arg))
 
+    def test_unrecognized(self):
+        # Check that we get an error for an unrecognized option
+        self.check_exit_code(self.OptionsClass(), ["-/"])
+
+    def test_no_positional_args(self):
+        # Check that we get an error for positional args when they
+        # haven't been enabled.
+        self.check_exit_code(self.OptionsClass(), ["A"])
+
+    def test_conflicting_flags(self):
+        # Check that we get an error for flags which compete over the
+        # same option setting.
+        options = self.OptionsClass()
+        options.add("setting", None, "a", flag=1)
+        options.add("setting", None, "b", flag=2)
+        self.check_exit_code(options, ["-a", "-b"])
+
+    def check_exit_code(self, options, args):
+        save_sys_stderr = sys.stderr
+        try:
+            sys.stderr = StringIO()
+            try:
+                options.realize(args)
+            except SystemExit, err:
+                self.assertEqual(err.code, 2)
+            else:
+                self.fail("SystemExit expected")
+        finally:
+            sys.stderr = save_sys_stderr
+
 def test_suite():
     suite = unittest.TestSuite()
     for cls in [TestZDOptions]: