2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
import py
|
|
|
|
import example1
|
|
|
|
|
|
|
|
from py.__.test.rsession.executor import RunExecutor, BoxExecutor,\
|
2007-02-01 19:59:47 +08:00
|
|
|
AsyncExecutor, ApigenExecutor
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.test.rsession.outcome import ReprOutcome
|
2007-02-07 04:36:03 +08:00
|
|
|
from py.__.test.rsession.testing.basetest import BasicRsessionTest
|
2007-02-12 23:40:04 +08:00
|
|
|
from py.__.test.outcome import Failed
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-07 23:54:50 +08:00
|
|
|
def setup_module(mod):
|
|
|
|
if py.std.sys.platform == "win32":
|
|
|
|
py.test.skip("skipping executor tests (some require os.fork)")
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-14 03:21:53 +08:00
|
|
|
class Item(py.test.collect.Item):
|
2007-02-11 00:50:47 +08:00
|
|
|
def __init__(self, name, config):
|
|
|
|
super(Item, self).__init__(name)
|
|
|
|
self._config = config
|
|
|
|
|
|
|
|
class ItemTestPassing(Item):
|
2007-01-24 22:24:01 +08:00
|
|
|
def run(self):
|
|
|
|
return None
|
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
class ItemTestFailing(Item):
|
2007-01-24 22:24:01 +08:00
|
|
|
def run(self):
|
|
|
|
assert 0 == 1
|
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
class ItemTestSkipping(Item):
|
2007-01-24 22:24:01 +08:00
|
|
|
def run(self):
|
|
|
|
py.test.skip("hello")
|
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
class ItemTestPrinting(Item):
|
|
|
|
def run(self):
|
|
|
|
print "hello"
|
|
|
|
|
2007-02-12 23:40:04 +08:00
|
|
|
class ItemTestFailingExplicit(Item):
|
|
|
|
def run(self):
|
|
|
|
raise Failed(excinfo="3")
|
|
|
|
|
2007-02-23 22:22:50 +08:00
|
|
|
class ItemTestFailingExplicitEmpty(Item):
|
|
|
|
def run(self):
|
|
|
|
py.test.raises(ValueError, lambda : 123)
|
|
|
|
|
2007-02-07 04:13:57 +08:00
|
|
|
class TestExecutor(BasicRsessionTest):
|
|
|
|
def test_run_executor(self):
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = RunExecutor(ItemTestPassing("pass", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome = ex.execute()
|
|
|
|
assert outcome.passed
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = RunExecutor(ItemTestFailing("fail", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome = ex.execute()
|
|
|
|
assert not outcome.passed
|
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = RunExecutor(ItemTestSkipping("skip", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome = ex.execute()
|
|
|
|
assert outcome.skipped
|
|
|
|
assert not outcome.passed
|
2007-02-11 00:50:47 +08:00
|
|
|
assert not outcome.excinfo
|
|
|
|
|
|
|
|
def test_run_executor_capture(self):
|
|
|
|
ex = RunExecutor(ItemTestPrinting("print", self.config), config=self.config)
|
|
|
|
outcome = ex.execute()
|
|
|
|
assert outcome.stdout == "hello\n"
|
2007-02-07 04:13:57 +08:00
|
|
|
|
|
|
|
def test_box_executor(self):
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = BoxExecutor(ItemTestPassing("pass", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome_repr = ex.execute()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert outcome.passed
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = BoxExecutor(ItemTestFailing("fail", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome_repr = ex.execute()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert not outcome.passed
|
|
|
|
|
2007-02-11 00:50:47 +08:00
|
|
|
ex = BoxExecutor(ItemTestSkipping("skip", self.config), config=self.config)
|
2007-02-07 04:13:57 +08:00
|
|
|
outcome_repr = ex.execute()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert outcome.skipped
|
|
|
|
assert not outcome.passed
|
|
|
|
assert not outcome.excinfo
|
|
|
|
|
|
|
|
def test_box_executor_stdout(self):
|
2007-02-07 04:36:03 +08:00
|
|
|
item = self.getexample("print")
|
2007-02-07 04:13:57 +08:00
|
|
|
ex = BoxExecutor(item, config=self.config)
|
|
|
|
outcome_repr = ex.execute()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert outcome.passed
|
|
|
|
assert outcome.stdout.find("samfing") != -1
|
|
|
|
|
|
|
|
def test_box_executor_stdout_error(self):
|
2007-02-07 04:36:03 +08:00
|
|
|
item = self.getexample("printfail")
|
2007-02-07 04:13:57 +08:00
|
|
|
ex = BoxExecutor(item, config=self.config)
|
|
|
|
outcome_repr = ex.execute()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert not outcome.passed
|
|
|
|
assert outcome.stdout.find("samfing elz") != -1
|
|
|
|
|
|
|
|
def test_cont_executor(self):
|
2007-02-07 04:36:03 +08:00
|
|
|
item = self.getexample("printfail")
|
2007-02-07 04:13:57 +08:00
|
|
|
ex = AsyncExecutor(item, config=self.config)
|
|
|
|
cont, pid = ex.execute()
|
|
|
|
assert pid
|
|
|
|
outcome_repr = cont()
|
|
|
|
outcome = ReprOutcome(outcome_repr)
|
|
|
|
assert not outcome.passed
|
|
|
|
assert outcome.stdout.find("samfing elz") != -1
|
|
|
|
|
|
|
|
def test_apigen_executor(self):
|
|
|
|
class Tracer(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.starts = 0
|
|
|
|
self.ends = 0
|
2007-02-01 19:59:47 +08:00
|
|
|
|
2007-02-07 04:13:57 +08:00
|
|
|
def start_tracing(self):
|
|
|
|
self.starts += 1
|
2007-02-01 19:59:47 +08:00
|
|
|
|
2007-02-07 04:13:57 +08:00
|
|
|
def end_tracing(self):
|
|
|
|
self.ends += 1
|
2007-02-01 19:59:47 +08:00
|
|
|
|
2007-02-07 04:13:57 +08:00
|
|
|
tmpdir = py.test.ensuretemp("apigen_executor")
|
|
|
|
tmpdir.ensure("__init__.py")
|
|
|
|
tmpdir.ensure("test_one.py").write(py.code.Source("""
|
|
|
|
def g():
|
|
|
|
pass
|
2007-02-01 19:59:47 +08:00
|
|
|
|
2007-02-07 04:13:57 +08:00
|
|
|
def test_1():
|
|
|
|
g()
|
|
|
|
|
|
|
|
class TestX(object):
|
|
|
|
def setup_method(self, m):
|
|
|
|
self.ttt = 1
|
|
|
|
|
|
|
|
def test_one(self):
|
|
|
|
self.ttt += 1
|
|
|
|
|
|
|
|
def test_raise(self):
|
|
|
|
1/0
|
|
|
|
"""))
|
|
|
|
config = py.test.config._reparse([tmpdir])
|
|
|
|
rootcol = config._getcollector(tmpdir)
|
|
|
|
tracer = Tracer()
|
|
|
|
item = rootcol._getitembynames("test_one.py/test_1")
|
|
|
|
ex = ApigenExecutor(item, config=config)
|
|
|
|
out1 = ex.execute(tracer)
|
|
|
|
item = rootcol._getitembynames("test_one.py/TestX/()/test_one")
|
|
|
|
ex = ApigenExecutor(item, config=config)
|
|
|
|
out2 = ex.execute(tracer)
|
|
|
|
item = rootcol._getitembynames("test_one.py/TestX/()/test_raise")
|
|
|
|
ex = ApigenExecutor(item, config=config)
|
|
|
|
out3 = ex.execute(tracer)
|
|
|
|
assert tracer.starts == 3
|
|
|
|
assert tracer.ends == 3
|
|
|
|
assert out1.passed
|
|
|
|
assert out2.passed
|
|
|
|
assert not out3.passed
|
2007-02-12 23:40:04 +08:00
|
|
|
|
|
|
|
def test_executor_explicit_Failed(self):
|
|
|
|
ex = RunExecutor(ItemTestFailingExplicit("failex", self.config),
|
|
|
|
config=self.config)
|
|
|
|
|
|
|
|
outcome = ex.execute()
|
|
|
|
assert not outcome.passed
|
|
|
|
assert outcome.excinfo == "3"
|
2007-02-23 22:22:50 +08:00
|
|
|
|
|
|
|
def test_executor_explicit_Faile_no_excinfo(self):
|
|
|
|
ex = RunExecutor(ItemTestFailingExplicitEmpty("failexx", self.config),
|
|
|
|
config=self.config)
|
|
|
|
outcome = ex.execute()
|
|
|
|
assert not outcome.passed
|
|
|
|
|