From c2da6d1a8f17b315300c7596f2ae1032a2483486 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 3 Nov 2010 15:09:36 +0100 Subject: [PATCH] enable CPython doctesting of .py files in tests/run/ --- runtests.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/runtests.py b/runtests.py index bb4937c4..6945ddbf 100644 --- a/runtests.py +++ b/runtests.py @@ -191,6 +191,9 @@ class TestBuilder(object): for test in self.build_tests(test_class, path, workdir, module, expect_errors): suite.addTest(test) + if filename.endswith('.py'): + # additionally test file in real Python + suite.addTest(PureDoctestTestCase(module, os.path.join(path, filename))) return suite def build_tests(self, test_class, path, workdir, module, expect_errors): @@ -499,6 +502,38 @@ class CythonRunTestCase(CythonCompileTestCase): try: os.unlink(result_file) except: pass +class PureDoctestTestCase(unittest.TestCase): + def __init__(self, module_name, module_path): + self.module_name = module_name + self.module_path = module_path + unittest.TestCase.__init__(self, 'run') + + def shortDescription(self): + return "running pure doctests in %s" % self.module_name + + def run(self, result=None): + if result is None: + result = self.defaultTestResult() + loaded_module_name = 'pure_doctest__' + self.module_name + result.startTest(self) + try: + self.setUp() + + import imp + m = imp.load_source(loaded_module_name, self.module_path) + try: + doctest.DocTestSuite(m).run(result) + finally: + del m + if loaded_module_name in sys.modules: + del sys.modules[loaded_module_name] + except Exception: + result.addError(self, sys.exc_info()) + result.stopTest(self) + try: + self.tearDown() + except Exception: + pass is_private_field = re.compile('^_[^_]').match -- 2.26.2