provide testdir.spawn_pytest for pexpect mediated interaction tests,

kill code, yay.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-06 11:47:48 +02:00
parent 22622e3370
commit 61885cd825
2 changed files with 16 additions and 24 deletions

View File

@ -254,10 +254,14 @@ class TmpTestdir:
return RunResult(ret, out, err)
def runpybin(self, scriptname, *args):
fullargs = self._getpybinargs(scriptname) + args
return self.run(*fullargs)
def _getpybinargs(self, scriptname):
bindir = py.path.local(py.__file__).dirpath("bin")
script = bindir.join(scriptname)
assert script.check()
return self.run(py.std.sys.executable, script, *args)
return py.std.sys.executable, script
def runpytest(self, *args):
p = py.path.local.make_numbered_dir(prefix="runpytest-",
@ -265,6 +269,15 @@ class TmpTestdir:
args = ('--basetemp=%s' % p, ) + args
return self.runpybin("py.test", *args)
def spawn_pytest(self, string, expect_timeout=10.0):
pexpect = py.test.importorskip("pexpect", "2.3")
basetemp = self.tmpdir.mkdir("pexpect")
invoke = "%s %s" % self._getpybinargs("py.test")
cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string)
child = pexpect.spawn(cmd, logfile=basetemp.join("spawn.out").open("w"))
child.timeout = expect_timeout
return child
class Event:
def __init__(self, name, args, kwargs):
self.name = name

View File

@ -1,7 +1,5 @@
import py
pydir = py.path.local(py.__file__).dirpath()
pytestpath = pydir.join("bin", "py.test")
EXPECTTIMEOUT=10.0
class TestGeneralUsage:
@ -445,30 +443,13 @@ class TestDistribution:
class TestInteractive:
def getspawn(self, tmpdir):
pexpect = py.test.importorskip("pexpect")
basetemp = tmpdir.mkdir("basetemp")
def spawn(cmd):
cmd = cmd + " --basetemp=" + str(basetemp)
return pexpect.spawn(cmd, logfile=tmpdir.join("spawn.out").open("w"))
return spawn
def requirespexpect(self, version_needed):
pexpect = py.test.importorskip("pexpect")
ver = tuple(map(int, pexpect.__version__.split(".")))
if ver < version_needed:
py.test.skip("pexpect version %s needed" %(".".join(map(str, version_needed))))
def test_pdb_interaction(self, testdir):
self.requirespexpect((2,3))
spawn = self.getspawn(testdir.tmpdir)
p1 = testdir.makepyfile("""
def test_1():
i = 0
assert i == 1
""")
child = spawn("%s %s --pdb %s" % (py.std.sys.executable, pytestpath, p1))
child.timeout = EXPECTTIMEOUT
child = testdir.spawn_pytest("--pdb %s" % p1)
#child.expect(".*def test_1.*")
child.expect(".*i = 0.*")
child.expect("(Pdb)")
@ -478,14 +459,12 @@ class TestInteractive:
child.wait()
def test_simple_looponfail_interaction(self, testdir):
spawn = self.getspawn(testdir.tmpdir)
p1 = testdir.makepyfile("""
def test_1():
assert 1 == 0
""")
p1.setmtime(p1.mtime() - 50.0)
child = spawn("%s %s --looponfail %s" % (py.std.sys.executable, pytestpath, p1))
child.timeout = EXPECTTIMEOUT
child = testdir.spawn_pytest("--looponfail %s" % p1)
child.expect("assert 1 == 0")
child.expect("test_simple_looponfail_interaction.py:")
child.expect("1 failed")