adding internal repr for debugging
adding an example for generating multi-args/multi python tests --HG-- branch : trunk
This commit is contained in:
parent
aed66120a2
commit
496e3b1138
|
@ -0,0 +1,65 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
module containing a parametrized tests testing cross-python
|
||||||
|
serialization via the pickle module.
|
||||||
|
"""
|
||||||
|
import py
|
||||||
|
|
||||||
|
pythonlist = ['python2.3', 'python2.4', 'python2.5', 'python2.6']
|
||||||
|
# 'jython' 'python3.1']
|
||||||
|
|
||||||
|
def pytest_generate_tests(metafunc):
|
||||||
|
if 'python1' in metafunc.funcargnames:
|
||||||
|
assert 'python2' in metafunc.funcargnames
|
||||||
|
for obj in metafunc.function.multiarg.obj:
|
||||||
|
for py1 in pythonlist:
|
||||||
|
for py2 in pythonlist:
|
||||||
|
metafunc.addcall(id="%s-%s-%s" % (py1, py2, obj),
|
||||||
|
param=(py1, py2, obj))
|
||||||
|
|
||||||
|
@py.test.mark.multiarg(obj=[42, {}, {1:3},])
|
||||||
|
def test_basic_objects(python1, python2, obj):
|
||||||
|
python1.dumps(obj)
|
||||||
|
python2.load_and_is_true("obj == %s" % obj)
|
||||||
|
|
||||||
|
def pytest_funcarg__python1(request):
|
||||||
|
tmpdir = request.getfuncargvalue("tmpdir")
|
||||||
|
picklefile = tmpdir.join("data.pickle")
|
||||||
|
return Python(request.param[0], picklefile)
|
||||||
|
|
||||||
|
def pytest_funcarg__python2(request):
|
||||||
|
python1 = request.getfuncargvalue("python1")
|
||||||
|
return Python(request.param[1], python1.picklefile)
|
||||||
|
|
||||||
|
def pytest_funcarg__obj(request):
|
||||||
|
return request.param[2]
|
||||||
|
|
||||||
|
class Python:
|
||||||
|
def __init__(self, version, picklefile):
|
||||||
|
self.pythonpath = py.path.local.sysfind(version)
|
||||||
|
if not self.pythonpath:
|
||||||
|
py.test.skip("%r not found" %(version,))
|
||||||
|
self.picklefile = picklefile
|
||||||
|
def dumps(self, obj):
|
||||||
|
dumpfile = self.picklefile.dirpath("dump.py")
|
||||||
|
dumpfile.write(py.code.Source("""
|
||||||
|
import pickle
|
||||||
|
f = open(%r, 'wb')
|
||||||
|
s = pickle.dump(%r, f)
|
||||||
|
f.close()
|
||||||
|
""" % (str(self.picklefile), obj)))
|
||||||
|
py.process.cmdexec("%s %s" %(self.pythonpath, dumpfile))
|
||||||
|
|
||||||
|
def load_and_is_true(self, expression):
|
||||||
|
loadfile = self.picklefile.dirpath("load.py")
|
||||||
|
loadfile.write(py.code.Source("""
|
||||||
|
import pickle
|
||||||
|
f = open(%r, 'rb')
|
||||||
|
obj = pickle.load(f)
|
||||||
|
f.close()
|
||||||
|
res = eval(%r)
|
||||||
|
if not res:
|
||||||
|
raise SystemExit(1)
|
||||||
|
""" % (str(self.picklefile), expression)))
|
||||||
|
print loadfile
|
||||||
|
py.process.cmdexec("%s %s" %(self.pythonpath, loadfile))
|
|
@ -23,6 +23,9 @@ class CallSpec:
|
||||||
self.id = id
|
self.id = id
|
||||||
if param is not _notexists:
|
if param is not _notexists:
|
||||||
self.param = param
|
self.param = param
|
||||||
|
def __repr__(self):
|
||||||
|
return "<CallSpec id=%r param=%r funcargs=%r>" %(
|
||||||
|
self.id, getattr(self, 'param', '?'), self.funcargs)
|
||||||
|
|
||||||
class Metafunc:
|
class Metafunc:
|
||||||
def __init__(self, function, config=None, cls=None, module=None):
|
def __init__(self, function, config=None, cls=None, module=None):
|
||||||
|
|
|
@ -17,6 +17,12 @@ def test_getfuncargnames():
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3,0):
|
||||||
assert funcargs.getfuncargnames(A.f) == ['arg1']
|
assert funcargs.getfuncargnames(A.f) == ['arg1']
|
||||||
|
|
||||||
|
def test_callspec_repr():
|
||||||
|
cs = funcargs.CallSpec({}, 'hello', 1)
|
||||||
|
repr(cs)
|
||||||
|
cs = funcargs.CallSpec({}, 'hello', funcargs._notexists)
|
||||||
|
repr(cs)
|
||||||
|
|
||||||
class TestFillFuncArgs:
|
class TestFillFuncArgs:
|
||||||
def test_funcarg_lookupfails(self, testdir):
|
def test_funcarg_lookupfails(self, testdir):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
|
@ -314,7 +320,6 @@ class TestRequestCachedSetup:
|
||||||
"*3 passed*"
|
"*3 passed*"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestMetafunc:
|
class TestMetafunc:
|
||||||
def test_no_funcargs(self, testdir):
|
def test_no_funcargs(self, testdir):
|
||||||
def function(): pass
|
def function(): pass
|
||||||
|
|
Loading…
Reference in New Issue