2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
""" reporter tests.
|
|
|
|
|
|
|
|
XXX there are a few disabled reporting tests because
|
|
|
|
they test for exact formatting as far as i can see.
|
|
|
|
I think it's rather better to directly invoke a
|
|
|
|
reporter and pass it some hand-prepared events to see
|
|
|
|
that running the reporter doesn't break shallowly.
|
|
|
|
|
|
|
|
Otherwise, i suppose that some "visual" testing can usually be driven
|
|
|
|
manually by user-input. And when passing particular events
|
|
|
|
to a reporter it's also easier to check for one line
|
|
|
|
instead of having to know the order in which things are printed
|
|
|
|
etc.
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import py, os
|
|
|
|
#py.test.skip("in progress")
|
|
|
|
from py.__.test.rsession.rsession import LocalReporter, AbstractSession,\
|
|
|
|
RemoteReporter
|
2007-02-05 07:34:23 +08:00
|
|
|
from py.__.test.rsession import repevent
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.test.rsession.outcome import ReprOutcome, Outcome
|
|
|
|
from py.__.test.rsession.testing.test_slave import funcpass_spec, mod_spec
|
|
|
|
from py.__.test.rsession.hostmanage import HostInfo
|
|
|
|
from py.__.test.rsession.box import Box
|
|
|
|
#from py.__.test.
|
|
|
|
import sys
|
|
|
|
from StringIO import StringIO
|
|
|
|
|
|
|
|
class DummyGateway(object):
|
|
|
|
def __init__(self, host):
|
|
|
|
self.host = host
|
|
|
|
|
|
|
|
class DummyChannel(object):
|
|
|
|
def __init__(self, host):
|
|
|
|
self.gateway = DummyGateway(host)
|
|
|
|
|
|
|
|
class AbstractTestReporter(object):
|
|
|
|
def setup_class(cls):
|
|
|
|
cls.pkgdir = py.path.local(py.__file__).dirpath()
|
|
|
|
|
|
|
|
def prepare_outcomes(self):
|
|
|
|
# possible outcomes
|
|
|
|
try:
|
|
|
|
1/0
|
|
|
|
except:
|
|
|
|
exc = py.code.ExceptionInfo()
|
|
|
|
|
|
|
|
outcomes = [Outcome(()),
|
|
|
|
Outcome(skipped=True),
|
|
|
|
Outcome(excinfo=exc),
|
|
|
|
Outcome()]
|
|
|
|
|
|
|
|
outcomes = [ReprOutcome(outcome.make_repr()) for outcome in outcomes]
|
|
|
|
outcomes[3].signal = 11
|
|
|
|
outcomes[0].passed = False
|
|
|
|
|
|
|
|
return outcomes
|
|
|
|
|
|
|
|
def report_received_item_outcome(self):
|
|
|
|
config = py.test.config._reparse(["some_sub"])
|
|
|
|
# we just go...
|
|
|
|
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
|
2007-02-04 02:29:24 +08:00
|
|
|
item = rootcol._getitembynames(funcpass_spec)
|
2007-01-24 22:24:01 +08:00
|
|
|
outcomes = self.prepare_outcomes()
|
|
|
|
|
|
|
|
def boxfun(config, item, outcomes):
|
|
|
|
hosts = [HostInfo("localhost")]
|
|
|
|
r = self.reporter(config, hosts)
|
|
|
|
ch = DummyChannel(hosts[0])
|
|
|
|
for outcome in outcomes:
|
2007-02-05 07:34:23 +08:00
|
|
|
r.report(repevent.ReceivedItemOutcome(ch, item, outcome))
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-01 23:20:39 +08:00
|
|
|
cap = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
boxfun(config, item, outcomes)
|
|
|
|
out, err = cap.reset()
|
|
|
|
assert not err
|
|
|
|
return out
|
|
|
|
|
|
|
|
def _test_module(self):
|
|
|
|
config = py.test.config._reparse(["some_sub"])
|
|
|
|
# we just go...
|
|
|
|
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
|
2007-02-04 02:29:24 +08:00
|
|
|
funcitem = rootcol._getitembynames(funcpass_spec)
|
|
|
|
moditem = rootcol._getitembynames(mod_spec)
|
2007-01-24 22:24:01 +08:00
|
|
|
outcomes = self.prepare_outcomes()
|
|
|
|
|
|
|
|
def boxfun(pkgdir, config, item, funcitem, outcomes):
|
|
|
|
hosts = [HostInfo('localhost')]
|
|
|
|
r = self.reporter(config, hosts)
|
|
|
|
#r.pkgdir = pkdgir
|
2007-02-05 07:34:23 +08:00
|
|
|
r.report(repevent.ItemStart(item))
|
2007-01-24 22:24:01 +08:00
|
|
|
ch = DummyChannel(hosts[0])
|
|
|
|
for outcome in outcomes:
|
2007-02-05 07:34:23 +08:00
|
|
|
r.report(repevent.ReceivedItemOutcome(ch, funcitem, outcome))
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-01 23:20:39 +08:00
|
|
|
cap = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
boxfun(self.pkgdir, config, moditem, funcitem, outcomes)
|
|
|
|
out, err = cap.reset()
|
|
|
|
assert not err
|
|
|
|
return out
|
|
|
|
|
|
|
|
def _test_full_module(self):
|
|
|
|
tmpdir = py.test.ensuretemp("repmod")
|
|
|
|
tmpdir.ensure("__init__.py")
|
|
|
|
tmpdir.ensure("test_one.py").write(py.code.Source("""
|
|
|
|
def test_x():
|
|
|
|
pass
|
|
|
|
"""))
|
|
|
|
tmpdir.ensure("test_two.py").write(py.code.Source("""
|
|
|
|
import py
|
|
|
|
py.test.skip("reason")
|
|
|
|
"""))
|
|
|
|
tmpdir.ensure("test_three.py").write(py.code.Source("""
|
|
|
|
sadsadsa
|
|
|
|
"""))
|
|
|
|
|
|
|
|
def boxfun():
|
|
|
|
config = py.test.config._reparse([str(tmpdir)])
|
|
|
|
rootcol = py.test.collect.Directory(tmpdir)
|
|
|
|
hosts = [HostInfo('localhost')]
|
|
|
|
r = self.reporter(config, hosts)
|
2007-02-04 02:44:34 +08:00
|
|
|
list(rootcol._tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x)))
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-01 23:20:39 +08:00
|
|
|
cap = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
boxfun()
|
|
|
|
out, err = cap.reset()
|
|
|
|
assert not err
|
|
|
|
return out
|
|
|
|
|
|
|
|
def test_failed_to_load(self):
|
|
|
|
tmpdir = py.test.ensuretemp("failedtoload")
|
|
|
|
tmpdir.ensure("__init__.py")
|
|
|
|
tmpdir.ensure("test_three.py").write(py.code.Source("""
|
|
|
|
sadsadsa
|
|
|
|
"""))
|
|
|
|
def boxfun():
|
|
|
|
config = py.test.config._reparse([str(tmpdir)])
|
|
|
|
rootcol = py.test.collect.Directory(tmpdir)
|
|
|
|
host = HostInfo('localhost')
|
|
|
|
r = self.reporter(config, [host])
|
2007-02-07 02:44:16 +08:00
|
|
|
r.report(repevent.TestStarted([host], config.topdir, ["a"]))
|
2007-02-05 07:34:23 +08:00
|
|
|
r.report(repevent.RsyncFinished())
|
2007-02-04 02:44:34 +08:00
|
|
|
list(rootcol._tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x)))
|
2007-02-05 07:34:23 +08:00
|
|
|
r.report(repevent.TestFinished())
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-01 23:20:39 +08:00
|
|
|
cap = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
boxfun()
|
|
|
|
out, err = cap.reset()
|
|
|
|
assert not err
|
|
|
|
assert out.find("NameError: name 'sadsadsa' is not defined") != -1
|
|
|
|
|
|
|
|
def _test_still_to_go(self):
|
|
|
|
tmpdir = py.test.ensuretemp("stilltogo")
|
|
|
|
tmpdir.ensure("__init__.py")
|
2007-02-01 23:20:39 +08:00
|
|
|
cap = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
config = py.test.config._reparse([str(tmpdir)])
|
|
|
|
hosts = [HostInfo(i) for i in ["host1", "host2", "host3"]]
|
|
|
|
r = self.reporter(config, hosts)
|
2007-02-07 02:44:16 +08:00
|
|
|
r.report(repevent.TestStarted(hosts, config.topdir, ["a", "b", "c"]))
|
2007-02-06 18:31:08 +08:00
|
|
|
for host in hosts:
|
|
|
|
r.report(repevent.HostRSyncRoots(host, ["a", "b", "c"]))
|
|
|
|
for host in hosts:
|
|
|
|
for root in ["a", "b", "c"]:
|
|
|
|
r.report(repevent.HostRSyncRootReady(host, root))
|
2007-01-24 22:24:01 +08:00
|
|
|
out, err = cap.reset()
|
|
|
|
assert not err
|
2007-01-25 00:46:46 +08:00
|
|
|
expected1 = "Test started, hosts: host1, host2, host3"
|
|
|
|
expected2 = """host1: READY (still 2 to go)
|
2007-01-24 22:24:01 +08:00
|
|
|
host2: READY (still 1 to go)
|
|
|
|
host3: READY"""
|
2007-01-25 00:46:46 +08:00
|
|
|
assert out.find(expected1) != -1
|
|
|
|
assert out.find(expected2) != -1
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
class TestLocalReporter(AbstractTestReporter):
|
|
|
|
reporter = LocalReporter
|
|
|
|
|
|
|
|
def test_report_received_item_outcome(self):
|
|
|
|
#py.test.skip("XXX rewrite test to not rely on exact formatting")
|
|
|
|
assert self.report_received_item_outcome() == 'FsF.'
|
|
|
|
|
|
|
|
def test_module(self):
|
|
|
|
#py.test.skip("XXX rewrite test to not rely on exact formatting")
|
2007-01-25 00:46:46 +08:00
|
|
|
output = self._test_module()
|
|
|
|
assert output.find("test_slave") != -1
|
|
|
|
assert output.endswith("FsF."), output
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
def test_full_module(self):
|
|
|
|
#py.test.skip("XXX rewrite test to not rely on exact formatting")
|
|
|
|
received = self._test_full_module()
|
|
|
|
expected = """
|
|
|
|
repmod/test_one.py[1]
|
|
|
|
repmod/test_three.py[0] - FAILED TO LOAD MODULE
|
|
|
|
repmod/test_two.py[0] - skipped (reason)"""
|
|
|
|
assert received.find(expected) != -1
|
|
|
|
|
|
|
|
class TestRemoteReporter(AbstractTestReporter):
|
|
|
|
reporter = RemoteReporter
|
|
|
|
|
|
|
|
def test_still_to_go(self):
|
|
|
|
self._test_still_to_go()
|
|
|
|
|
|
|
|
def test_report_received_item_outcome(self):
|
2007-01-28 18:32:01 +08:00
|
|
|
py.test.skip("XXX rewrite test to not rely on exact formatting")
|
2007-01-24 22:24:01 +08:00
|
|
|
val = self.report_received_item_outcome()
|
2007-01-25 00:46:46 +08:00
|
|
|
expected = """ localhost: FAILED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: SKIPPED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: FAILED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: PASSED py.test.rsession.testing.test_slave.py funcpass
|
2007-01-24 22:24:01 +08:00
|
|
|
"""
|
|
|
|
assert val.find(expected) != -1
|
|
|
|
|
|
|
|
def test_module(self):
|
2007-01-28 18:32:01 +08:00
|
|
|
py.test.skip("XXX rewrite test to not rely on exact formatting")
|
2007-01-24 22:24:01 +08:00
|
|
|
val = self._test_module()
|
|
|
|
print val
|
2007-01-25 00:46:46 +08:00
|
|
|
expected = """ localhost: FAILED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: SKIPPED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: FAILED py.test.rsession.testing.test_slave.py funcpass
|
|
|
|
localhost: PASSED py.test.rsession.testing.test_slave.py funcpass
|
2007-01-24 22:24:01 +08:00
|
|
|
"""
|
|
|
|
assert val.find(expected) != -1
|
|
|
|
|
|
|
|
def test_full_module(self):
|
|
|
|
#py.test.skip("XXX rewrite test to not rely on exact formatting")
|
|
|
|
val = self._test_full_module()
|
|
|
|
assert val.find('FAILED TO LOAD MODULE: repmod/test_three.py\n'\
|
|
|
|
'\nSkipped (reason) repmod/test_two.py') != -1
|