Skip to content

Commit

Permalink
Add --stats-as-error (-E) argument: (#73)
Browse files Browse the repository at this point in the history
* Add PDK_STATS_AS_ERROR environment variable
* Add status_failable dict to control which statuses are considered errors
* Scan t_stat for failure cases
  • Loading branch information
jhunkeler committed Aug 26, 2021
1 parent 0a514b5 commit dd3962f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions pandokia/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ def complex_readpass():
'M': 'missing',
}

# statuses that always indicate failure
status_failable = {
'P': False,
'F': True,
'E': True,
'D': False,
'M': True,
}

#####
#
# used if the user has nothing in their email preferences
Expand Down
26 changes: 23 additions & 3 deletions pandokia/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
-r / --recursive
search subdirectories
-E / --stats-as-error
exit non-zero based on test run statistics
or set PDK_STATS_AS_ERROR to any value to enable
Default is False
--log file
write the PDK report log into this file
Expand Down Expand Up @@ -73,15 +79,17 @@ def run(args):
parallel = os.environ.get("PDK_PARALLEL", None)
tmpdir = os.environ.get("PDK_TMP", None)
host = os.environ.get("PDK_HOST", None)
stats_as_error = os.environ.get("PDK_STATS_AS_ERROR", "")
verbose = 0 # not implemented
dry_run = 0 # not implemented

if args == []:
args = ['-r', '.']
opts, args = getopt.gnu_getopt(args, "rvpsw",
opts, args = getopt.gnu_getopt(args, "rvpswE",
["recursive", "environment_already_set", "dir", "log=",
"project=", "test_run=", "test_prefix=",
"show-command", "verbose", "parallel=", "help", "context=",
"stats_as_error",
])
for (opt, optarg) in opts:
if opt == '-r' or opt == '--recursive':
Expand Down Expand Up @@ -115,6 +123,8 @@ def run(args):
host = optarg
elif opt == '--custom':
custom = optarg
elif opt == '--stats-as-error' or opt == '-E':
stats_as_error = "1"

if project is None:
project = default_project()
Expand All @@ -124,7 +134,6 @@ def run(args):
log = "PDK_DEFAULT.LOG." + test_run
if host is None:
host = common.gethostname()

if parallel is not None:
os.environ['PDK_PARALLEL'] = parallel

Expand All @@ -136,6 +145,7 @@ def run(args):
os.environ['PDK_CONTEXT'] = context
os.environ['PDK_CUSTOM'] = custom
os.environ['PDK_HOST'] = host
os.environ['PDK_STATS_AS_ERROR'] = stats_as_error

initialized_status_file = 0
if 'PDK_STATUSFILE' not in os.environ:
Expand All @@ -162,6 +172,7 @@ def run(args):
# environment_already_set=environment_already_set ) bug: we need to
# get this optimization in some how

was_error = 0
if recursive:
import pandokia.run_recursive
(was_error, t_stat) = pandokia.run_recursive.run(args, envgetter)
Expand All @@ -170,7 +181,6 @@ def run(args):
# of each file/dir that we ran, but if there are more than one file/dir, we will print
# the total in t_stat.
t_stat = {}
was_error = 0
n_things_run = 0
for x in args:
try:
Expand Down Expand Up @@ -216,6 +226,16 @@ def run(args):
pandokia.run_status.pdkrun_status('', slot=x)
os.unlink(os.environ['PDK_STATUSFILE'])

# Set error based on recorded test stats
if stats_as_error:
for key, value in t_stat.items():
if common.cfg.status_failable[key] and value:
# e.g. any of: error != 0
# fail != 0
# missing != 0
was_error = 1
break

return (was_error, t_stat)


Expand Down

0 comments on commit dd3962f

Please sign in to comment.