Commit b355d4c9 authored by Stefan Behnel's avatar Stefan Behnel

allow selecting tests via RegExp

parent 78df7dc4
...@@ -15,9 +15,10 @@ INCLUDE_DIRS = os.getenv('INCLUDE', '').split(os.pathsep) ...@@ -15,9 +15,10 @@ INCLUDE_DIRS = os.getenv('INCLUDE', '').split(os.pathsep)
CFLAGS = os.getenv('CFLAGS', '').split() CFLAGS = os.getenv('CFLAGS', '').split()
class TestBuilder(object): class TestBuilder(object):
def __init__(self, rootdir, workdir): def __init__(self, rootdir, workdir, selectors):
self.rootdir = rootdir self.rootdir = rootdir
self.workdir = workdir self.workdir = workdir
self.selectors = selectors
def build_suite(self): def build_suite(self):
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -25,18 +26,22 @@ class TestBuilder(object): ...@@ -25,18 +26,22 @@ class TestBuilder(object):
path = os.path.join(self.rootdir, filename) path = os.path.join(self.rootdir, filename)
if os.path.isdir(path) and filename in TEST_DIRS: if os.path.isdir(path) and filename in TEST_DIRS:
suite.addTest( suite.addTest(
self.handle_directory(path, filename in TEST_RUN_DIRS)) self.handle_directory(path, filename))
return suite return suite
def handle_directory(self, path, run_module): def handle_directory(self, path, context):
suite = unittest.TestSuite() suite = unittest.TestSuite()
for filename in os.listdir(path): for filename in os.listdir(path):
if not filename.endswith(".pyx"): if not filename.endswith(".pyx"):
continue continue
module = filename[:-4] module = filename[:-4]
fqmodule = "%s.%s" % (context, module)
if not [ 1 for match in self.selectors
if match(fqmodule) ]:
continue
suite.addTest( suite.addTest(
CythonCompileTestCase(path, self.workdir, module)) CythonCompileTestCase(path, self.workdir, module))
if run_module: if context in TEST_RUN_DIRS:
suite.addTest( suite.addTest(
CythonRunTestCase(self.workdir, module)) CythonRunTestCase(self.workdir, module))
return suite return suite
...@@ -105,5 +110,10 @@ if __name__ == '__main__': ...@@ -105,5 +110,10 @@ if __name__ == '__main__':
if not os.path.exists(WORKDIR): if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR) os.makedirs(WORKDIR)
tests = TestBuilder(ROOTDIR, WORKDIR) import re
selectors = [ re.compile(r, re.I).search for r in sys.argv[1:] ]
if not selectors:
selectors = [ lambda x:True ]
tests = TestBuilder(ROOTDIR, WORKDIR, selectors)
unittest.TextTestRunner(verbosity=2).run( tests.build_suite() ) unittest.TextTestRunner(verbosity=2).run( tests.build_suite() )
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