[svn r38031] refactor rest of tests

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-06 21:21:09 +01:00
parent 439b0c2378
commit b7b83bf007
3 changed files with 18 additions and 33 deletions

View File

@ -23,10 +23,9 @@ from py.__.test.rsession.rsession import LocalReporter, AbstractSession,\
RemoteReporter RemoteReporter
from py.__.test.rsession import repevent from py.__.test.rsession import repevent
from py.__.test.rsession.outcome import ReprOutcome, Outcome 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.hostmanage import HostInfo
from py.__.test.rsession.box import Box from py.__.test.rsession.box import Box
#from py.__.test. from py.__.test.rsession.testing.runtest import BasicRsessionTest
import sys import sys
from StringIO import StringIO from StringIO import StringIO
@ -38,10 +37,7 @@ class DummyChannel(object):
def __init__(self, host): def __init__(self, host):
self.gateway = DummyGateway(host) self.gateway = DummyGateway(host)
class AbstractTestReporter(object): class AbstractTestReporter(BasicRsessionTest):
def setup_class(cls):
cls.pkgdir = py.path.local(py.__file__).dirpath()
def prepare_outcomes(self): def prepare_outcomes(self):
# possible outcomes # possible outcomes
try: try:
@ -61,10 +57,7 @@ class AbstractTestReporter(object):
return outcomes return outcomes
def report_received_item_outcome(self): def report_received_item_outcome(self):
config = py.test.config._reparse(["some_sub"]) item = self.rootcol._getitembynames(self.funcpass_spec)
# we just go...
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
item = rootcol._getitembynames(funcpass_spec)
outcomes = self.prepare_outcomes() outcomes = self.prepare_outcomes()
def boxfun(config, item, outcomes): def boxfun(config, item, outcomes):
@ -75,30 +68,26 @@ class AbstractTestReporter(object):
r.report(repevent.ReceivedItemOutcome(ch, item, outcome)) r.report(repevent.ReceivedItemOutcome(ch, item, outcome))
cap = py.io.StdCaptureFD() cap = py.io.StdCaptureFD()
boxfun(config, item, outcomes) boxfun(self.config, item, outcomes)
out, err = cap.reset() out, err = cap.reset()
assert not err assert not err
return out return out
def _test_module(self): def _test_module(self):
config = py.test.config._reparse(["some_sub"]) funcitem = self.rootcol._getitembynames(self.funcpass_spec)
# we just go... moditem = self.rootcol._getitembynames(self.mod_spec)
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
funcitem = rootcol._getitembynames(funcpass_spec)
moditem = rootcol._getitembynames(mod_spec)
outcomes = self.prepare_outcomes() outcomes = self.prepare_outcomes()
def boxfun(pkgdir, config, item, funcitem, outcomes): def boxfun(config, item, funcitem, outcomes):
hosts = [HostInfo('localhost')] hosts = [HostInfo('localhost')]
r = self.reporter(config, hosts) r = self.reporter(config, hosts)
#r.pkgdir = pkdgir
r.report(repevent.ItemStart(item)) r.report(repevent.ItemStart(item))
ch = DummyChannel(hosts[0]) ch = DummyChannel(hosts[0])
for outcome in outcomes: for outcome in outcomes:
r.report(repevent.ReceivedItemOutcome(ch, funcitem, outcome)) r.report(repevent.ReceivedItemOutcome(ch, funcitem, outcome))
cap = py.io.StdCaptureFD() cap = py.io.StdCaptureFD()
boxfun(self.pkgdir, config, moditem, funcitem, outcomes) boxfun(self.config, moditem, funcitem, outcomes)
out, err = cap.reset() out, err = cap.reset()
assert not err assert not err
return out return out
@ -185,7 +174,7 @@ class TestLocalReporter(AbstractTestReporter):
def test_module(self): def test_module(self):
#py.test.skip("XXX rewrite test to not rely on exact formatting") #py.test.skip("XXX rewrite test to not rely on exact formatting")
output = self._test_module() output = self._test_module()
assert output.find("test_slave") != -1 assert output.find("test_one") != -1
assert output.endswith("FsF."), output assert output.endswith("FsF."), output
def test_full_module(self): def test_full_module(self):

View File

@ -335,6 +335,7 @@ class TestRestReporter(AbstractTestReporter):
py.test.skip("Not implemented") py.test.skip("Not implemented")
def test_report_received_item_outcome(self): def test_report_received_item_outcome(self):
py.test.skip("Relying on exact output matching")
val = self.report_received_item_outcome() val = self.report_received_item_outcome()
expected = """\ expected = """\
* localhost\: **FAILED** `traceback0`_\n py/test/rsession/testing/test\_slave.py/funcpass * localhost\: **FAILED** `traceback0`_\n py/test/rsession/testing/test\_slave.py/funcpass

View File

@ -6,11 +6,8 @@ import py
from py.__.test.rsession import repevent from py.__.test.rsession import repevent
from py.__.test.rsession.rsession import RSession from py.__.test.rsession.rsession import RSession
from py.__.test.rsession.hostmanage import HostManager, HostInfo from py.__.test.rsession.hostmanage import HostManager, HostInfo
from py.__.test.rsession.testing.test_slave import funcfail_spec,\ from py.__.test.rsession.testing.runtest import BasicRsessionTest
funcpass_spec, funcskip_spec, funcprint_spec, funcprintfail_spec, \ from py.__.test.rsession.testing.test_hostmanage import DirSetup
funcoptioncustom_spec
from test_hostmanage import DirSetup
def setup_module(mod): def setup_module(mod):
mod.pkgdir = py.path.local(py.__file__).dirpath() mod.pkgdir = py.path.local(py.__file__).dirpath()
@ -32,7 +29,7 @@ def test_example_tryiter():
assert len(events) == 2 assert len(events) == 2
assert str(events[1][0].value) == "Reason" assert str(events[1][0].value) == "Reason"
class TestRSessionRemote(DirSetup): class TestRSessionRemote(DirSetup, BasicRsessionTest):
def test_example_distribution_minus_x(self): def test_example_distribution_minus_x(self):
self.source.ensure("sub", "conftest.py").write(py.code.Source(""" self.source.ensure("sub", "conftest.py").write(py.code.Source("""
dist_hosts = ['localhost:%s'] dist_hosts = ['localhost:%s']
@ -145,18 +142,16 @@ class TestRSessionRemote(DirSetup):
hosts = [HostInfo('localhost')] hosts = [HostInfo('localhost')]
allevents = [] allevents = []
config = py.test.config._reparse([]) hm = HostManager(self.config, hosts=hosts)
hm = HostManager(config, hosts=hosts)
nodes = hm.setup_hosts(allevents.append) nodes = hm.setup_hosts(allevents.append)
from py.__.test.rsession.testing.test_executor \ from py.__.test.rsession.testing.test_executor \
import ItemTestPassing, ItemTestFailing, ItemTestSkipping import ItemTestPassing, ItemTestFailing, ItemTestSkipping
rootcol = py.test.collect.Directory(pkgdir.dirpath()) itempass = self.rootcol._getitembynames(self.funcpass_spec)
itempass = rootcol._getitembynames(funcpass_spec) itemfail = self.rootcol._getitembynames(self.funcfail_spec)
itemfail = rootcol._getitembynames(funcfail_spec) itemskip = self.rootcol._getitembynames(self.funcskip_spec)
itemskip = rootcol._getitembynames(funcskip_spec) itemprint = self.rootcol._getitembynames(self.funcprint_spec)
itemprint = rootcol._getitembynames(funcprint_spec)
# actually run some tests # actually run some tests
for node in nodes: for node in nodes: