[svn r38029] Move funcxxxspec out of pylib itself.

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-06 21:05:55 +01:00
parent 4369d430c8
commit 8fd09aac24
2 changed files with 106 additions and 90 deletions

View File

@ -0,0 +1,54 @@
""" Support module for running tests
"""
import py
def func_source():
import py
import time
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():
assert py.test.config.getvalue("custom")
def funchang():
import time
time.sleep(1000)
class BasicRsessionTest(object):
def setup_class(cls):
tmptop = py.test.ensuretemp("test_suite")
name = cls.__name__
tmpdir = tmptop.ensure(name, dir=1)
source = py.code.Source(func_source)[1:].deindent()
tmpdir.ensure("test_one.py").write(source)
tmpdir.ensure("__init__.py")
cls.rootdir = tmpdir
cls.config = py.test.config._reparse([cls.rootdir])
cls.rootcol = cls.config._getcollector(tmpdir)
#cls.rootcol._config = cls.config
BASE = "test_one.py/"
cls.funcpass_spec = (BASE + "funcpass").split("/")
cls.funcfail_spec = (BASE + "funcfail").split("/")
cls.funcskip_spec = (BASE + "funcskip").split("/")
cls.funcprint_spec = (BASE + "funcprint").split("/")
cls.funcprintfail_spec = (BASE + "funcprintfail").split("/")
cls.funcoptioncustom_spec = (BASE + "funcoptioncustom").split("/")
cls.funchang_spec = (BASE + "funchang").split("/")
cls.mod_spec = BASE[:-1].split("/")

View File

@ -3,6 +3,7 @@
from py.__.test.rsession.slave import SlaveNode, slave_main, setup, PidInfo
from py.__.test.rsession.outcome import ReprOutcome
import py, sys
from py.__.test.rsession.testing.runtest import BasicRsessionTest
modlevel = []
import os
@ -10,108 +11,69 @@ import os
if sys.platform == 'win32':
py.test.skip("rsession is unsupported on Windows.")
def setup_module(module):
module.tmpdir = py.test.ensuretemp(module.__name__)
module.rootdir = py.path.local(py.__file__).dirpath().dirpath()
module.rootcol = py.test.collect.Directory(rootdir)
# ----------------------------------------------------------------------
# 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():
assert py.test.config.getvalue("custom")
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():
config = py.test.config._reparse([rootdir])
pidinfo = PidInfo()
node = SlaveNode(config, pidinfo, executor=RunExecutor)
return node
class TestSlave(BasicRsessionTest):
def gettestnode(self):
pidinfo = PidInfo()
node = SlaveNode(self.config, pidinfo, executor=RunExecutor)
return node
def test_slave_run_passing():
node = gettestnode()
item = rootcol._getitembynames(funcpass_spec)
outcome = node.execute(item._get_collector_trail())
assert outcome.passed
assert not outcome.setupfailure
def test_slave_run_passing(self):
node = self.gettestnode()
item = self.rootcol._getitembynames(self.funcpass_spec)
outcome = node.execute(item._get_collector_trail())
assert outcome.passed
assert not outcome.setupfailure
ser = outcome.make_repr()
reproutcome = ReprOutcome(ser)
assert reproutcome.passed
assert not reproutcome.setupfailure
ser = outcome.make_repr()
reproutcome = ReprOutcome(ser)
assert reproutcome.passed
assert not reproutcome.setupfailure
def test_slave_run_failing():
node = gettestnode()
item = rootcol._getitembynames(funcfail_spec)
outcome = node.execute(item._get_collector_trail())
assert not outcome.passed
assert not outcome.setupfailure
assert len(outcome.excinfo.traceback) == 1
assert outcome.excinfo.traceback[-1].frame.code.name == 'funcfail'
def test_slave_run_failing(self):
node = self.gettestnode()
item = self.rootcol._getitembynames(self.funcfail_spec)
outcome = node.execute(item._get_collector_trail())
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
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()
item = rootcol._getitembynames(funcskip_spec)
outcome = node.execute(item._get_collector_trail())
assert not outcome.passed
assert outcome.skipped
def test_slave_run_skipping(self):
node = self.gettestnode()
item = self.rootcol._getitembynames(self.funcskip_spec)
outcome = node.execute(item._get_collector_trail())
assert not outcome.passed
assert outcome.skipped
ser = outcome.make_repr()
reproutcome = ReprOutcome(ser)
assert not reproutcome.passed
assert reproutcome.skipped
ser = outcome.make_repr()
reproutcome = ReprOutcome(ser)
assert not reproutcome.passed
assert reproutcome.skipped
def test_slave_run_failing_wrapped():
node = gettestnode()
item = rootcol._getitembynames(funcfail_spec)
repr_outcome = node.run(item._get_collector_trail())
outcome = ReprOutcome(repr_outcome)
assert not outcome.passed
assert not outcome.setupfailure
assert outcome.excinfo
def test_slave_run_failing_wrapped(self):
node = self.gettestnode()
item = self.rootcol._getitembynames(self.funcfail_spec)
repr_outcome = node.run(item._get_collector_trail())
outcome = ReprOutcome(repr_outcome)
assert not outcome.passed
assert not outcome.setupfailure
assert outcome.excinfo
def test_slave_run_different_stuff():
node = gettestnode()
node.run(rootcol._getitembynames("py doc log.txt".split()).
_get_collector_trail())
def test_slave_run_different_stuff(self):
py.test.skip("XXX not this way")
node = self.gettestnode()
node.run(self.rootcol._getitembynames("py doc log.txt".split()).
_get_collector_trail())
def test_pidinfo():
if not hasattr(os, 'fork') or not hasattr(os, 'waitpid'):