add --quiet option
to make writing unit tests of 'cmdtest.py' itself easier
This commit is contained in:
parent
2d37244714
commit
f0e6f5c281
@ -669,17 +669,19 @@ def cmdtest_in_dir(path):
|
|||||||
py_files = glob.glob("CMDTEST_*.py")
|
py_files = glob.glob("CMDTEST_*.py")
|
||||||
return test_files(py_files)
|
return test_files(py_files)
|
||||||
|
|
||||||
def test_files(py_files, selected_methods = set()):
|
def test_files(py_files, 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:
|
||||||
tfile = Tfile(py_file)
|
tfile = Tfile(py_file)
|
||||||
for tclass in tfile.tclasses():
|
for tclass in tfile.tclasses():
|
||||||
statistics.classes += 1
|
statistics.classes += 1
|
||||||
|
if not quiet:
|
||||||
progress(tclass.name())
|
progress(tclass.name())
|
||||||
for tmethod in tclass.tmethods():
|
for tmethod in tclass.tmethods():
|
||||||
if not selected_methods or tmethod.name() in selected_methods:
|
if not selected_methods or tmethod.name() in selected_methods:
|
||||||
statistics.methods += 1
|
statistics.methods += 1
|
||||||
|
if not quiet:
|
||||||
progress(tmethod.name())
|
progress(tmethod.name())
|
||||||
tmethod.run(tmpdir, statistics)
|
tmethod.run(tmpdir, statistics)
|
||||||
return statistics
|
return statistics
|
||||||
@ -688,6 +690,8 @@ def parse_options():
|
|||||||
parser = argparse.ArgumentParser('cmdtest')
|
parser = argparse.ArgumentParser('cmdtest')
|
||||||
parser.add_argument("-v", "--verbose", action="store_true",
|
parser.add_argument("-v", "--verbose", action="store_true",
|
||||||
help="be more verbose")
|
help="be more verbose")
|
||||||
|
parser.add_argument("-q", "--quiet", action="store_true",
|
||||||
|
help="be more quiet")
|
||||||
parser.add_argument("arg", nargs="*",
|
parser.add_argument("arg", nargs="*",
|
||||||
help="CMDTEST_*.py files / test methods")
|
help="CMDTEST_*.py files / test methods")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
@ -710,7 +714,8 @@ 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)
|
statistics = test_files(py_files, selected_methods, options.quiet)
|
||||||
|
if not options.quiet:
|
||||||
print()
|
print()
|
||||||
print(statistics)
|
print(statistics)
|
||||||
print()
|
print()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user