Loading scripts/dev/coverage.py +2 −2 Changes for scripts/dev/coverage.py: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -228,7 +228,7 @@ def merge(args): "--rc", "branch_coverage=1", "--ignore-errors","inconsistent,inconsistent,corrupt,corrupt,mismatch,mismatch,negative,negative,version,version,empty,empty,unused,unused,source,source,missing,missing,count,count,gcov,gcov,range,range", "--quiet" if args.verbosity > 3 else "", *(f"--add-tracefile={t}" for t in tracefiles), *(arg for t in tracefiles for arg in ("--add-tracefile", str(t))), "--output-file=$OUTPUT"]) logger.info("Executing command pipeline") Loading Loading @@ -282,7 +282,7 @@ def cobertura_report(args): cmdline=[ "lcov_cobertura", f"{args.input_tracefile}", "--base-dir={args.base_dir}", f"--base-dir={args.base_dir}" if args.base_dir else "", f"--output={output_file}"]) logger.info("Generating Cobertura report...") Loading tests/scripts/test_coverage.py 0 → 100644 +50 −0 Changes for tests/scripts/test_coverage.py: 50 added lines, 0 removed lines. Original line number Diff line number Diff line import importlib.util from argparse import Namespace from pathlib import Path MODULE_PATH = Path(__file__).parents[2] / "scripts" / "dev" / "coverage.py" SPEC = importlib.util.spec_from_file_location("coverage_helper", MODULE_PATH) coverage = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(coverage) def test_merge_passes_tracefiles_as_separate_arguments(tmp_path, monkeypatch): traces = [tmp_path / "first trace.info", tmp_path / "second.info"] output = tmp_path / "merged.info" commands = [] def run(command): commands.append(command._cmdline) target = next(arg.split("=", 1)[1] for arg in command._cmdline if arg.startswith("--output-file=")) Path(target).write_text("merged") monkeypatch.setattr(coverage.Command, "run", run) coverage.merge(Namespace(output_file=output, tracefiles=traces, search_pattern=None, verbosity=0)) args = commands[0] index = args.index("--add-tracefile") assert args[index:index + 4] == [ "--add-tracefile", str(traces[0]), "--add-tracefile", str(traces[1])] assert output.read_text() == "merged" def test_cobertura_interpolates_base_directory(tmp_path, monkeypatch): commands = [] monkeypatch.setattr(coverage.Command, "run", lambda command: commands.append(command._cmdline)) coverage.cobertura_report(Namespace( output_file=tmp_path / "coverage.xml", input_tracefile=tmp_path / "coverage.info", base_dir=tmp_path)) assert f"--base-dir={tmp_path}" in commands[0] def test_cobertura_omits_unspecified_base_directory(tmp_path, monkeypatch): commands = [] monkeypatch.setattr(coverage.Command, "run", lambda command: commands.append(command._cmdline)) coverage.cobertura_report(Namespace( output_file=tmp_path / "coverage.xml", input_tracefile=tmp_path / "coverage.info", base_dir=None)) assert not any(arg.startswith("--base-dir=") for arg in commands[0]) No newline at end of file Loading
scripts/dev/coverage.py +2 −2 Changes for scripts/dev/coverage.py: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -228,7 +228,7 @@ def merge(args): "--rc", "branch_coverage=1", "--ignore-errors","inconsistent,inconsistent,corrupt,corrupt,mismatch,mismatch,negative,negative,version,version,empty,empty,unused,unused,source,source,missing,missing,count,count,gcov,gcov,range,range", "--quiet" if args.verbosity > 3 else "", *(f"--add-tracefile={t}" for t in tracefiles), *(arg for t in tracefiles for arg in ("--add-tracefile", str(t))), "--output-file=$OUTPUT"]) logger.info("Executing command pipeline") Loading Loading @@ -282,7 +282,7 @@ def cobertura_report(args): cmdline=[ "lcov_cobertura", f"{args.input_tracefile}", "--base-dir={args.base_dir}", f"--base-dir={args.base_dir}" if args.base_dir else "", f"--output={output_file}"]) logger.info("Generating Cobertura report...") Loading
tests/scripts/test_coverage.py 0 → 100644 +50 −0 Changes for tests/scripts/test_coverage.py: 50 added lines, 0 removed lines. Original line number Diff line number Diff line import importlib.util from argparse import Namespace from pathlib import Path MODULE_PATH = Path(__file__).parents[2] / "scripts" / "dev" / "coverage.py" SPEC = importlib.util.spec_from_file_location("coverage_helper", MODULE_PATH) coverage = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(coverage) def test_merge_passes_tracefiles_as_separate_arguments(tmp_path, monkeypatch): traces = [tmp_path / "first trace.info", tmp_path / "second.info"] output = tmp_path / "merged.info" commands = [] def run(command): commands.append(command._cmdline) target = next(arg.split("=", 1)[1] for arg in command._cmdline if arg.startswith("--output-file=")) Path(target).write_text("merged") monkeypatch.setattr(coverage.Command, "run", run) coverage.merge(Namespace(output_file=output, tracefiles=traces, search_pattern=None, verbosity=0)) args = commands[0] index = args.index("--add-tracefile") assert args[index:index + 4] == [ "--add-tracefile", str(traces[0]), "--add-tracefile", str(traces[1])] assert output.read_text() == "merged" def test_cobertura_interpolates_base_directory(tmp_path, monkeypatch): commands = [] monkeypatch.setattr(coverage.Command, "run", lambda command: commands.append(command._cmdline)) coverage.cobertura_report(Namespace( output_file=tmp_path / "coverage.xml", input_tracefile=tmp_path / "coverage.info", base_dir=tmp_path)) assert f"--base-dir={tmp_path}" in commands[0] def test_cobertura_omits_unspecified_base_directory(tmp_path, monkeypatch): commands = [] monkeypatch.setattr(coverage.Command, "run", lambda command: commands.append(command._cmdline)) coverage.cobertura_report(Namespace( output_file=tmp_path / "coverage.xml", input_tracefile=tmp_path / "coverage.info", base_dir=None)) assert not any(arg.startswith("--base-dir=") for arg in commands[0]) No newline at end of file