[py-svn] r48129 - in py/branch/reporter-merge/py/test: . rsession rsession/testing testing
fijal at codespeak.net
fijal at codespeak.net
Sun Oct 28 14:41:07 CET 2007
Author: fijal
Date: Sun Oct 28 14:41:06 2007
New Revision: 48129
Modified:
py/branch/reporter-merge/py/test/reporter.py
py/branch/reporter-merge/py/test/rsession/rest.py
py/branch/reporter-merge/py/test/rsession/testing/test_rest.py
py/branch/reporter-merge/py/test/session.py
py/branch/reporter-merge/py/test/testing/test_reporter.py
Log:
Refactor LocalReporter not to rely on hosts being there
Modified: py/branch/reporter-merge/py/test/reporter.py
==============================================================================
--- py/branch/reporter-merge/py/test/reporter.py (original)
+++ py/branch/reporter-merge/py/test/reporter.py Sun Oct 28 14:41:06 2007
@@ -56,9 +56,6 @@
self.skipped_tests_outcome = []
self.out = getout(py.std.sys.stdout)
self.presenter = Presenter(self.out, config)
- self.failed = dict([(host, 0) for host in hosts])
- self.skipped = dict([(host, 0) for host in hosts])
- self.passed = dict([(host, 0) for host in hosts])
self.to_rsync = {}
def get_item_name(self, event, colitem):
@@ -249,6 +246,9 @@
def summary(self):
def gather(dic):
+ # XXX hack to handle dicts & ints here, get rid of it
+ if isinstance(dic, int):
+ return dic
total = 0
for key, val in dic.iteritems():
total += val
@@ -316,7 +316,13 @@
def was_failure(self):
return sum(self.failed.values()) > 0
-class RemoteReporter(AbstractReporter):
+class RemoteReporter(AbstractReporter):
+ def __init__(self, config, hosts):
+ super(RemoteReporter, self).__init__(config, hosts)
+ self.failed = dict([(host, 0) for host in hosts])
+ self.skipped = dict([(host, 0) for host in hosts])
+ self.passed = dict([(host, 0) for host in hosts])
+
def get_item_name(self, event, colitem):
return event.host.hostname + ":" + \
"/".join(colitem.listnames())
@@ -332,6 +338,13 @@
join(event.item.listnames())))
class LocalReporter(AbstractReporter):
+ def __init__(self, config, hosts=None):
+ assert not hosts
+ super(LocalReporter, self).__init__(config, hosts)
+ self.failed = 0
+ self.skipped = 0
+ self.passed = 0
+
def report_TestStarted(self, item):
colitems = item.config.getcolitems()
txt = " test process starts "
@@ -371,19 +384,18 @@
#self.show_item(event.item, False)
self.out.write("- FAILED TO LOAD MODULE")
self.failed_tests_outcome.append(event)
- self.failed[self.hosts[0]] += 1
+ self.failed += 1
def report_ReceivedItemOutcome(self, event):
- host = self.hosts[0]
if event.outcome.passed:
- self.passed[host] += 1
+ self.passed += 1
self.out.write(".")
elif event.outcome.skipped:
self.skipped_tests_outcome.append(event)
- self.skipped[host] += 1
+ self.skipped += 1
self.out.write("s")
else:
- self.failed[host] += 1
+ self.failed += 1
self.failed_tests_outcome.append(event)
self.out.write("F")
@@ -418,3 +430,6 @@
def hangs(self):
pass
+
+ def was_failure(self):
+ return self.failed > 0
Modified: py/branch/reporter-merge/py/test/rsession/rest.py
==============================================================================
--- py/branch/reporter-merge/py/test/rsession/rest.py (original)
+++ py/branch/reporter-merge/py/test/rsession/rest.py Sun Oct 28 14:41:06 2007
@@ -12,10 +12,13 @@
class RestReporter(AbstractReporter):
linkwriter = None
- def __init__(self, *args, **kwargs):
- super(RestReporter, self).__init__(*args, **kwargs)
+ def __init__(self, config, hosts):
+ super(RestReporter, self).__init__(config, hosts)
self.rest = Rest()
self.traceback_num = 0
+ self.failed = dict([(host, 0) for host in hosts])
+ self.skipped = dict([(host, 0) for host in hosts])
+ self.passed = dict([(host, 0) for host in hosts])
def get_linkwriter(self):
if self.linkwriter is None:
Modified: py/branch/reporter-merge/py/test/rsession/testing/test_rest.py
==============================================================================
--- py/branch/reporter-merge/py/test/rsession/testing/test_rest.py (original)
+++ py/branch/reporter-merge/py/test/rsession/testing/test_rest.py Sun Oct 28 14:41:06 2007
@@ -332,6 +332,9 @@
class TestRestReporter(AbstractTestReporter):
reporter = RestReporter
+ def get_hosts(self):
+ return [HostInfo('localhost')]
+
def test_failed_to_load(self):
py.test.skip("Not implemented")
Modified: py/branch/reporter-merge/py/test/session.py
==============================================================================
--- py/branch/reporter-merge/py/test/session.py (original)
+++ py/branch/reporter-merge/py/test/session.py Sun Oct 28 14:41:06 2007
@@ -122,8 +122,7 @@
def main(self, reporter=None):
""" main loop for running tests. """
config = self.config
- self.reporter, shouldstop = self.init_reporter(reporter,
- config, ['localhost'])
+ self.reporter, shouldstop = self.init_reporter(reporter, config, None)
colitems = self.config.getcolitems()
self.header(colitems)
Modified: py/branch/reporter-merge/py/test/testing/test_reporter.py
==============================================================================
--- py/branch/reporter-merge/py/test/testing/test_reporter.py (original)
+++ py/branch/reporter-merge/py/test/testing/test_reporter.py Sun Oct 28 14:41:06 2007
@@ -75,9 +75,12 @@
outcomes = self.prepare_outcomes()
def boxfun(config, item, outcomes):
- hosts = [HostInfo("localhost")]
+ hosts = self.get_hosts()
r = self.reporter(config, hosts)
- ch = DummyChannel(hosts[0])
+ if hosts:
+ ch = DummyChannel(hosts[0])
+ else:
+ ch = None
for outcome in outcomes:
r.report(repevent.ReceivedItemOutcome(ch, item, outcome))
@@ -93,10 +96,13 @@
outcomes = self.prepare_outcomes()
def boxfun(config, item, funcitem, outcomes):
- hosts = [HostInfo('localhost')]
+ hosts = self.get_hosts()
r = self.reporter(config, hosts)
r.report(repevent.ItemStart(item))
- ch = DummyChannel(hosts[0])
+ if hosts:
+ ch = DummyChannel(hosts[0])
+ else:
+ ch = None
for outcome in outcomes:
r.report(repevent.ReceivedItemOutcome(ch, funcitem, outcome))
@@ -124,7 +130,7 @@
def boxfun():
config = py.test.config._reparse([str(tmpdir)])
rootcol = py.test.collect.Directory(tmpdir)
- hosts = [HostInfo('localhost')]
+ hosts = self.get_hosts()
r = self.reporter(config, hosts)
list(itemgen(MockSession(r), [rootcol], r.report))
@@ -143,9 +149,9 @@
def boxfun():
config = py.test.config._reparse([str(tmpdir)])
rootcol = py.test.collect.Directory(tmpdir)
- host = HostInfo('localhost')
- r = self.reporter(config, [host])
- r.report(repevent.TestStarted([host], config, ["a"]))
+ hosts = self.get_hosts()
+ r = self.reporter(config, hosts)
+ r.report(repevent.TestStarted(hosts, config, ["a"]))
r.report(repevent.RsyncFinished())
list(itemgen(MockSession(r), [rootcol], r.report))
r.report(repevent.TestFinished())
@@ -164,7 +170,7 @@
tmpdir.ensure("test_one.py").write("def test_x(): pass")
cap = py.io.StdCaptureFD()
config = py.test.config._reparse([str(tmpdir), '-v'])
- hosts = [HostInfo("host")]
+ hosts = self.get_hosts()
r = self.reporter(config, hosts)
r.report(repevent.TestStarted(hosts, config, []))
r.report(repevent.RsyncFinished())
@@ -205,6 +211,9 @@
class TestLocalReporter(AbstractTestReporter):
reporter = LocalReporter
+
+ def get_hosts(self):
+ return None
def test_report_received_item_outcome(self):
assert self.report_received_item_outcome() == 'FsF.'
@@ -227,12 +236,15 @@
class TestRemoteReporter(AbstractTestReporter):
reporter = RemoteReporter
+ def get_hosts(self):
+ return [HostInfo("host")]
+
def test_still_to_go(self):
self._test_still_to_go()
def test_report_received_item_outcome(self):
val = self.report_received_item_outcome()
- expected_lst = ["localhost", "FAILED",
+ expected_lst = ["host", "FAILED",
"funcpass", "test_one",
"SKIPPED",
"PASSED"]
@@ -241,7 +253,7 @@
def test_module(self):
val = self._test_module()
- expected_lst = ["localhost", "FAILED",
+ expected_lst = ["host", "FAILED",
"funcpass", "test_one",
"SKIPPED",
"PASSED"]
More information about the pytest-commit
mailing list