[svn r38030] Refactor this test to use new testing service

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-06 21:13:57 +01:00
parent 8fd09aac24
commit 439b0c2378
1 changed files with 96 additions and 133 deletions

View File

@ -5,47 +5,11 @@ import example1
from py.__.test.rsession.executor import RunExecutor, BoxExecutor,\ from py.__.test.rsession.executor import RunExecutor, BoxExecutor,\
AsyncExecutor, ApigenExecutor AsyncExecutor, ApigenExecutor
from py.__.test.rsession.outcome import ReprOutcome from py.__.test.rsession.outcome import ReprOutcome
from py.__.test.rsession.testing.test_slave import funcprint_spec, \ from py.__.test.rsession.testing.runtest import BasicRsessionTest
funcprintfail_spec
def setup_module(mod): #def setup_module(mod):
mod.rootdir = py.path.local(py.__file__).dirpath().dirpath() # mod.rootdir = py.path.local(py.__file__).dirpath().dirpath()
mod.config = py.test.config._reparse([mod.rootdir]) # mod.config = py.test.config._reparse([mod.rootdir])
def XXXtest_executor_passing_function():
ex = Executor(example1.f1)
outcome = ex.execute()
assert outcome.passed
def XXXtest_executor_raising_function():
ex = Executor(example1.g1)
outcome = ex.execute()
assert not outcome.passed
excinfo = outcome.excinfo
assert excinfo.type == ValueError
def XXXtest_executor_traceback():
ex = Executor(example1.g1)
outcome = ex.execute()
excinfo = outcome.excinfo
assert len(excinfo.traceback) == 2
assert excinfo.traceback[1].frame.code.name == 'g2'
assert excinfo.traceback[0].frame.code.name == 'g1'
def XXX_test_executor_setup_passing():
ex = Executor(example1.f1, setup=lambda: None)
outcome = ex.execute()
assert outcome.passed
assert not outcome.setupfailure
def XXX_test_executor_setup_failing():
def failingsetup():
raise ValueError
ex = Executor(example1.f1, setup=failingsetup)
outcome = ex.execute()
assert not outcome.passed
assert outcome.setupfailure
assert outcome.excinfo.traceback[-1].frame.code.name == 'failingsetup'
class ItemTestPassing(py.test.Item): class ItemTestPassing(py.test.Item):
def run(self): def run(self):
@ -59,112 +23,111 @@ class ItemTestSkipping(py.test.Item):
def run(self): def run(self):
py.test.skip("hello") py.test.skip("hello")
def test_run_executor(): class TestExecutor(BasicRsessionTest):
ex = RunExecutor(ItemTestPassing("pass"), config=config) def test_run_executor(self):
outcome = ex.execute() ex = RunExecutor(ItemTestPassing("pass"), config=self.config)
assert outcome.passed outcome = ex.execute()
assert outcome.passed
ex = RunExecutor(ItemTestFailing("fail"), config=config) ex = RunExecutor(ItemTestFailing("fail"), config=self.config)
outcome = ex.execute() outcome = ex.execute()
assert not outcome.passed assert not outcome.passed
ex = RunExecutor(ItemTestSkipping("skip"), config=config) ex = RunExecutor(ItemTestSkipping("skip"), config=self.config)
outcome = ex.execute() outcome = ex.execute()
assert outcome.skipped assert outcome.skipped
assert not outcome.passed assert not outcome.passed
assert not outcome.excinfo assert not outcome.excinfo
def test_box_executor(): def test_box_executor(self):
ex = BoxExecutor(ItemTestPassing("pass"), config=config) ex = BoxExecutor(ItemTestPassing("pass"), config=self.config)
outcome_repr = ex.execute() outcome_repr = ex.execute()
outcome = ReprOutcome(outcome_repr) outcome = ReprOutcome(outcome_repr)
assert outcome.passed assert outcome.passed
ex = BoxExecutor(ItemTestFailing("fail"), config=config) ex = BoxExecutor(ItemTestFailing("fail"), config=self.config)
outcome_repr = ex.execute() outcome_repr = ex.execute()
outcome = ReprOutcome(outcome_repr) outcome = ReprOutcome(outcome_repr)
assert not outcome.passed assert not outcome.passed
ex = BoxExecutor(ItemTestSkipping("skip"), config=config) ex = BoxExecutor(ItemTestSkipping("skip"), config=self.config)
outcome_repr = ex.execute() outcome_repr = ex.execute()
outcome = ReprOutcome(outcome_repr) outcome = ReprOutcome(outcome_repr)
assert outcome.skipped assert outcome.skipped
assert not outcome.passed assert not outcome.passed
assert not outcome.excinfo assert not outcome.excinfo
def test_box_executor_stdout(): def test_box_executor_stdout(self):
rootcol = py.test.collect.Directory(rootdir) item = self.rootcol._getitembynames(self.funcprint_spec)
item = rootcol._getitembynames(funcprint_spec) ex = BoxExecutor(item, config=self.config)
ex = BoxExecutor(item, config=config) outcome_repr = ex.execute()
outcome_repr = ex.execute() outcome = ReprOutcome(outcome_repr)
outcome = ReprOutcome(outcome_repr) assert outcome.passed
assert outcome.passed assert outcome.stdout.find("samfing") != -1
assert outcome.stdout.find("samfing") != -1
def test_box_executor_stdout_error(): def test_box_executor_stdout_error(self):
rootcol = py.test.collect.Directory(rootdir) item = self.rootcol._getitembynames(self.funcprintfail_spec)
item = rootcol._getitembynames(funcprintfail_spec) ex = BoxExecutor(item, config=self.config)
ex = BoxExecutor(item, config=config) outcome_repr = ex.execute()
outcome_repr = ex.execute() outcome = ReprOutcome(outcome_repr)
outcome = ReprOutcome(outcome_repr) assert not outcome.passed
assert not outcome.passed assert outcome.stdout.find("samfing elz") != -1
assert outcome.stdout.find("samfing elz") != -1
def test_cont_executor(): def test_cont_executor(self):
rootcol = py.test.collect.Directory(rootdir) item = self.rootcol._getitembynames(self.funcprintfail_spec)
item = rootcol._getitembynames(funcprintfail_spec) ex = AsyncExecutor(item, config=self.config)
ex = AsyncExecutor(item, config=config) cont, pid = ex.execute()
cont, pid = ex.execute() assert pid
assert pid outcome_repr = cont()
outcome_repr = cont() outcome = ReprOutcome(outcome_repr)
outcome = ReprOutcome(outcome_repr) assert not outcome.passed
assert not outcome.passed assert outcome.stdout.find("samfing elz") != -1
assert outcome.stdout.find("samfing elz") != -1
def test_apigen_executor(): def test_apigen_executor(self):
class Tracer(object): class Tracer(object):
def __init__(self): def __init__(self):
self.starts = 0 self.starts = 0
self.ends = 0 self.ends = 0
def start_tracing(self): def start_tracing(self):
self.starts += 1 self.starts += 1
def end_tracing(self): def end_tracing(self):
self.ends += 1 self.ends += 1
tmpdir = py.test.ensuretemp("apigen_executor") tmpdir = py.test.ensuretemp("apigen_executor")
tmpdir.ensure("__init__.py") tmpdir.ensure("__init__.py")
tmpdir.ensure("test_one.py").write(py.code.Source(""" tmpdir.ensure("test_one.py").write(py.code.Source("""
def g(): def g():
pass pass
def test_1(): def test_1():
g() g()
class TestX(object): class TestX(object):
def setup_method(self, m): def setup_method(self, m):
self.ttt = 1 self.ttt = 1
def test_one(self): def test_one(self):
self.ttt += 1 self.ttt += 1
def test_raise(self): def test_raise(self):
1/0 1/0
""")) """))
rootcol = py.test.collect.Directory(tmpdir) config = py.test.config._reparse([tmpdir])
tracer = Tracer() rootcol = config._getcollector(tmpdir)
item = rootcol._getitembynames("test_one.py/test_1") tracer = Tracer()
ex = ApigenExecutor(item, config=config) item = rootcol._getitembynames("test_one.py/test_1")
out1 = ex.execute(tracer) ex = ApigenExecutor(item, config=config)
item = rootcol._getitembynames("test_one.py/TestX/()/test_one") out1 = ex.execute(tracer)
ex = ApigenExecutor(item, config=config) item = rootcol._getitembynames("test_one.py/TestX/()/test_one")
out2 = ex.execute(tracer) ex = ApigenExecutor(item, config=config)
item = rootcol._getitembynames("test_one.py/TestX/()/test_raise") out2 = ex.execute(tracer)
ex = ApigenExecutor(item, config=config) item = rootcol._getitembynames("test_one.py/TestX/()/test_raise")
out3 = ex.execute(tracer) ex = ApigenExecutor(item, config=config)
assert tracer.starts == 3 out3 = ex.execute(tracer)
assert tracer.ends == 3 assert tracer.starts == 3
assert out1.passed assert tracer.ends == 3
assert out2.passed assert out1.passed
assert not out3.passed assert out2.passed
assert not out3.passed