1. Pypy
  2. Untitled project
  3. pypy

Commits

Ronny Pfannschmidt  committed ee7e2b3

adapt testrunner tests to shifted file opening semantics

  • Participants
  • Parent commits 0417a79
  • Branches refine-testrunner

Comments (0)

Files changed (3)

File testrunner/test/test_runner.py

View file
 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
+
 
 
 
     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'],
 
                     '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):
     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']
 
         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']

File testrunner/test/test_util.py

View file
+import py
 import sys
 import util
 import signal
         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"
 
 
 

File testrunner/util.py

View file
 
 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: