Commit a663be97 authored by Stefan Behnel's avatar Stefan Behnel

fixes for C++ test runs

parent 50cef2fe
...@@ -85,8 +85,6 @@ class TestBuilder(object): ...@@ -85,8 +85,6 @@ class TestBuilder(object):
workdir = os.path.join(self.workdir, context) workdir = os.path.join(self.workdir, context)
if not os.path.exists(workdir): if not os.path.exists(workdir):
os.makedirs(workdir) os.makedirs(workdir)
if workdir not in sys.path:
sys.path.insert(0, workdir)
expect_errors = (context == 'errors') expect_errors = (context == 'errors')
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -126,6 +124,9 @@ class TestBuilder(object): ...@@ -126,6 +124,9 @@ class TestBuilder(object):
def build_test(self, test_class, path, workdir, module, def build_test(self, test_class, path, workdir, module,
language, expect_errors): language, expect_errors):
workdir = os.path.join(workdir, language)
if not os.path.exists(workdir):
os.makedirs(workdir)
return test_class(path, workdir, module, return test_class(path, workdir, module,
language=language, language=language,
expect_errors=expect_errors, expect_errors=expect_errors,
...@@ -152,7 +153,19 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -152,7 +153,19 @@ class CythonCompileTestCase(unittest.TestCase):
def shortDescription(self): def shortDescription(self):
return "compiling (%s) %s" % (self.language, self.module) return "compiling (%s) %s" % (self.language, self.module)
def setUp(self):
if self.workdir not in sys.path:
sys.path.insert(0, self.workdir)
def tearDown(self): def tearDown(self):
try:
sys.path.remove(self.workdir)
except ValueError:
pass
try:
del sys.modules[self.module]
except KeyError:
pass
cleanup_c_files = WITH_CYTHON and self.cleanup_workdir cleanup_c_files = WITH_CYTHON and self.cleanup_workdir
cleanup_lib_files = self.cleanup_sharedlibs cleanup_lib_files = self.cleanup_sharedlibs
if os.path.exists(self.workdir): if os.path.exists(self.workdir):
...@@ -187,6 +200,10 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -187,6 +200,10 @@ class CythonCompileTestCase(unittest.TestCase):
source_file = source_file[:-1] source_file = source_file[:-1]
return source_file return source_file
def build_target_filename(self, module_name):
target = '%s.%s' % (module_name, self.language)
return target
def split_source_and_output(self, directory, module, workdir): def split_source_and_output(self, directory, module, workdir):
source_file = os.path.join(directory, module) + '.pyx' source_file = os.path.join(directory, module) + '.pyx'
source_and_output = open( source_and_output = open(
...@@ -212,7 +229,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -212,7 +229,7 @@ class CythonCompileTestCase(unittest.TestCase):
include_dirs.append(incdir) include_dirs.append(incdir)
source = self.find_module_source_file( source = self.find_module_source_file(
os.path.join(directory, module + '.pyx')) os.path.join(directory, module + '.pyx'))
target = os.path.join(targetdir, module + '.' + self.language) target = os.path.join(targetdir, self.build_target_filename(module))
options = CompilationOptions( options = CompilationOptions(
pyrex_default_options, pyrex_default_options,
include_path = include_dirs, include_path = include_dirs,
...@@ -236,7 +253,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -236,7 +253,7 @@ class CythonCompileTestCase(unittest.TestCase):
extension = Extension( extension = Extension(
module, module,
sources = [module + '.' + self.language], sources = [self.build_target_filename(module)],
extra_compile_args = CFLAGS, extra_compile_args = CFLAGS,
) )
build_extension.extensions = [extension] build_extension.extensions = [extension]
...@@ -285,6 +302,7 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -285,6 +302,7 @@ class CythonRunTestCase(CythonCompileTestCase):
result = self.defaultTestResult() result = self.defaultTestResult()
result.startTest(self) result.startTest(self)
try: try:
self.setUp()
self.runCompileTest() self.runCompileTest()
if not self.cython_only: if not self.cython_only:
sys.stderr.write('running doctests in %s ...\n' % self.module) sys.stderr.write('running doctests in %s ...\n' % self.module)
...@@ -306,6 +324,7 @@ class CythonUnitTestCase(CythonCompileTestCase): ...@@ -306,6 +324,7 @@ class CythonUnitTestCase(CythonCompileTestCase):
result = self.defaultTestResult() result = self.defaultTestResult()
result.startTest(self) result.startTest(self)
try: try:
self.setUp()
self.runCompileTest() self.runCompileTest()
sys.stderr.write('running tests in %s ...\n' % self.module) sys.stderr.write('running tests in %s ...\n' % self.module)
unittest.defaultTestLoader.loadTestsFromName(self.module).run(result) unittest.defaultTestLoader.loadTestsFromName(self.module).run(result)
......
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