mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-07-01 11:47:33 +00:00
Tighten nvbench-compare argument parsing
Let argparse derive the program name from the actual invocation instead of hardcoding nvbench_compare, so help and error output match the installed nvbench-compare entry point. Declare comparison inputs as explicit positional arguments and use parse_args() instead of parse_known_args(). This preserves --dump-config without input files while rejecting unknown options through argparse rather than treating typoed flags as JSON paths. Add regression coverage for rejecting an unknown CLI option.
This commit is contained in:
@@ -2960,7 +2960,7 @@ def main() -> int:
|
||||
The number of detected regressions is reported in the summary output.
|
||||
"""
|
||||
help_text = "%(prog)s [reference.json compare.json | reference_dir/ compare_dir/]"
|
||||
parser = argparse.ArgumentParser(prog="nvbench_compare", usage=help_text)
|
||||
parser = argparse.ArgumentParser(usage=help_text)
|
||||
parser.add_argument(
|
||||
"--ignore-devices",
|
||||
dest="ignore_devices",
|
||||
@@ -3054,8 +3054,10 @@ def main() -> int:
|
||||
action=OrderedBenchmarkFilterAction,
|
||||
help="Filter by benchmark name (can repeat)",
|
||||
)
|
||||
parser.add_argument("files_or_dirs", nargs="*")
|
||||
|
||||
args, files_or_dirs = parser.parse_known_args()
|
||||
args = parser.parse_args()
|
||||
files_or_dirs = args.files_or_dirs
|
||||
try:
|
||||
comparison_preset, comparison_thresholds = resolve_comparison_thresholds(
|
||||
args.preset, args.config
|
||||
|
||||
@@ -1969,6 +1969,19 @@ def test_main_dump_config_merges_config_and_cli_preset(
|
||||
assert "sample_coverage = 0.93" in output
|
||||
|
||||
|
||||
def test_main_rejects_unknown_options(monkeypatch, nvbench_compare):
|
||||
monkeypatch.setattr(
|
||||
sys,
|
||||
"argv",
|
||||
["nvbench_compare", "--dispaly", "explain", "ref.json", "cmp.json"],
|
||||
)
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
nvbench_compare.main()
|
||||
|
||||
assert exc_info.value.code == 2
|
||||
|
||||
|
||||
def test_main_prints_bulk_debug_python_to_stdout(monkeypatch, capsys, nvbench_compare):
|
||||
devices = [{"id": 0, "name": "Test GPU"}]
|
||||
root = {
|
||||
|
||||
Reference in New Issue
Block a user