From fd40b43cdf10c85dcf6966c3c54c69724e4fb9d2 Mon Sep 17 00:00:00 2001 From: guido Date: Sat, 27 Jan 2007 16:37:43 +0100 Subject: [PATCH] [svn r37438] Fiddle-fixed --rest, although it works now some cleanups would be nice... Cleaned up the tests a bit and re-enabled some (sucky tests are better than no tests at all, I guess... :| ), re-enabled a debug print after complaints from cfbolz ;) but this time it prints to stderr (to avoid ReST pollution). --HG-- branch : trunk --- py/test/conftesthandle.py | 2 +- py/test/rsession/outcome.py | 5 +- py/test/rsession/rest.py | 8 ++- py/test/rsession/testing/test_rest.py | 75 +++++++++++++++------------ 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/py/test/conftesthandle.py b/py/test/conftesthandle.py index 4f51549f6..102413f33 100644 --- a/py/test/conftesthandle.py +++ b/py/test/conftesthandle.py @@ -26,7 +26,7 @@ class Conftest(object): for arg in args + [current]: anchor = current.join(arg, abs=1) if anchor.check(): # we found some file object - #print "initializing conftest from", anchor + print >>py.std.sys.stderr, "initializing conftest from", anchor # conftest-lookups without a path actually mean # lookups with our initial path. self._path2confmods[None] = self.getconftestmodules(anchor) diff --git a/py/test/rsession/outcome.py b/py/test/rsession/outcome.py index 741be2b4e..bdc8f6af1 100644 --- a/py/test/rsession/outcome.py +++ b/py/test/rsession/outcome.py @@ -27,7 +27,10 @@ class Outcome(object): tb_info = [self.traceback_entry_repr(x, tbstyle) for x in excinfo.traceback] rec_index = excinfo.traceback.recursionindex() - return (excinfo.type.__name__, str(excinfo.value), (tb_info, rec_index)) + etype = excinfo.type + if hasattr(etype, '__name__'): + etype = etype.__name__ + return (etype, str(excinfo.value), (tb_info, rec_index)) def traceback_entry_repr(self, tb_entry, tb_style): lineno = tb_entry.lineno diff --git a/py/test/rsession/rest.py b/py/test/rsession/rest.py index 38d370309..514bf565f 100644 --- a/py/test/rsession/rest.py +++ b/py/test/rsession/rest.py @@ -140,7 +140,10 @@ class RestReporter(AbstractReporter): self.add_rest(ListItem('%s: %s' % (item, text))) def get_host(self, event): - return event.channel.gateway.host + try: + return event.channel.gateway.host + except AttributeError: + return None def failures(self): self.traceback_num = 0 @@ -160,7 +163,8 @@ class RestReporter(AbstractReporter): t.add(Link(itempath, link)) else: t.add(Text(itempath)) - t.add(Text('on %s' % (host.hostname,))) + if host: + t.add(Text('on %s' % (host.hostname,))) self.add_rest(t) if event.outcome.signal: self.repr_signal(event.item, event.outcome) diff --git a/py/test/rsession/testing/test_rest.py b/py/test/rsession/testing/test_rest.py index 48093dcb8..0c456b661 100644 --- a/py/test/rsession/testing/test_rest.py +++ b/py/test/rsession/testing/test_rest.py @@ -11,6 +11,11 @@ from py.__.rest.rst import * from py.__.test.rsession.hostmanage import HostInfo from py.__.test.rsession.outcome import Outcome +class Container(object): + def __init__(self, **args): + for arg, val in args.items(): + setattr(self, arg, val) + class RestTestReporter(RestReporter): def __init__(self, *args, **kwargs): if args: @@ -78,11 +83,6 @@ Running tests on hosts\: localhost, foo.com def listnames(self): return ['package', 'foo', 'bar.py'] - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) - parent = Container(parent=None, fspath=py.path.local('.')) event = report.ItemStart(item=FakeModule(parent)) reporter.report(event) @@ -105,11 +105,6 @@ Testing module foo/bar.py (2 items) def test_ReceivedItemOutcome_PASSED(self): outcome = Outcome() - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) - item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz']) event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item) reporter.report(event) @@ -117,11 +112,6 @@ Testing module foo/bar.py (2 items) 'foo.py/bar()/baz\n\n') def test_ReceivedItemOutcome_SKIPPED(self): - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) - outcome = Outcome(skipped="reason") item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz']) event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item) @@ -130,11 +120,6 @@ Testing module foo/bar.py (2 items) 'foo.py/bar()/baz\n\n') def test_ReceivedItemOutcome_FAILED(self): - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) - outcome = Outcome(excinfo="xxx") item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz']) event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item) @@ -143,13 +128,45 @@ Testing module foo/bar.py (2 items) * localhost\: **FAILED** `traceback0`_ foo.py/bar()/baz """ - - def test_skips(self): - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) + def test_ReceivedItemOutcome_FAILED_stdout(self): + excinfo = Container( + typename='FooError', + value='A foo has occurred', + traceback=[ + Container( + path='foo/bar.py', + lineno=1, + relline=1, + source='foo()', + ), + Container( + path='foo/baz.py', + lineno=4, + relline=1, + source='raise FooError("A foo has occurred")', + ), + ] + ) + outcome = Outcome(excinfo=excinfo) + outcome.stdout = '' + outcome.stderr = '' + parent = Container(parent=None, fspath=py.path.local('.')) + item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'], + parent=parent, fspath=py.path.local('foo')) + event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, + item=item) + reporter.report(event) + reporter.timestart = 10 + reporter.timeend = 20 + reporter.timersync = 15 + reporter.print_summary(10, '', '') + + reporter.print_summary(1, 'skipped', 'failed') + out = stdout.getvalue() + assert out.find('') > -1 + + def test_skips(self): class FakeOutcome(Container, report.ReceivedItemOutcome): pass @@ -175,12 +192,6 @@ Reasons for skipped tests\: """ def test_failures(self): - py.test.skip("This one is totally artificial, needs to be rewritten") - class Container(object): - def __init__(self, **args): - for arg, val in args.items(): - setattr(self, arg, val) - class FakeOutcome(Container, report.ReceivedItemOutcome): pass