From c75803ed91fc89f80508403bb08af38e71bb129d Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Thu, 19 Jun 2008 01:52:57 -0700 Subject: [PATCH] Added unit tests to test runner --- runtests.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/runtests.py b/runtests.py index 75ab875b..a91b3aaf 100644 --- a/runtests.py +++ b/runtests.py @@ -238,6 +238,27 @@ class CythonRunTestCase(CythonCompileTestCase): except Exception: pass +def collect_unittests(path, suite): + def file_matches(filename): + return filename.startswith("Test") and filename.endswith(".py") + + def package_matches(dirname): + return dirname == "Tests" + + loader = unittest.TestLoader() + + for dirpath, dirnames, filenames in os.walk(path): + parentname = os.path.split(dirpath)[-1] + if package_matches(parentname): + for f in filenames: + if file_matches(f): + filepath = os.path.join(dirpath, f)[:-len(".py")] + modulename = filepath[len(path)+1:].replace(os.path.sep, '.') + module = __import__(modulename) + for x in modulename.split('.')[1:]: + module = getattr(module, x) + suite.addTests(loader.loadTestsFromModule(module)) + if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() @@ -247,6 +268,12 @@ if __name__ == '__main__': parser.add_option("--no-cython", dest="with_cython", action="store_false", default=True, help="do not run the Cython compiler, only the C compiler") + parser.add_option("--no-unit", dest="unittests", + action="store_false", default=True, + help="do not run the unit tests") + parser.add_option("--no-file", dest="filetests", + action="store_false", default=True, + help="do not run the file based tests") parser.add_option("-C", "--coverage", dest="coverage", action="store_true", default=False, help="collect source coverage data for the Compiler") @@ -296,9 +323,15 @@ if __name__ == '__main__': if not selectors: selectors = [ lambda x:True ] - tests = TestBuilder(ROOTDIR, WORKDIR, selectors, - options.annotate_source, options.cleanup_workdir) - test_suite = tests.build_suite() + test_suite = unittest.TestSuite() + + if options.unittests: + collect_unittests(os.getcwd(), test_suite) + + if options.filetests: + filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, + options.annotate_source, options.cleanup_workdir) + test_suite.addTests(filetests.build_suite()) unittest.TextTestRunner(verbosity=options.verbosity).run(test_suite) -- 2.26.2