Added --refnanny option to runtests.py
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 7 Jan 2009 12:05:54 +0000 (13:05 +0100)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 7 Jan 2009 12:05:54 +0000 (13:05 +0100)
runtests.py

index 1e7ef9584a4e7dec7c4e5d9859995ca9ec84bd4c..e955d6e9a4f20865b5972793df3648dd384afded 100644 (file)
@@ -26,11 +26,6 @@ VER_DEP_MODULES = {
 INCLUDE_DIRS = [ d for d in os.getenv('INCLUDE', '').split(os.pathsep) if d ]
 CFLAGS = os.getenv('CFLAGS', '').split()
 
-ctypes.PyDLL("Cython/Runtime/refnanny.so", mode=ctypes.RTLD_GLOBAL)
-sys.path.append("Cython/Runtime")
-import refnanny
-#CFLAGS.append("-DCYTHON_REFNANNY")
-
 class ErrorWriter(object):
     match_error = re.compile('(warning:)?(?:.*:)?\s*([-0-9]+)\s*:\s*([-0-9]+)\s*:\s*(.*)').match
     def __init__(self):
@@ -475,6 +470,9 @@ if __name__ == '__main__':
     parser.add_option("--cython-only", dest="cython_only",
                       action="store_true", default=False,
                       help="only compile pyx to c, do not run C compiler or run the tests")
+    parser.add_option("--refnanny", dest="with_refnanny",
+                      action="store_true", default=False,
+                      help="also test that Cython-generated code does correct reference counting")
     parser.add_option("--sys-pyregr", dest="system_pyregr",
                       action="store_true", default=False,
                       help="run the regression tests of the CPython installation")
@@ -518,6 +516,13 @@ if __name__ == '__main__':
         from Cython.Compiler import Errors
         Errors.LEVEL = 0 # show all warnings
 
+    if options.with_refnanny:
+        ctypes.PyDLL("Cython/Runtime/refnanny.so", mode=ctypes.RTLD_GLOBAL)
+        sys.path.append("Cython/Runtime")
+        import refnanny
+        del sys.path[-1]
+        CFLAGS.append("-DCYTHON_REFNANNY")
+
     # RUN ALL TESTS!
     ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests')
     WORKDIR = os.path.join(os.getcwd(), 'BUILD')
@@ -599,4 +604,5 @@ if __name__ == '__main__':
         for test in missing_dep_excluder.tests_missing_deps:
             sys.stderr.write("   %s\n" % test)
 
-print "\n".join([repr(x) for x in refnanny.reflog])
+    if options.with_refnanny:
+        sys.stderr.write("\n".join([repr(x) for x in refnanny.reflog]))