From fe5dbe704e3c2738304c342d4681b1d4721b7522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kan=20Th=C3=B6rngren?= Date: Mon, 12 Dec 2016 09:44:11 -0800 Subject: [PATCH] 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. --- python/cmdtest.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/python/cmdtest.py b/python/cmdtest.py index 69b3346..616bd11 100755 --- a/python/cmdtest.py +++ b/python/cmdtest.py @@ -665,12 +665,13 @@ class Tfile: #---------------------------------------------------------------------- # 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): - py_files = glob.glob("CMDTEST_*.py") - return test_files(py_files) + if not 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() tmpdir = Tmpdir() for py_file in py_files: @@ -679,12 +680,13 @@ def test_files(py_files, selected_methods=None, quiet=False): statistics.classes += 1 if not quiet: progress(tclass.name()) - for tmethod in tclass.tmethods(): - if not selected_methods or tmethod.name() in selected_methods: - statistics.methods += 1 - if not quiet: - progress(tmethod.name()) - tmethod.run(tmpdir, statistics) + if not selected_classes or tclass.name() in selected_classes: + for tmethod in tclass.tmethods(): + if not selected_methods or tmethod.name() in selected_methods: + statistics.methods += 1 + if not quiet: + progress(tmethod.name()) + tmethod.run(tmpdir, statistics) return statistics def parse_options(): @@ -715,7 +717,7 @@ def parse_options(): def main(): 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: print() print(statistics)