diff options
author | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-16 15:07:51 +0200 |
---|---|---|
committer | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-16 15:07:51 +0200 |
commit | 5293c540df765031ef8747e675c317106aba0c32 (patch) | |
tree | 6a9d4282b331c7d0877ce90f7d60026478276e25 | |
parent | e543924fed0cb07c33403f59f05edfdb59799ca8 (diff) | |
download | logilab-common-5293c540df765031ef8747e675c317106aba0c32.tar.gz |
debug testlib color printing due to unexpected stream (cStringIO)
-rw-r--r-- | test/unittest_configuration.py | 24 | ||||
-rw-r--r-- | testlib.py | 32 |
2 files changed, 40 insertions, 16 deletions
diff --git a/test/unittest_configuration.py b/test/unittest_configuration.py index 9d65664..4de3c6c 100644 --- a/test/unittest_configuration.py +++ b/test/unittest_configuration.py @@ -85,6 +85,30 @@ class ConfigurationTC(TestCase): self.assertEquals(cfg['choice'], 'ye') self.assertEquals(cfg['value'], None) self.assertEquals(cfg['multiple-choice'], ('yo', 'ya')) + + def test_generate_config(self): + file = os.tmpfile() + stream = StringIO() + self.cfg.generate_config(stream) + self.assertLinesEquals(stream.getvalue().strip(), """# test configuration +[Test] + +dothis=yes + +#value= + +# you can also document the option +multiple=yop,yep + +# boom +number=2 + +choice=yo + +multiple-choice=yo,ye + +named=key:val +""") def test_generate_config(self): stream = StringIO() @@ -410,15 +410,15 @@ class SkipAwareTestResult(unittest._TextTestResult): def printErrorList(self, flavour, errors): for (_, descr), (test, err) in zip(self.descrs_for(flavour), errors): #print 'HERRRRRE', type(self.stream) - #if PYGMENTS_FOUND and isatty(self.stream): - # err = highlight(err, lexers.PythonLexer(), - # formatters.terminal.TerminalFormatter()) + if PYGMENTS_FOUND and isatty(self.stream): + err = highlight(err, lexers.PythonLexer(), + formatters.terminal.TerminalFormatter()) self.stream.writeln(self.separator1) - #if os.isatty(self.stream): - # self.stream.writeln("%s: %s" % ( - # textutils.colorize_ansi(flavour, color='red'), descr)) - #else: - self.stream.writeln("%s: %s" % (flavour, descr)) + if isatty(self.stream): + self.stream.writeln("%s: %s" % ( + textutils.colorize_ansi(flavour, color='red'), descr)) + else: + self.stream.writeln("%s: %s" % (flavour, descr)) self.stream.writeln(self.separator2) self.stream.writeln(str(err)) @@ -556,15 +556,15 @@ class SkipAwareTextTestRunner(unittest.TextTestRunner): (run, run != 1 and "s" or "", timeTaken)) self.stream.writeln() if not result.wasSuccessful(): - #if os.isatty(self.stream.fileno()): - # self.stream.write(textutils.colorize_ansi("FAILED", color='red')) - #else: - self.stream.write("FAILED") + if isatty(self.stream): + self.stream.write(textutils.colorize_ansi("FAILED", color='red')) + else: + self.stream.write("FAILED") else: - #if os.isatty(self.stream.fileno()): - # self.stream.write(textutils.colorize_ansi("OK", color='green')) - #else: - self.stream.write("OK") + if isatty(self.stream): + self.stream.write(textutils.colorize_ansi("OK", color='green')) + else: + self.stream.write("OK") failed, errored, skipped = map(len, (result.failures, result.errors, result.skipped)) |