[pypy-commit] pypy refine-testrunner: adapt testrunner tests to shifted file opening semantics
RonnyPfannschmidt
noreply at buildbot.pypy.org
Sat Feb 23 23:02:42 CET 2013
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: refine-testrunner
Changeset: r61708:ee7e2b34a9d9
Date: 2013-02-23 22:52 +0100
http://bitbucket.org/pypy/pypy/changeset/ee7e2b34a9d9/
Log: adapt testrunner tests to shifted file opening semantics
diff --git a/testrunner/test/test_runner.py b/testrunner/test/test_runner.py
--- a/testrunner/test/test_runner.py
+++ b/testrunner/test/test_runner.py
@@ -7,13 +7,26 @@
pytest_script = py.path.local(pypy.__file__).dirpath('test_all.py')
-
class FakeRun(object):
exitcode = 0
+
def __call__(self, args, cwd, out, timeout):
self.called = (args, cwd, out, timeout)
return self.exitcode
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *exc):
+ pass
+
+ def open(self, mode):
+ assert mode=='w'
+ return self
+
+ def write(self, data):
+ pass
+
@@ -22,8 +35,8 @@
def pytest_funcarg__fakerun(self, request):
return FakeRun()
- def test_explicit(self, fakerun):
- res = runner.execute_test('/wd', 'test_one', 'out', 'LOGFILE',
+ def test_explicit(self, fakerun, ):
+ res = runner.execute_test('/wd', 'test_one', fakerun, 'LOGFILE',
runfunc=fakerun,
interp=['INTERP', 'IARG'],
test_driver=['driver', 'darg'],
@@ -37,7 +50,7 @@
'test_one']
- assert fakerun.called == (expected, '/wd', 'out', 'secs')
+ assert fakerun.called == (expected, '/wd', fakerun, 'secs')
assert res == 0
def test_explicit_win32(self, fakerun):
@@ -61,7 +74,7 @@
def test_error(self, fakerun):
fakerun.exitcode = 1
res = runner.execute_test(
- '/wd', 'test_one', 'out', 'LOGFILE',
+ '/wd', 'test_one', fakerun, 'LOGFILE',
runfunc=fakerun,
interp=['INTERP', 'IARG'],
test_driver=['driver', 'darg']
@@ -70,7 +83,7 @@
fakerun.exitcode = -signal.SIGSEGV
res = runner.execute_test(
- '/wd', 'test_one', 'out', 'LOGFILE',
+ '/wd', 'test_one', fakerun, 'LOGFILE',
runfunc=fakerun,
interp=['INTERP', 'IARG'],
test_driver=['driver', 'darg']
diff --git a/testrunner/test/test_util.py b/testrunner/test/test_util.py
--- a/testrunner/test/test_util.py
+++ b/testrunner/test/test_util.py
@@ -1,3 +1,4 @@
+import py
import sys
import util
import signal
@@ -51,39 +52,58 @@
tmpdir = request.getfuncargvalue('tmpdir')
return tmpdir.ensure('out')
- def test_run(self, out):
- res = util.run([sys.executable, "-c", "print 42"], '.', out)
+ def pytest_funcarg__outf(self, request):
+ out = request.getfuncargvalue('out')
+ return out.open('w')
+
+ def test_run(self, out, outf):
+ res = util.run([sys.executable, "-c", "print 42"], '.', outf)
assert res == 0
assert out.read() == "42\n"
- def test_error(self, out):
- res = util.run([sys.executable, "-c", "import sys; sys.exit(3)"], '.', out)
+ def test_error(self, outf):
+ res = util.run(
+ [sys.executable, "-c", "import sys; sys.exit(3)"],
+ '.', outf)
assert res == 3
- def test_signal(self, out):
+ def test_signal(self, outf):
if sys.platform == 'win32':
py.test.skip("no death by signal on windows")
- res = util.run([sys.executable, "-c", "import os; os.kill(os.getpid(), 9)"], '.', out)
+ res = util.run(
+ [sys.executable, "-c", "import os; os.kill(os.getpid(), 9)"],
+ '.', outf)
assert res == -9
- def test_timeout(self, out):
- res = util.run([sys.executable, "-c", "while True: pass"], '.', out, timeout=3)
+ def test_timeout(self, outf):
+ res = util.run(
+ [sys.executable, "-c", "while True: pass"],
+ '.', outf, timeout=3)
assert res == -999
- def test_timeout_lock(self, out):
- res = util.run([sys.executable, "-c", "import threading; l=threading.Lock(); l.acquire(); l.acquire()"], '.', out, timeout=3)
+ def test_timeout_lock(self, outf):
+ res = util.run(
+ [sys.executable, "-c",
+ "import threading; l=threading.Lock(); l.acquire(); l.acquire()"],
+ '.', outf, timeout=3)
assert res == -999
- def test_timeout_syscall(self, out):
- res = util.run([sys.executable, "-c", "import socket; s=s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind(('', 0)); s.recv(1000)"], '.', out, timeout=3)
- assert res == -999
+ def test_timeout_syscall(self, outf):
+ res = util.run(
+ [sys.executable, "-c",
+ "import socket;"
+ "s= socket.socket(socket.AF_INET, socket.SOCK_DGRAM);"
+ "s.bind(('', 0)); s.recv(1000)"],
+ '.', outf, timeout=3)
+ assert res == -999
- def test_timeout_success(self, out):
- res = util.run([sys.executable, "-c", "print 42"], '.',
- out, timeout=2)
+ def test_timeout_success(self, out, outf):
+ res = util.run(
+ [sys.executable, "-c", "print 42"], '.',
+ outf, timeout=2)
assert res == 0
out = out.read()
- assert out == "42\n"
+ assert out == "42\n"
diff --git a/testrunner/util.py b/testrunner/util.py
--- a/testrunner/util.py
+++ b/testrunner/util.py
@@ -137,11 +137,12 @@
def run(args, cwd, out, timeout=None):
try:
- p = subprocess.Popen(args, cwd=str(cwd), stdout=f, stderr=f)
+ p = subprocess.Popen(args, cwd=str(cwd), stdout=out, stderr=out)
except Exception, e:
- f.write("Failed to run %s with cwd='%s' timeout=%s:\n"
- " %s\n"
- % (args, cwd, timeout, e))
+ out.write(
+ "Failed to run %s with cwd='%s' timeout=%s:\n %s\n" % (
+ args, cwd, timeout, e
+ ))
return RUNFAILED
if timeout is None:
More information about the pypy-commit
mailing list