[Zope3-checkins] SVN: zdaemon/trunk/ made --help option for zdoptions robust in the case that __main__.__doc__

Fred L. Drake, Jr. fdrake at gmail.com
Fri Sep 22 23:58:05 EDT 2006


Log message for revision 70353:
  made --help option for zdoptions robust in the case that __main__.__doc__
  is None
  
  (the release history is seriously confused; need to decipher before
   another release can be made)
  

Changed:
  U   zdaemon/trunk/CHANGES.txt
  U   zdaemon/trunk/src/zdaemon/tests/testzdoptions.py
  U   zdaemon/trunk/src/zdaemon/tests/testzdrun.py
  U   zdaemon/trunk/src/zdaemon/zdoptions.py

-=-
Modified: zdaemon/trunk/CHANGES.txt
===================================================================
--- zdaemon/trunk/CHANGES.txt	2006-09-23 03:39:04 UTC (rev 70352)
+++ zdaemon/trunk/CHANGES.txt	2006-09-23 03:58:04 UTC (rev 70353)
@@ -1,6 +1,12 @@
 zdaemon Changelog
 =================
 
+After some unknown release(???)
+-------------------------------
+
+ - Made 'zdaemon.zdoptions' not fail for --help when __main__.__doc__
+   is None.
+
 After zdaemon 1.1
 -----------------
 
@@ -31,6 +37,6 @@
 zdaemon 1.1 (2005/06/09)
 ------------------------
 
- - SVN tag:  svn+ssh://svn.zope.org/repos/main/zdaemon/tags/zdaemon-1.1
+ - SVN tag:  svn://svn.zope.org/repos/main/zdaemon/tags/zdaemon-1.1
 
  - Tagged to make better 'svn:externals' linkage possible.

Modified: zdaemon/trunk/src/zdaemon/tests/testzdoptions.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testzdoptions.py	2006-09-23 03:39:04 UTC (rev 70352)
+++ zdaemon/trunk/src/zdaemon/tests/testzdoptions.py	2006-09-23 03:58:04 UTC (rev 70353)
@@ -81,8 +81,7 @@
     def test_help(self):
         # __main__.__doc__ is used as the default source of the help
         # text; specific text can also be provided in the `doc`
-        # keyword arg to `realize()`.  It must be provided in one of
-        # those places.
+        # keyword arg to `realize()`.
         import __main__
         old_doc = __main__.__doc__
         __main__.__doc__ = "Example help text 1."
@@ -108,6 +107,29 @@
         finally:
             __main__.__doc__ = old_doc
 
+    def test_no_help(self):
+        # Test that zdoptions doesn't die when __main__.__doc__ is None.
+        import __main__
+        old_doc = __main__.__doc__
+        __main__.__doc__ = None
+        try:
+            for arg in "-h", "--h", "--help":
+                options = self.OptionsClass()
+                try:
+                    self.save_streams()
+                    try:
+                        options.realize([arg])
+                    finally:
+                        self.restore_streams()
+                except SystemExit, err:
+                    self.assertEqual(err.code, 0)
+                else:
+                    self.fail("%s didn't call sys.exit()" % repr(arg))
+                helptext = self.stdout.getvalue()
+                self.assertEqual(helptext, "No help available.")
+        finally:
+            __main__.__doc__ = old_doc
+
     def test_unrecognized(self):
         # Check that we get an error for an unrecognized option
         self.check_exit_code(self.OptionsClass(), ["-/"])

Modified: zdaemon/trunk/src/zdaemon/tests/testzdrun.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2006-09-23 03:39:04 UTC (rev 70352)
+++ zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2006-09-23 03:58:04 UTC (rev 70353)
@@ -138,6 +138,14 @@
         self._run("-h")
         self.expect = __main__.__doc__
 
+    def testNoHelp(self):
+        # XXX We shouldn't mutate and leave our change in!
+        import __main__
+        if __main__.__doc__:
+            __main__.__doc__ = None
+        self._run("-h")
+        self.expect = "No help available."
+
     def testOptionsSysArgv(self):
         # Check that options are parsed from sys.argv by default
         options = zdrun.ZDRunOptions()

Modified: zdaemon/trunk/src/zdaemon/zdoptions.py
===================================================================
--- zdaemon/trunk/src/zdaemon/zdoptions.py	2006-09-23 03:39:04 UTC (rev 70352)
+++ zdaemon/trunk/src/zdaemon/zdoptions.py	2006-09-23 03:58:04 UTC (rev 70353)
@@ -60,7 +60,9 @@
         Occurrences of "%s" in self.doc are replaced by self.progname.
         """
         doc = self.doc
-        if doc.find("%s") > 0:
+        if not doc:
+            doc = "No help available."
+        elif doc.find("%s") > 0:
             doc = doc.replace("%s", self.progname)
         print doc,
         sys.exit(0)



More information about the Zope3-Checkins mailing list