[Zope3-checkins] SVN: zope.testing/trunk/ Added --auto-progress and --no-progress options, similar to --auto-color

Marius Gedminas marius at pov.lt
Sat Jul 21 14:58:32 EDT 2007


Log message for revision 78270:
  Added --auto-progress and --no-progress options, similar to --auto-color
  and --no-color.
  
  It makes sense to enable --progress only when the output is a terminal, just
  like it makes sense to enable --color only when the output is a terminal.
  
  

Changed:
  U   zope.testing/trunk/README.txt
  U   zope.testing/trunk/src/zope/testing/testrunner-progress.txt
  U   zope.testing/trunk/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/trunk/README.txt
===================================================================
--- zope.testing/trunk/README.txt	2007-07-21 15:54:41 UTC (rev 78269)
+++ zope.testing/trunk/README.txt	2007-07-21 18:58:31 UTC (rev 78270)
@@ -68,6 +68,8 @@
 
 - Added --slow-test option.
 
+- Added --no-progress and --auto-progress options.
+
 3.5.0 (2007/07/19)
 ==================
 

Modified: zope.testing/trunk/src/zope/testing/testrunner-progress.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-progress.txt	2007-07-21 15:54:41 UTC (rev 78269)
+++ zope.testing/trunk/src/zope/testing/testrunner-progress.txt	2007-07-21 18:58:31 UTC (rev 78270)
@@ -362,3 +362,67 @@
 Unfortunately, the time data above doesn't buy us much because, in
 practice, the line is cleared before there is time to see the
 times. :/
+
+
+Autodetecting progress
+----------------------
+
+The --auto-progress option will determine if stdout is a terminal, and only enable
+progress output if so.
+
+Let's pretend we have a terminal
+
+    >>> class Terminal(object):
+    ...     def __init__(self, stream):
+    ...         self._stream = stream
+    ...     def __getattr__(self, attr):
+    ...         return getattr(self._stream, attr)
+    ...     def isatty(self):
+    ...         return True
+    >>> real_stdout = sys.stdout
+    >>> sys.stdout = Terminal(sys.stdout)
+
+    >>> sys.argv = 'test -u -t test_one.TestNotMuch --auto-progress'.split()
+    >>> testrunner.run(defaults)
+    Running unit tests:
+      Running:
+        1/6 (16.7%)\r
+                   \r
+        2/6 (33.3%)\r
+                   \r
+        3/6 (50.0%)\r
+                   \r
+        4/6 (66.7%)\r
+                   \r
+        5/6 (83.3%)\r
+                   \r
+        6/6 (100.0%)\r
+                    \r
+    <BLANKLINE>
+      Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.
+    False
+
+Let's stop pretending
+
+    >>> sys.stdout = real_stdout
+
+    >>> sys.argv = 'test -u -t test_one.TestNotMuch --auto-progress'.split()
+    >>> testrunner.run(defaults)
+    Running unit tests:
+      Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.
+    False
+
+
+Disabling progress indication
+-----------------------------
+
+If -p or --progress have been previously provided on the command line (perhaps by a
+wrapper script) but you do not desire progress indication, you can switch it off with
+--no-progress:
+
+    >>> sys.argv = 'test -u -t test_one.TestNotMuch -p --no-progress'.split()
+    >>> testrunner.run(defaults)
+    Running unit tests:
+      Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.
+    False
+

Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2007-07-21 15:54:41 UTC (rev 78269)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2007-07-21 18:58:31 UTC (rev 78270)
@@ -2035,6 +2035,22 @@
 """)
 
 reporting.add_option(
+    '--no-progress',action="store_false", dest='progress',
+    help="""\
+Do not output progress status.  This is the default, but can be used to
+counter a previous use of --progress or -p.
+""")
+
+# We use a noop callback because the actual processing will be done in the
+# get_options function, but we want optparse to generate appropriate help info
+# for us, so we add an option anyway.
+reporting.add_option(
+    '--auto-progress', action="callback", callback=lambda *args: None,
+    help="""\
+Output progress status, but only when stdout is a terminal.
+""")
+
+reporting.add_option(
     '--color', '-c', action="store_true", dest='color',
     help="""\
 Colorize the output.
@@ -2347,8 +2363,21 @@
             args[:] = [arg.replace('--auto-color', colorization)
                        for arg in args]
 
+    # The comment of apply_auto_color applies here as well
+    def apply_auto_progress(args):
+        if args and '--auto-progress' in args:
+            if sys.stdout.isatty():
+                progress = '--progress'
+            else:
+                progress = '--no-progress'
+
+            args[:] = [arg.replace('--auto-progress', progress)
+                       for arg in args]
+
     apply_auto_color(args)
     apply_auto_color(defaults)
+    apply_auto_progress(args)
+    apply_auto_progress(defaults)
 
     default_setup, _ = parser.parse_args(default_setup_args)
     assert not _



More information about the Zope3-Checkins mailing list