[Pyrex] Testing on Linux

Eric Wald eswald at gmail.com
Wed Apr 19 00:01:41 CEST 2006


I have hacked together some support for running the test suite on Linux
(and perhaps other Posix systems).  It may not be the best code, but it
runs on my system.  The patch follows this post.

Unfortunately, a few of the tests fail, and some others give warnings.
Is this normal, or an artifact of the different compiler environment?
I'm using Python 2.4.3 and GCC 3.4.3 (ssp).

- Eric

=======================================================================
diff -aurp Pyrex-0.9.4/bin/run_tests Pyrex-modified/bin/run_tests
--- Pyrex-0.9.4/bin/run_tests	2003-09-20 00:35:06.000000000 -0600
+++ Pyrex-modified/bin/run_tests	2006-04-18 10:54:38.000000000 -0600
@@ -1,4 +1,4 @@
-#!/usr/bin/env pythonw
+#!/usr/bin/env python
 #
 #   runtests -- Run all the tests.
 #
diff -aurp Pyrex-0.9.4/Pyrex/Compiler/Main.py
Pyrex-modified/Pyrex/Compiler/Main.py
--- Pyrex-0.9.4/Pyrex/Compiler/Main.py	2006-04-15 01:24:02.000000000 -0600
+++ Pyrex-modified/Pyrex/Compiler/Main.py	2006-04-18 14:06:32.000000000 -0600
@@ -321,6 +321,32 @@
     default_options.use_listing_file = 1
 elif sys.platform == "darwin":
     from Pyrex.Mac.DarwinSystem import c_compile, c_link, CCompilerError
+elif "linux" in sys.platform:
+    def c_compile(c_file, verbose_flag=False, cplus=False, obj_suffix=".o"):
+        from subprocess import call
+        out_file = replace_suffix(c_file, obj_suffix)
+        version = sys.version_info[:2]
+        args = [cplus and 'c++' or 'cc',
+                '-I' + sys.exec_prefix + '/include/python%d.%d/' % version,
+                '-c', c_file, '-o', out_file]
+        if verbose_flag: args += ['-v', '-Wall']
+        #print 'Calling %r ...' % str.join(' ', args)
+        status = call(args)
+        if status:
+            raise CCompilerError("C compiler returned status %s" % status)
+        return out_file
+    def c_link(obj_file, verbose_flag=False, extra_objects=[], cplus=False):
+        from subprocess import call
+        out_file = replace_suffix(obj_file, ".so")
+        args = ['ld', '-shared', obj_file, '-o', out_file]
+        if verbose_flag: args += ['-v']
+        #print 'Calling %r ...' % str.join(' ', args)
+        status = call(args)
+        if status:
+            raise CCompilerError("Linker returned status %s" % status)
+        return out_file
+    class CCompilerError(PyrexError):
+        pass
 else:
     c_compile = None
     c_link = None
diff -aurp Pyrex-0.9.4/Pyrex/Testing.py Pyrex-modified/Pyrex/Testing.py
--- Pyrex-0.9.4/Pyrex/Testing.py	2006-04-15 05:42:08.000000000 -0600
+++ Pyrex-modified/Pyrex/Testing.py	2006-04-18 14:15:35.000000000 -0600
@@ -22,6 +22,23 @@
     from Pyrex.Mac.FileMarking import \
         set_item_colour, get_item_colour, passed_colour, failed_colour
     from Pyrex.Mac.DarwinSystem import c_compile
+elif "linux" in sys.platform:
+    from Pyrex.Compiler.Main import c_compile
+    colours = {}
+    passed_colour = 2
+    failed_colour = 4
+    def get_item_colour(item): return colours.get(item)
+    def set_item_colour(item, colour): colours[item] = colour
+    def run_python_file(pyfile, outfile, errfile):
+        from subprocess import call
+        args = [ sys.executable, pyfile ]
+        output = open(outfile, "w")
+        errput = open(errfile, "w")
+        status = call(args, stdout=output, stderr=errput)
+        output.close()
+        errput.close()
+        print_file(errfile)
+        return status
 else:
     raise Exception(
         "Testing not supported on platform '%s'" % sys.platform)
@@ -255,7 +273,7 @@ def run_functional_test(pyx_file, keep_f
 def print_file(path):
     text = open(path).read()
     sys.stdout.write(text)
-    if not text.endswith("\n"):
+    if text and not text.endswith("\n"):
         sys.stdout.write("\n")

 def compare_with_reference(file_in_question, show_diffs,
=======================================================================



More information about the Pyrex mailing list