[Zope3-checkins]
SVN: zope.testing/trunk/src/zope/testing/testrunner
fix broken --auto-color handling;
options are processed differently than I
Benji York
benji at zope.com
Wed Jul 18 09:22:55 EDT 2007
Log message for revision 78107:
fix broken --auto-color handling; options are processed differently than I
expected. One problem, I couldn't figure out an automated way of testing this,
suggestions accepted
Changed:
U zope.testing/trunk/src/zope/testing/testrunner-colors.txt
U zope.testing/trunk/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner-colors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-colors.txt 2007-07-18 13:21:52 UTC (rev 78106)
+++ zope.testing/trunk/src/zope/testing/testrunner-colors.txt 2007-07-18 13:22:54 UTC (rev 78107)
@@ -268,7 +268,6 @@
Tear down samplelayers.Layer1 in 0.000 seconds.
False
-
Clean up:
>>> sys.stdout = real_stdout
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2007-07-18 13:21:52 UTC (rev 78106)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2007-07-18 13:22:54 UTC (rev 78107)
@@ -806,7 +806,7 @@
def run(defaults=None, args=None):
if args is None:
- args = sys.argv
+ args = sys.argv[:]
# Set the default logging policy.
# XXX There are no tests for this logging behavior.
@@ -1977,9 +1977,6 @@
######################################################################
# Reporting
-def handle_auto_color(option, opt_str, value, parser):
- parser.values.color = sys.stdout.isatty()
-
reporting = optparse.OptionGroup(parser, "Reporting", """\
Reporting options control basic aspects of test-runner output
""")
@@ -2016,8 +2013,11 @@
counter a previous use of --color or -c.
""")
+# 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 the option anyway.
reporting.add_option(
- '--auto-color', action="callback", callback=handle_auto_color,
+ '--auto-color', action="callback", callback=lambda *args: None,
help="""\
Colorize the output, but only when stdout is a terminal.
""")
@@ -2291,7 +2291,6 @@
]
def get_options(args=None, defaults=None):
-
default_setup, _ = parser.parse_args(default_setup_args)
assert not _
if defaults:
@@ -2303,8 +2302,22 @@
if args is None:
args = sys.argv
+
+ # Because we want to inspect stdout and decide to colorize or not, we
+ # replace the --auto-color option with the appropriate --color or
+ # --no-color option. That way the subprocess doesn't have to decide (which
+ # it would do incorrectly anyway because stdout wouled be a pipe).
+ if '--auto-color' in args:
+ if sys.stdout.isatty():
+ colorization = '--color'
+ else:
+ colorization = '--no-color'
+
+ args = [arg.replace('--auto-color', colorization) for arg in args]
+
original_testrunner_args = args
args = args[1:]
+
options, positional = parser.parse_args(args)
merge_options(options, defaults)
options.original_testrunner_args = original_testrunner_args
More information about the Zope3-Checkins
mailing list