Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
allow regular expression when running unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Aug 21, 2016
1 parent 4f4e185 commit 0cc6df2
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/pyquickhelper/pycode/setup_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def process_standard_options_for_setup(argv,
.. versionchanged:: 1.4
Parameters *use_run_cmd*, *filter_warning* were added.
command *unittests -d 10* and *unittests -d 5* was added to run unit
tests below 10 or 5 seconds.
tests below 10 or 5 seconds. Option ``-e`` and ``-g`` were added to
filter file by regular expression (in with *e*, out with *g*).
"""
if "--help" in argv or "--help-commands" in argv:
process_standard_options_for_setup_help(argv)
Expand All @@ -180,6 +181,7 @@ def process_argv_for_unittest(argv):
d = float(argv[l + 1])
else:
d = None

if "-f" in argv:
l = argv.index("-f")
if l >= len(argv) - 1:
Expand All @@ -189,21 +191,47 @@ def process_argv_for_unittest(argv):
else:
f = None

if f is None and d is None:
if "-e" in argv:
l = argv.index("-e")
if l >= len(argv) - 1:
raise ValueError(
"Option -e should be follow by a regular expression.")
e = re.compile(argv[l + 1])
else:
e = None

if "-g" in argv:
l = argv.index("-g")
if l >= len(argv) - 1:
raise ValueError(
"Option -g should be follow by a regular expression.")
g = re.compile(argv[l + 1])
else:
g = None

if f is None and d is None and e is None and g is None:
return skip_function
elif f is not None:
if d is not None:
raise NotImplementedError(
"Options -f and -d cannot be specified at the same time.")

def allow(name, code, duration):
return f not in name
return allow
else:
# d is not None
def allowd(name, code, duration):
return duration is None or duration > d
return allowd

def ereg(name):
return e is None or e.search(name)

def greg(name):
return g is not None and g.search(name)

if f is not None:
if d is not None:
raise NotImplementedError(
"Options -f and -d cannot be specified at the same time.")

def allow(name, code, duration):
return f not in name and ereg(name) and not greg(name)
return allow
else:
# d is not None
def allowd(name, code, duration):
return (duration is None or duration > d) and ereg(name) and not greg(name)
return allowd

folder = file_or_folder if os.path.isdir(
file_or_folder) else os.path.dirname(file_or_folder)
Expand Down

0 comments on commit 0cc6df2

Please sign in to comment.