minimal ARGV parsing, similar to Ruby-version
This commit is contained in:
parent
6faf657da0
commit
96b8f3a42f
@ -22,7 +22,9 @@
|
|||||||
|
|
||||||
# This is a minimal Python version of "cmdtest".
|
# This is a minimal Python version of "cmdtest".
|
||||||
|
|
||||||
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
|
import glob
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -522,16 +524,39 @@ class Tfile:
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
def parse_otions():
|
||||||
|
parser = argparse.ArgumentParser('jcons')
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true",
|
||||||
|
help="be more verbose")
|
||||||
|
parser.add_argument("arg", nargs="*",
|
||||||
|
help="CMDTEST_*.py files / test methods")
|
||||||
|
options = parser.parse_args()
|
||||||
|
py_files = []
|
||||||
|
selected_methods = set()
|
||||||
|
for arg in options.arg:
|
||||||
|
if re.match(r'CMDTEST_.*\.py$', arg):
|
||||||
|
py_files.append(arg)
|
||||||
|
else:
|
||||||
|
selected_methods.add(arg)
|
||||||
|
if not py_files:
|
||||||
|
py_files = glob.glob("CMDTEST_*.py")
|
||||||
|
if not py_files:
|
||||||
|
print("ERROR: no CMDTEST_*.py files found")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
return options, py_files, selected_methods
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
selected = set(sys.argv[1:])
|
options, py_files, selected_methods = parse_otions()
|
||||||
tfile = Tfile("CMDTEST_example.py")
|
for py_file in py_files:
|
||||||
tmpdir = Tmpdir()
|
tfile = Tfile(py_file)
|
||||||
for tclass in tfile.tclasses():
|
tmpdir = Tmpdir()
|
||||||
progress(tclass.name())
|
for tclass in tfile.tclasses():
|
||||||
for tmethod in tclass.tmethods():
|
progress(tclass.name())
|
||||||
if not selected or tmethod.name() in selected:
|
for tmethod in tclass.tmethods():
|
||||||
progress(tmethod.name())
|
if not selected_methods or tmethod.name() in selected_methods:
|
||||||
tmethod.run(tmpdir)
|
progress(tmethod.name())
|
||||||
|
tmethod.run(tmpdir)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user