Commit 185adaa1 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Regex matching for unit tests

parent 8eb10086
...@@ -238,7 +238,7 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -238,7 +238,7 @@ class CythonRunTestCase(CythonCompileTestCase):
except Exception: except Exception:
pass pass
def collect_unittests(path, suite): def collect_unittests(path, suite, selectors):
def file_matches(filename): def file_matches(filename):
return filename.startswith("Test") and filename.endswith(".py") return filename.startswith("Test") and filename.endswith(".py")
...@@ -254,6 +254,8 @@ def collect_unittests(path, suite): ...@@ -254,6 +254,8 @@ def collect_unittests(path, suite):
if file_matches(f): if file_matches(f):
filepath = os.path.join(dirpath, f)[:-len(".py")] filepath = os.path.join(dirpath, f)[:-len(".py")]
modulename = filepath[len(path)+1:].replace(os.path.sep, '.') modulename = filepath[len(path)+1:].replace(os.path.sep, '.')
if not [ 1 for match in selectors if match(modulename) ]:
continue
module = __import__(modulename) module = __import__(modulename)
for x in modulename.split('.')[1:]: for x in modulename.split('.')[1:]:
module = getattr(module, x) module = getattr(module, x)
...@@ -326,7 +328,7 @@ if __name__ == '__main__': ...@@ -326,7 +328,7 @@ if __name__ == '__main__':
test_suite = unittest.TestSuite() test_suite = unittest.TestSuite()
if options.unittests: if options.unittests:
collect_unittests(os.getcwd(), test_suite) collect_unittests(os.getcwd(), test_suite, selectors)
if options.filetests: if options.filetests:
filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, filetests = TestBuilder(ROOTDIR, WORKDIR, selectors,
......
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