Commits

Ronny Pfannschmidt committed 416df64

fix and refine lib_pypy/pypy_test/test_os_wait.py

Comments (0)

Files changed (2)

lib_pypy/pypy_test/test_os_wait.py

-# Generates the resource cache
 from __future__ import absolute_import
-from lib_pypy.ctypes_config_cache import rebuild
-rebuild.rebuild_one('resource.ctc.py')
+import os
+import pytest
+from pypy.tool.lib_pypy import ctypes_cachedir, rebuild_one
 
-import os
 
-from lib_pypy._pypy_wait import wait3, wait4
+def setup_module(mod):
+    # Generates the resource cache
+    rebuild_one(ctypes_cachedir.join('resource.ctc.py'))
+    if not hasattr(os, 'fork'):
+        pytest.skip("can't test wait without fork")
 
-if hasattr(os, 'wait3'):
-    def test_os_wait3():
-        exit_status = 0x33
 
-        if not hasattr(os, "fork"):
-            skip("Need fork() to test wait3()")
+def test_os_wait3():
+    #XXX: have skip_if deco
+    if not hasattr(os, 'wait3'):
+        pytest.skip('no os.wait3')
 
-        child = os.fork()
-        if child == 0: # in child
-            os._exit(exit_status)
-        else:
-            pid, status, rusage = wait3(0)
-            assert child == pid
-            assert os.WIFEXITED(status)
-            assert os.WEXITSTATUS(status) == exit_status
-            assert isinstance(rusage.ru_utime, float)
-            assert isinstance(rusage.ru_maxrss, int)
+    from lib_pypy._pypy_wait import wait3
+    exit_status = 0x33
 
-if hasattr(os, 'wait4'):
-    def test_os_wait4():
-        exit_status = 0x33
+    child = os.fork()
+    if child == 0: # in child
+        os._exit(exit_status)
+    else:
+        pid, status, rusage = wait3(0)
+        assert child == pid
+        assert os.WIFEXITED(status)
+        assert os.WEXITSTATUS(status) == exit_status
+        assert isinstance(rusage.ru_utime, float)
+        assert isinstance(rusage.ru_maxrss, int)
 
-        if not hasattr(os, "fork"):
-            skip("Need fork() to test wait4()")
+def test_os_wait4():
+    #XXX: have skip_if deco
+    if not hasattr(os, 'wait4'):
+        pytest.skip('no os.wait4')
 
-        child = os.fork()
-        if child == 0: # in child
-            os._exit(exit_status)
-        else:
-            pid, status, rusage = wait4(child, 0)
-            assert child == pid
-            assert os.WIFEXITED(status)
-            assert os.WEXITSTATUS(status) == exit_status
-            assert isinstance(rusage.ru_utime, float)
-            assert isinstance(rusage.ru_maxrss, int)
+    from lib_pypy._pypy_wait import wait4
+    exit_status = 0x33
+
+    child = os.fork()
+    if child == 0: # in child
+        os._exit(exit_status)
+    else:
+        pid, status, rusage = wait4(child, 0)
+        assert child == pid
+        assert os.WIFEXITED(status)
+        assert os.WEXITSTATUS(status) == exit_status
+        assert isinstance(rusage.ru_utime, float)
+        assert isinstance(rusage.ru_maxrss, int)

pypy/tool/lib_pypy.py

 def rebuild_one(path):
     filename = str(path)
     d = {'__file__': filename}
-    try:
-        execfile(filename, d)
-    finally:
-        base = path.basename.split('.')[0]
-        dumpcache2(base, d['config'], filename)
+    execfile(filename, d)
+    base = path.basename.split('.')[0]
+    dumpcache2(base, d['config'], filename)
 
 
 def try_rebuild():