Sfoglia il codice sorgente

Coverage: pass file= to print_function, test Options.help

Nick Pilon 11 anni fa
parent
commit
8cee926b31
3 ha cambiato i file con 15 aggiunte e 2 eliminazioni
  1. 1 1
      supervisor/compat.py
  2. 1 1
      supervisor/options.py
  3. 13 0
      supervisor/tests/test_options.py

+ 1 - 1
supervisor/compat.py

@@ -23,7 +23,7 @@ else:
     def as_string(s): return s if isinstance(s, unicode) else s.decode('utf-8')
     reduce = reduce
 
-def print_function(*args,**kwargs): sys.stdout.write(' '.join(str(i) for i in args)+kwargs.get('end','\n'))
+def print_function(*args,**kwargs): kwargs.get('file', sys.stdout).write(' '.join(str(i) for i in args)+kwargs.get('end','\n'))
 
 def total_ordering(cls): # pragma: no cover
     """Class decorator that fills in missing ordering methods"""

+ 1 - 1
supervisor/options.py

@@ -135,7 +135,7 @@ class Options:
         help = self.doc + "\n"
         if help.find("%s") > 0:
             help = help.replace("%s", self.progname)
-        print_function(help, end='')
+        print_function(help, end='', file=self.stdout)
         self.exit(0)
 
     def usage(self, msg):

+ 13 - 0
supervisor/tests/test_options.py

@@ -158,6 +158,19 @@ class OptionTests(unittest.TestCase):
         self.assertEqual(config, tempf.name)
         tempf.close()
 
+    def test_help(self):
+        options = self._makeOptions()
+        options.exit = dummy_exit()
+        options.stdout = StringIO()
+        options.progname = 'test_help'
+        options.doc = 'A sample docstring for %s'
+        try:
+            options.help('Argument ignored?')
+        except DummyExitException:
+            self.assertEqual(options.stdout.getvalue(), 'A sample docstring for test_help\n')
+        else:
+            self.fail('help() did not try to exit.')
+
 class ClientOptionsTests(unittest.TestCase):
     def _getTargetClass(self):
         from supervisor.options import ClientOptions