Skip to content

Commit 6603dd7

Browse files
authored
fix: Add fix and test for 'triton' with no args (#89)
1 parent 36a425e commit 6603dd7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/triton_cli/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,10 @@ def parse_args(argv=None):
444444

445445
argv_ = argv if argv is not None else sys.argv[1:]
446446
# Add special argparse handling for passthrough to genai-perf CLI
447-
if argv_[0] == "profile":
447+
if len(argv_) > 1 and argv_[0] == "profile":
448448
args, unknown_args = parser.parse_known_args(argv_)
449449
args = add_unknown_args_to_args(args, unknown_args)
450450
else:
451451
args = parser.parse_args(argv_)
452+
452453
return args

tests/test_cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949

5050

5151
class TestRepo:
52+
def test_noargs(self):
53+
# Test that running 'triton' with no args will fail with a parsing error
54+
# NOTE: pytest needs to be run with `--capture=sys` to read the output,
55+
# so just assert the error code and exception type for now.
56+
args = []
57+
with pytest.raises(SystemExit) as excinfo:
58+
TritonCommands._run_and_capture_stdout(args)
59+
60+
# argparse returns code 2 for error / missing arguments
61+
assert excinfo.value.code == 2
62+
5263
@pytest.mark.parametrize("repo", TEST_REPOS)
5364
def test_clear(self, repo):
5465
TritonCommands._clear(repo)

0 commit comments

Comments
 (0)