[svn r38032] simplified testing machinery a bit
(you know just have to add an example and can immediately use it from tests without adding boilerplate anywhere) --HG-- branch : trunk
This commit is contained in:
parent
b7b83bf007
commit
50c6e97e1c
|
@ -0,0 +1,46 @@
|
|||
|
||||
""" 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):
|
||||
tmpdir = py.test.ensuretemp(cls.__name__)
|
||||
source = py.code.Source(func_source)[1:].deindent()
|
||||
testonepath = tmpdir.ensure("test_one.py")
|
||||
testonepath.write(source)
|
||||
cls.config = py.test.config._reparse([tmpdir])
|
||||
cls.collector_test_one = cls.config._getcollector(testonepath)
|
||||
|
||||
def getexample(self, name):
|
||||
funcname = "func" + name
|
||||
col = self.collector_test_one.join(funcname)
|
||||
assert col is not None, funcname
|
||||
return col
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
""" 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("/")
|
||||
|
|
@ -3,7 +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
|
||||
from py.__.test.rsession.testing.basetest import BasicRsessionTest
|
||||
|
||||
modlevel = []
|
||||
import os
|
||||
|
@ -23,7 +23,7 @@ class TestSlave(BasicRsessionTest):
|
|||
|
||||
def test_slave_run_passing(self):
|
||||
node = self.gettestnode()
|
||||
item = self.rootcol._getitembynames(self.funcpass_spec)
|
||||
item = self.getexample("pass")
|
||||
outcome = node.execute(item._get_collector_trail())
|
||||
assert outcome.passed
|
||||
assert not outcome.setupfailure
|
||||
|
@ -35,7 +35,7 @@ class TestSlave(BasicRsessionTest):
|
|||
|
||||
def test_slave_run_failing(self):
|
||||
node = self.gettestnode()
|
||||
item = self.rootcol._getitembynames(self.funcfail_spec)
|
||||
item = self.getexample("fail")
|
||||
outcome = node.execute(item._get_collector_trail())
|
||||
assert not outcome.passed
|
||||
assert not outcome.setupfailure
|
||||
|
@ -50,7 +50,7 @@ class TestSlave(BasicRsessionTest):
|
|||
|
||||
def test_slave_run_skipping(self):
|
||||
node = self.gettestnode()
|
||||
item = self.rootcol._getitembynames(self.funcskip_spec)
|
||||
item = self.getexample("skip")
|
||||
outcome = node.execute(item._get_collector_trail())
|
||||
assert not outcome.passed
|
||||
assert outcome.skipped
|
||||
|
@ -62,7 +62,7 @@ class TestSlave(BasicRsessionTest):
|
|||
|
||||
def test_slave_run_failing_wrapped(self):
|
||||
node = self.gettestnode()
|
||||
item = self.rootcol._getitembynames(self.funcfail_spec)
|
||||
item = self.getexample("fail")
|
||||
repr_outcome = node.run(item._get_collector_trail())
|
||||
outcome = ReprOutcome(repr_outcome)
|
||||
assert not outcome.passed
|
||||
|
|
Loading…
Reference in New Issue