Commit 51f5387d authored by Stefan Behnel's avatar Stefan Behnel

support running tests without running Cython to test the generated code under...

support running tests without running Cython to test the generated code under different Python versions (including Py3)
parent 211a89f0
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
import os, sys, re, shutil, unittest, doctest import os, sys, re, shutil, unittest, doctest
from Cython.Compiler.Version import version WITH_CYTHON = True
from Cython.Compiler.Main import \ CLEANUP_WORKDIR = True
CompilationOptions, \
default_options as pyrex_default_options, \
compile as cython_compile
from distutils.dist import Distribution from distutils.dist import Distribution
from distutils.core import Extension from distutils.core import Extension
...@@ -90,8 +87,11 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -90,8 +87,11 @@ class CythonCompileTestCase(unittest.TestCase):
return "compiling " + self.module return "compiling " + self.module
def tearDown(self): def tearDown(self):
cleanup_c_files = WITH_CYTHON and CLEANUP_WORKDIR
if os.path.exists(self.workdir): if os.path.exists(self.workdir):
for rmfile in os.listdir(self.workdir): for rmfile in os.listdir(self.workdir):
if not cleanup_c_files and rmfile[-2:] in (".c", ".h"):
continue
if self.annotate and rmfile.endswith(".html"): if self.annotate and rmfile.endswith(".html"):
continue continue
try: try:
...@@ -171,6 +171,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -171,6 +171,7 @@ class CythonCompileTestCase(unittest.TestCase):
directory, module, workdir) directory, module, workdir)
directory = workdir directory = workdir
if WITH_CYTHON:
old_stderr = sys.stderr old_stderr = sys.stderr
try: try:
sys.stderr = ErrorWriter() sys.stderr = ErrorWriter()
...@@ -211,19 +212,47 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -211,19 +212,47 @@ class CythonRunTestCase(CythonCompileTestCase):
pass pass
if __name__ == '__main__': if __name__ == '__main__':
try:
sys.argv.remove("--no-cython")
except ValueError:
WITH_CYTHON = True
else:
WITH_CYTHON = False
if WITH_CYTHON:
from Cython.Compiler.Main import \
CompilationOptions, \
default_options as pyrex_default_options, \
compile as cython_compile
from distutils.dist import Distribution
from distutils.core import Extension
from distutils.command.build_ext import build_ext
distutils_distro = Distribution()
# RUN ALL TESTS! # RUN ALL TESTS!
ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests') ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests')
WORKDIR = os.path.join(os.getcwd(), 'BUILD') WORKDIR = os.path.join(os.getcwd(), 'BUILD')
if WITH_CYTHON:
if os.path.exists(WORKDIR): if os.path.exists(WORKDIR):
shutil.rmtree(WORKDIR, ignore_errors=True) shutil.rmtree(WORKDIR, ignore_errors=True)
if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR) os.makedirs(WORKDIR)
if not sys.path or sys.path[0] != WORKDIR: if not sys.path or sys.path[0] != WORKDIR:
sys.path.insert(0, WORKDIR) sys.path.insert(0, WORKDIR)
print "Running tests against Cython %s" % version if WITH_CYTHON:
print "Python", sys.version from Cython.Compiler.Version import version
print from Cython.Compiler.Main import \
CompilationOptions, \
default_options as pyrex_default_options, \
compile as cython_compile
print("Running tests against Cython %s" % version)
else:
print("Running tests without Cython.")
print("Python", sys.version)
print("")
try: try:
sys.argv.remove("-C") sys.argv.remove("-C")
...@@ -233,6 +262,13 @@ if __name__ == '__main__': ...@@ -233,6 +262,13 @@ if __name__ == '__main__':
import coverage import coverage
coverage.erase() coverage.erase()
try:
sys.argv.remove("--no-cleanup")
except ValueError:
CLEANUP_WORKDIR = True
else:
CLEANUP_WORKDIR = False
try: try:
sys.argv.remove("-a") sys.argv.remove("-a")
except ValueError: except ValueError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment