From 1ac92a45f6c6949987676b7f5061cfc21cba311a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 19 2018 12:57:49 +0000 Subject: Add a show-coverage command Signed-off-by: Pierre-Yves Chibon --- diff --git a/runpaguretests.py b/runpaguretests.py index 882f86f..eeb8055 100755 --- a/runpaguretests.py +++ b/runpaguretests.py @@ -121,6 +121,39 @@ def setup_parser(): ) parser_run.set_defaults(func=do_rerun) + # SHOW-COVERAGE + parser_run = subparsers.add_parser( + "show-coverage", + help="Shows the coverage report from the data in the results folder") + parser_run.add_argument( + "--debug", + dest="debug", + action="store_true", + default=False, + help="Expand the level of data returned.", + ) + parser_run.add_argument( + "--py2", + dest="py2", + action="store_true", + default=False, + help="Runs the tests only in python2 instead of both python2 and python3", + ) + parser_run.add_argument( + "--py3", + dest="py3", + action="store_true", + default=False, + help="Runs the tests only in python3 instead of both python2 and python3", + ) + parser_run.add_argument( + "--results", + default="results", + help="Specify a folder in which the results should be placed " + "(defaults to `results`)", + ) + parser_run.set_defaults(func=do_show_coverage) + return parser @@ -365,36 +398,41 @@ def _run_test_suites(args, suites): return 1 if args.with_coverage: - print() - print("Combining coverage results...") - pyvers = (2, 3) - if args.py2: - pyvers = (2,) - elif args.py3: - pyvers = (3,) - - for pyver in pyvers: - coverfiles = [] - for fname in os.listdir(args.results): - if fname.endswith(".coverage") and fname.startswith("py%d-" % pyver): - coverfiles.append(os.path.join(args.results, fname)) - - cover = None - if pyver == 2: - cover = COVER_PY2 - elif pyver == 3: - cover = COVER_PY3 - - env = {"COVERAGE_FILE": os.path.join(args.results, "combined.coverage")} - cmd = [cover, "combine"] + coverfiles - subprocess.check_call(cmd, env=env) - print("Python %d coverage: " % pyver) - cmd = [cover, "report", "--include=../pagure/*"] - subprocess.check_call(cmd, env=env) + do_show_coverage(args) return 0 +def do_show_coverage(args): + print() + print("Combining coverage results...") + pyvers = (2, 3) + if args.py2: + pyvers = (2,) + elif args.py3: + pyvers = (3,) + + for pyver in pyvers: + coverfiles = [] + for fname in os.listdir(args.results): + if fname.endswith(".coverage") and fname.startswith("py%d-" % pyver): + coverfiles.append(os.path.join(args.results, fname)) + + cover = None + if pyver == 2: + cover = COVER_PY2 + elif pyver == 3: + cover = COVER_PY3 + + env = {"COVERAGE_FILE": os.path.join(args.results, "combined.coverage")} + cmd = [cover, "combine"] + coverfiles + subprocess.check_call(cmd, env=env) + print() + print("Python %d coverage: " % pyver) + cmd = [cover, "report", "--include=../pagure/*"] + subprocess.check_call(cmd, env=env) + + def main(): """ Main function """ # Set up parser for global args