[py-svn] r33349 - in py/dist/py/test/rsession: . testing
fijal at codespeak.net
fijal at codespeak.net
Mon Oct 16 22:36:21 CEST 2006
Author: fijal
Date: Mon Oct 16 22:35:56 2006
New Revision: 33349
Modified:
py/dist/py/test/rsession/rsession.py
py/dist/py/test/rsession/testing/test_report.py
py/dist/py/test/rsession/testing/test_reporter.py
Log:
Refactored reporter a bit (not refactored web server - beware)
Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py (original)
+++ py/dist/py/test/rsession/rsession.py Mon Oct 16 22:35:56 2006
@@ -27,7 +27,7 @@
remote_options = RemoteOptions({'we_are_remote':False})
-class Reporter(object):
+class AbstractReporter(object):
def __init__(self, config, hosts):
self.config = config
self.failed_tests_outcome = []
@@ -57,10 +57,7 @@
print "Unknown report: %s" % what
def report_SendItem(self, item):
- if item.channel:
- address = item.channel.gateway.sshaddress
- else:
- address = 'localhost'
+ address = self.get_host(item)
if self.config.option.verbose:
print "Sending %s to %s" % (item.item,
address)
@@ -90,8 +87,6 @@
def hangs(self):
h = []
- if not hasattr(self, 'nodes'):
- return
for node in self.nodes:
h += [(i, node.channel.gateway.sshaddress) for i in node.pending]
if h:
@@ -103,10 +98,7 @@
if self.failed_tests_outcome:
self.out.sep("=", " FAILURES ")
for event in self.failed_tests_outcome:
- if event.channel:
- host = event.channel.gateway.sshaddress
- else:
- host = 'localhost'
+ host = self.get_host(event)
self.out.sep('_', "%s on %s" %
(" ".join(event.item.listnames()), host))
if event.outcome.signal:
@@ -163,11 +155,7 @@
if isinstance(event, report.ReceivedItemOutcome):
outcome = event.outcome
text = outcome.skipped
- if event.channel:
- itemname = event.channel.gateway.sshaddress + ":" + \
- "/".join(colitem.listnames())
- else:
- itemname = "/".join(colitem.listnames())
+ itemname = self.get_item_name(event, colitem)
elif isinstance(event, report.SkippedTryiter):
text = str(event.excinfo.value)
itemname = "/".join(colitem.listnames())
@@ -215,10 +203,7 @@
# XXX: right now we do not do anything with it
def report_ReceivedItemOutcome(self, event):
- if event.channel:
- host = event.channel.gateway.sshaddress
- else:
- host = 'localhost'
+ host = self.get_host(event)
if event.outcome.passed:
status = "PASSED "
self.passed[host] += 1
@@ -231,10 +216,7 @@
self.failed[host] += 1
self.failed_tests_outcome.append(event)
# we'll take care of them later
- if event.channel:
- sshhost = event.channel.gateway.sshaddress
- else:
- sshhost = 'localhost'
+ sshhost = self.get_host(event)
itempath = " ".join(event.item.listnames()[1:])
print "%10s: %s %s" %(sshhost[:10], status, itempath)
@@ -244,6 +226,25 @@
def report_Nodes(self, event):
self.nodes = event.nodes
+class RemoteReporter(AbstractReporter):
+ def get_host(self, item):
+ return item.channel.gateway.sshaddress
+
+ def get_item_name(self, event, colitem):
+ return event.channel.gateway.sshaddress + ":" + \
+ "/".join(colitem.listnames())
+
+
+class LocalReporter(AbstractReporter):
+ def get_host(self, item):
+ return 'localhost'
+
+ def get_item_name(self, event, colitem):
+ return "/".join(colitem.listnames())
+
+ def hangs(self):
+ pass
+
class AbstractSession(object):
"""
An abstract session executes collectors/items through a runner.
@@ -277,7 +278,7 @@
return pkgpath
getpkgdir = staticmethod(getpkgdir)
- def init_reporter(self, reporter, sshhosts):
+ def init_reporter(self, reporter, sshhosts, reporter_class):
try:
# XXX: use it like a command line option, but how?
startserverflag = self.config.getinitialvalue("startserver")
@@ -291,17 +292,12 @@
reporter = exported_methods.report
start_server()
elif reporter is None:
- reporter_instance = Reporter(self.config, sshhosts)
+ reporter_instance = reporter_class(self.config, sshhosts)
reporter = reporter_instance.report
checkfun = lambda : self.config.option.exitfirst and \
reporter_instance.is_failing()
else:
startserverflag = False
- if reporter is None:
- reporter_instance = Reporter(self.config, sshhosts)
- reporter = reporter_instance.report
- checkfun = lambda : self.config.option.exitfirst and \
- reporter_instance.is_failing()
return reporter, checkfun, startserverflag
def reporterror(reporter, data):
@@ -338,7 +334,7 @@
rsync_roots = None # all files and directories in the pkgdir
reporter, checkfun, startserverflag = self.init_reporter(reporter,
- sshhosts)
+ sshhosts, RemoteReporter)
reporter(report.TestStarted(sshhosts))
pkgdir = self.getpkgdir(args[0])
colitems = self.make_colitems(args, baseon=pkgdir.dirpath())
@@ -379,7 +375,7 @@
sshhosts = ['localhost'] # this is just an info to reporter
reporter, checkfun, startserverflag = self.init_reporter(reporter,
- sshhosts)
+ sshhosts, LocalReporter)
reporter(report.TestStarted(sshhosts))
pkgdir = self.getpkgdir(args[0])
Modified: py/dist/py/test/rsession/testing/test_report.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_report.py (original)
+++ py/dist/py/test/rsession/testing/test_report.py Mon Oct 16 22:35:56 2006
@@ -27,10 +27,10 @@
def test_reporter_methods_sanity():
""" Checks if all the methods of reporter are sane
"""
- from py.__.test.rsession.rsession import Reporter
+ from py.__.test.rsession.rsession import RemoteReporter
from py.__.test.rsession import report
- for method in dir(Reporter):
+ for method in dir(RemoteReporter):
if method.startswith("report_") and method != "report_unknown":
assert method[len('report_'):] in report.__dict__
Modified: py/dist/py/test/rsession/testing/test_reporter.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_reporter.py (original)
+++ py/dist/py/test/rsession/testing/test_reporter.py Mon Oct 16 22:35:56 2006
@@ -4,7 +4,7 @@
"""
import py
-from py.__.test.rsession.rsession import Reporter
+from py.__.test.rsession.rsession import RemoteReporter
from py.__.test.rsession.report import ReceivedItemOutcome
from py.__.test.rsession.outcome import ReprOutcome, Outcome
from py.__.test.rsession.testing.test_slave import funcpass_spec
@@ -15,7 +15,7 @@
class TestReporter(object):
def test_report_received_item_outcome(self):
config, args = py.test.Config.parse(["some_sub"])
- r = Reporter(config, ["host"])
+ r = RemoteReporter(config, ["host"])
# possible outcomes
try:
1/0
More information about the pytest-commit
mailing list