Author: Armin Rigo <[email protected]>
Branch: ffi-backend
Changeset: r55761:a51edadd4fc8
Date: 2012-06-22 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/a51edadd4fc8/

Log:    Hack hack hack differently. Now we get feedback from crashing
        tests.

diff --git a/pypy/module/_ffi_backend/test/test_c.py 
b/pypy/module/_ffi_backend/test/test_c.py
--- a/pypy/module/_ffi_backend/test/test_c.py
+++ b/pypy/module/_ffi_backend/test/test_c.py
@@ -14,41 +14,50 @@
 class AppTestC(object):
     """Populated below, hack hack hack."""
 
+    def setup_class(cls):
+        space = gettestobjspace(usemodules=('_ffi_backend',))
+        cls.space = space
+        def find_and_load_library_for_test(space, w_name):
+            import ctypes.util
+            path = ctypes.util.find_library(space.str_w(w_name))
+            return space.appexec([space.wrap(path)], """(path):
+                import _ffi_backend
+                return _ffi_backend.load_library(path)""")
+        w_func = space.wrap(gateway.interp2app(find_and_load_library_for_test))
+        space.appexec([space.wrap(str(tmpdir)), w_func],
+        """(path, func):
+            import sys
+            sys.path.append(path)
+            import _all_test_c
+            _all_test_c.find_and_load_library = func
+        """)
 
-def find_and_load_library_for_test(space, w_name):
-    import ctypes.util
-    path = ctypes.util.find_library(space.str_w(w_name))
-    return space.appexec([space.wrap(path)], """(path):
-        import _ffi_backend
-        return _ffi_backend.load_library(path)""")
 
-
-space = gettestobjspace(usemodules=('_ffi_backend',))
-src = py.path.local(__file__).join('..', '_backend_test_c.py').read()
-w_func = space.wrap(gateway.interp2app(find_and_load_library_for_test))
 all_names = ', '.join(Module.interpleveldefs.keys())
-w_namespace = space.appexec([w_func], "(func):" +
-                            '\n    from _ffi_backend import %s' % all_names +
-                            '\n    class py:' +
-                            '\n        class test:' +
-                            '\n            raises = staticmethod(raises)' +
-                            src.replace('\n', '\n    ') +
-                            '\n    find_and_load_library = func' +
-                            '\n    return locals()\n')
-AppTestC.w_namespace = w_namespace
 
 lst = []
-for name in space.unwrap(space.call_function(space.w_list, w_namespace)):
+for name, value in _backend_test_c.__dict__.items():
     if name.startswith('test_'):
-        lst.append(getattr(_backend_test_c, name))
+        lst.append(value)
 lst.sort(key=lambda func: func.func_code.co_firstlineno)
 
-tmpname = udir.join('_test_c.py')
+tmpdir = udir.join('test_c').ensure(dir=1)
+
+tmpname = tmpdir.join('_test_c.py')
 with tmpname.open('w') as f:
     for func in lst:
         print >> f, 'def %s(self):' % (func.__name__,)
-        print >> f, '    func = self.namespace[%r]' % (func.__name__,)
-        print >> f, '    func()'
+        print >> f, '    import _all_test_c'
+        print >> f, '    _all_test_c.%s()' % (func.__name__,)
+
+tmpname2 = tmpdir.join('_all_test_c.py')
+with tmpname2.open('w') as f:
+    print >> f, 'from _ffi_backend import %s' % all_names
+    print >> f, 'class py:'
+    print >> f, '    class test:'
+    print >> f, '        raises = staticmethod(raises)'
+    print >> f, py.path.local(__file__).join('..', '_backend_test_c.py').read()
+
 
 mod = tmpname.pyimport()
 for key, value in mod.__dict__.items():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to