[Zodb-checkins] CVS: Zope/lib/python/zdaemon/tests - testzdoptions.py:1.6

Fred L. Drake, Jr. fred@zope.com
Tue, 11 Feb 2003 18:14:09 -0500


Update of /cvs-repository/Zope/lib/python/zdaemon/tests
In directory cvs.zope.org:/tmp/cvs-serv10240/tests

Modified Files:
	testzdoptions.py 
Log Message:
Add support for environment variables overriding values from a
configuration file.


=== Zope/lib/python/zdaemon/tests/testzdoptions.py 1.5 => 1.6 ===
--- Zope/lib/python/zdaemon/tests/testzdoptions.py:1.5	Mon Jan 20 16:40:32 2003
+++ Zope/lib/python/zdaemon/tests/testzdoptions.py	Tue Feb 11 18:14:08 2003
@@ -58,7 +58,7 @@
                                   "sample.conf")
         for arg in "-C", "--c", "--configure":
             options = self.OptionsClass()
-            options.realize(["-C", configfile])
+            options.realize([arg, configfile])
             self.assertEqual(options.configfile, configfile)
 
     def test_help(self):
@@ -147,6 +147,22 @@
         options = self.OptionsClass()
         options.add("setting", None, "a:", handler=int)
         self.check_exit_code(options, ["-afoo"])
+
+    def test_with_environment(self):
+        os.environ["OPT"] = "2"
+        def create():
+            options = self.OptionsClass()
+            options.add("opt", None, "o:", "opt=",
+                        default=42, handler=int, env="OPT")
+            return options
+        for args in (["-o1"], ["--opt", "1"]):
+            options = create()
+            options.realize(args)
+            self.assertEqual(options.opt, 1)
+        options = create()
+        options.realize([])
+        self.assertEqual(options.opt, 2)
+        
 
 def test_suite():
     suite = unittest.TestSuite()