provide testdir.spawn_pytest for pexpect mediated interaction tests,
kill code, yay. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									22622e3370
								
							
						
					
					
						commit
						61885cd825
					
				|  | @ -254,10 +254,14 @@ class TmpTestdir: | ||||||
|         return RunResult(ret, out, err) |         return RunResult(ret, out, err) | ||||||
| 
 | 
 | ||||||
|     def runpybin(self, scriptname, *args): |     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") |         bindir = py.path.local(py.__file__).dirpath("bin") | ||||||
|         script = bindir.join(scriptname) |         script = bindir.join(scriptname) | ||||||
|         assert script.check() |         assert script.check() | ||||||
|         return self.run(py.std.sys.executable, script, *args) |         return py.std.sys.executable, script | ||||||
| 
 | 
 | ||||||
|     def runpytest(self, *args): |     def runpytest(self, *args): | ||||||
|         p = py.path.local.make_numbered_dir(prefix="runpytest-",  |         p = py.path.local.make_numbered_dir(prefix="runpytest-",  | ||||||
|  | @ -265,6 +269,15 @@ class TmpTestdir: | ||||||
|         args = ('--basetemp=%s' % p, ) + args  |         args = ('--basetemp=%s' % p, ) + args  | ||||||
|         return self.runpybin("py.test", *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: | class Event: | ||||||
|     def __init__(self, name, args, kwargs): |     def __init__(self, name, args, kwargs): | ||||||
|         self.name = name |         self.name = name | ||||||
|  |  | ||||||
|  | @ -1,7 +1,5 @@ | ||||||
| import py | import py | ||||||
| 
 | 
 | ||||||
| pydir = py.path.local(py.__file__).dirpath() |  | ||||||
| pytestpath = pydir.join("bin", "py.test") |  | ||||||
| EXPECTTIMEOUT=10.0 | EXPECTTIMEOUT=10.0 | ||||||
| 
 | 
 | ||||||
| class TestGeneralUsage: | class TestGeneralUsage: | ||||||
|  | @ -445,30 +443,13 @@ class TestDistribution: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestInteractive: | 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): |     def test_pdb_interaction(self, testdir): | ||||||
|         self.requirespexpect((2,3)) |  | ||||||
|         spawn = self.getspawn(testdir.tmpdir) |  | ||||||
|         p1 = testdir.makepyfile(""" |         p1 = testdir.makepyfile(""" | ||||||
|             def test_1(): |             def test_1(): | ||||||
|                 i = 0 |                 i = 0 | ||||||
|                 assert i == 1 |                 assert i == 1 | ||||||
|         """) |         """) | ||||||
|         child = spawn("%s %s --pdb %s" % (py.std.sys.executable, pytestpath, p1)) |         child = testdir.spawn_pytest("--pdb %s" % p1) | ||||||
|         child.timeout = EXPECTTIMEOUT |  | ||||||
|         #child.expect(".*def test_1.*") |         #child.expect(".*def test_1.*") | ||||||
|         child.expect(".*i = 0.*") |         child.expect(".*i = 0.*") | ||||||
|         child.expect("(Pdb)") |         child.expect("(Pdb)") | ||||||
|  | @ -478,14 +459,12 @@ class TestInteractive: | ||||||
|             child.wait() |             child.wait() | ||||||
| 
 | 
 | ||||||
|     def test_simple_looponfail_interaction(self, testdir): |     def test_simple_looponfail_interaction(self, testdir): | ||||||
|         spawn = self.getspawn(testdir.tmpdir) |  | ||||||
|         p1 = testdir.makepyfile(""" |         p1 = testdir.makepyfile(""" | ||||||
|             def test_1(): |             def test_1(): | ||||||
|                 assert 1 == 0  |                 assert 1 == 0  | ||||||
|         """) |         """) | ||||||
|         p1.setmtime(p1.mtime() - 50.0)   |         p1.setmtime(p1.mtime() - 50.0)   | ||||||
|         child = spawn("%s %s --looponfail %s" % (py.std.sys.executable, pytestpath, p1)) |         child = testdir.spawn_pytest("--looponfail %s" % p1) | ||||||
|         child.timeout = EXPECTTIMEOUT |  | ||||||
|         child.expect("assert 1 == 0") |         child.expect("assert 1 == 0") | ||||||
|         child.expect("test_simple_looponfail_interaction.py:") |         child.expect("test_simple_looponfail_interaction.py:") | ||||||
|         child.expect("1 failed") |         child.expect("1 failed") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue