2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
""" Testing the slave side node code (in a local way). """
|
2007-01-25 00:46:46 +08:00
|
|
|
from py.__.test.rsession.slave import SlaveNode, slave_main, setup, PidInfo
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.test.rsession.outcome import ReprOutcome
|
|
|
|
import py, sys
|
|
|
|
|
|
|
|
modlevel = []
|
|
|
|
import os
|
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
py.test.skip("rsession is unsupported on Windows.")
|
|
|
|
|
|
|
|
def setup_module(module):
|
2007-02-04 22:05:01 +08:00
|
|
|
module.tmpdir = py.test.ensuretemp(module.__name__)
|
2007-01-24 22:24:01 +08:00
|
|
|
module.rootdir = py.path.local(py.__file__).dirpath().dirpath()
|
2007-01-26 19:49:59 +08:00
|
|
|
module.rootcol = py.test.collect.Directory(rootdir)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# inlined testing functions used below
|
|
|
|
def funcpass():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def funcfail():
|
|
|
|
raise AssertionError("hello world")
|
|
|
|
|
|
|
|
def funcskip():
|
|
|
|
py.test.skip("skipped")
|
|
|
|
|
|
|
|
def funcprint():
|
|
|
|
print "samfing"
|
|
|
|
|
|
|
|
def funcprintfail():
|
|
|
|
print "samfing elz"
|
|
|
|
asddsa
|
|
|
|
|
|
|
|
def funcoptioncustom():
|
2007-01-25 00:46:46 +08:00
|
|
|
assert py.test.config.getvalue("custom")
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
def funchang():
|
|
|
|
import time
|
|
|
|
time.sleep(1000)
|
|
|
|
|
|
|
|
BASE = "py/test/rsession/testing/test_slave.py/"
|
|
|
|
funcpass_spec = (BASE + "funcpass").split("/")
|
|
|
|
funcfail_spec = (BASE + "funcfail").split("/")
|
|
|
|
funcskip_spec = (BASE + "funcskip").split("/")
|
|
|
|
funcprint_spec = (BASE + "funcprint").split("/")
|
|
|
|
funcprintfail_spec = (BASE + "funcprintfail").split("/")
|
|
|
|
funcoptioncustom_spec = (BASE + "funcoptioncustom").split("/")
|
|
|
|
funchang_spec = (BASE + "funchang").split("/")
|
|
|
|
mod_spec = BASE[:-1].split("/")
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
from py.__.test.rsession.executor import RunExecutor
|
|
|
|
|
|
|
|
def gettestnode():
|
2007-01-25 00:46:46 +08:00
|
|
|
config = py.test.config._reparse([rootdir])
|
|
|
|
pidinfo = PidInfo()
|
2007-01-26 19:49:59 +08:00
|
|
|
node = SlaveNode(config, pidinfo, executor=RunExecutor)
|
2007-01-24 22:24:01 +08:00
|
|
|
return node
|
|
|
|
|
|
|
|
def test_slave_run_passing():
|
|
|
|
node = gettestnode()
|
2007-02-04 02:29:24 +08:00
|
|
|
item = rootcol._getitembynames(funcpass_spec)
|
2007-02-04 02:00:04 +08:00
|
|
|
outcome = node.execute(item._get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
assert outcome.passed
|
|
|
|
assert not outcome.setupfailure
|
|
|
|
|
|
|
|
ser = outcome.make_repr()
|
|
|
|
reproutcome = ReprOutcome(ser)
|
|
|
|
assert reproutcome.passed
|
|
|
|
assert not reproutcome.setupfailure
|
|
|
|
|
|
|
|
def test_slave_run_failing():
|
|
|
|
node = gettestnode()
|
2007-02-04 02:29:24 +08:00
|
|
|
item = rootcol._getitembynames(funcfail_spec)
|
2007-02-04 02:00:04 +08:00
|
|
|
outcome = node.execute(item._get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
assert not outcome.passed
|
|
|
|
assert not outcome.setupfailure
|
|
|
|
assert len(outcome.excinfo.traceback) == 1
|
|
|
|
assert outcome.excinfo.traceback[-1].frame.code.name == 'funcfail'
|
|
|
|
|
|
|
|
ser = outcome.make_repr()
|
|
|
|
reproutcome = ReprOutcome(ser)
|
|
|
|
assert not reproutcome.passed
|
|
|
|
assert not reproutcome.setupfailure
|
|
|
|
assert reproutcome.excinfo
|
|
|
|
|
|
|
|
def test_slave_run_skipping():
|
|
|
|
node = gettestnode()
|
2007-02-04 02:29:24 +08:00
|
|
|
item = rootcol._getitembynames(funcskip_spec)
|
2007-02-04 02:00:04 +08:00
|
|
|
outcome = node.execute(item._get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
assert not outcome.passed
|
|
|
|
assert outcome.skipped
|
|
|
|
|
|
|
|
ser = outcome.make_repr()
|
|
|
|
reproutcome = ReprOutcome(ser)
|
|
|
|
assert not reproutcome.passed
|
|
|
|
assert reproutcome.skipped
|
|
|
|
|
|
|
|
def test_slave_run_failing_wrapped():
|
|
|
|
node = gettestnode()
|
2007-02-04 02:29:24 +08:00
|
|
|
item = rootcol._getitembynames(funcfail_spec)
|
2007-02-04 02:00:04 +08:00
|
|
|
repr_outcome = node.run(item._get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
outcome = ReprOutcome(repr_outcome)
|
|
|
|
assert not outcome.passed
|
|
|
|
assert not outcome.setupfailure
|
|
|
|
assert outcome.excinfo
|
|
|
|
|
|
|
|
def test_slave_run_different_stuff():
|
|
|
|
node = gettestnode()
|
2007-02-04 02:29:24 +08:00
|
|
|
node.run(rootcol._getitembynames("py doc log.txt".split()).
|
2007-02-04 02:00:04 +08:00
|
|
|
_get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def test_pidinfo():
|
|
|
|
if not hasattr(os, 'fork') or not hasattr(os, 'waitpid'):
|
|
|
|
py.test.skip("Platform does not support fork")
|
|
|
|
pidinfo = PidInfo()
|
|
|
|
pid = os.fork()
|
|
|
|
if pid:
|
|
|
|
pidinfo.set_pid(pid)
|
|
|
|
pidinfo.waitandclear(pid, 0)
|
|
|
|
else:
|
|
|
|
import time, sys
|
|
|
|
time.sleep(.3)
|
|
|
|
os._exit(0)
|
|
|
|
# check if this really exits
|
|
|
|
py.test.raises(OSError, "os.waitpid(pid, 0)")
|