Allow specifying tests with 'cmdtest_in_dir'

The entry point 'cmdtest_in_dir' now accepts and passes on arguments
that optionally specifies which tests to be run. This can be done on file
level, class level and method level.

As the list of optional named arguments is quite long, they are now
keyword arguments.
This commit is contained in:
Håkan Thörngren 2016-12-12 09:44:11 -08:00
parent 9b977a8761
commit fe5dbe704e

View File

@ -665,12 +665,13 @@ class Tfile:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# Run cmdtest in given directory # Run cmdtest in given directory
def cmdtest_in_dir(path): def cmdtest_in_dir(path, *, py_files=None, selected_classes=None, selected_methods=None, quiet=False):
with temp_chdir(path): with temp_chdir(path):
py_files = glob.glob("CMDTEST_*.py") if not py_files:
return test_files(py_files) py_files = glob.glob("CMDTEST_*.py")
return test_files(py_files, selected_classes=selected_classes, selected_methods=selected_methods, quiet=quiet)
def test_files(py_files, selected_methods=None, quiet=False): def test_files(py_files, *, selected_classes=None, selected_methods=None, quiet=False):
statistics = Statistics() statistics = Statistics()
tmpdir = Tmpdir() tmpdir = Tmpdir()
for py_file in py_files: for py_file in py_files:
@ -679,12 +680,13 @@ def test_files(py_files, selected_methods=None, quiet=False):
statistics.classes += 1 statistics.classes += 1
if not quiet: if not quiet:
progress(tclass.name()) progress(tclass.name())
for tmethod in tclass.tmethods(): if not selected_classes or tclass.name() in selected_classes:
if not selected_methods or tmethod.name() in selected_methods: for tmethod in tclass.tmethods():
statistics.methods += 1 if not selected_methods or tmethod.name() in selected_methods:
if not quiet: statistics.methods += 1
progress(tmethod.name()) if not quiet:
tmethod.run(tmpdir, statistics) progress(tmethod.name())
tmethod.run(tmpdir, statistics)
return statistics return statistics
def parse_options(): def parse_options():
@ -715,7 +717,7 @@ def parse_options():
def main(): def main():
options, py_files, selected_methods = parse_options() options, py_files, selected_methods = parse_options()
statistics = test_files(py_files, selected_methods, options.quiet) statistics = test_files(py_files, selected_methods=selected_methods, quiet=options.quiet)
if not options.quiet: if not options.quiet:
print() print()
print(statistics) print(statistics)