Skip to content

Commit

Permalink
Add pytest as req, use parser for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dyastremsky committed Feb 29, 2024
1 parent 394731d commit 26f976a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/c++/perf_analyzer/genai-pa/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ keywords = []
requires-python = ">=3.8,<4"
dependencies = [
"numpy",
"pytest",
"rich"
]

Expand Down
37 changes: 14 additions & 23 deletions src/c++/perf_analyzer/genai-pa/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import sys

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'sys' is not used.

import pytest
from genai_pa import parser
from genai_pa.main import run


Expand All @@ -43,13 +44,13 @@ class TestCLIArguments:
],
)
def test_help_arguments_output_and_exit(self, arg, expected_output, capsys):
with pytest.raises(SystemExit) as exc_info:
run(arg)
with pytest.raises(SystemExit) as excinfo:
_ = parser.parse_args(arg)

# Confirm the exit was successful
assert exc_info.value.code == 0
# Check that the exit was successful
assert excinfo.value.code == 0

# Confirm the message is correct
# Capture that the correct message was displayed
captured = capsys.readouterr()
assert expected_output in captured.out

Expand All @@ -75,26 +76,16 @@ def test_help_arguments_output_and_exit(self, arg, expected_output, capsys):
],
)
def test_arguments_output(self, arg, expected_output, capsys):
combined_args = ["-m", "test_model"] + arg
# Redirect stdout and stderr to capture output
original_stdout, original_stderr = sys.stdout, sys.stderr
sys.stdout, sys.stderr = io.StringIO(), io.StringIO()

try:
# Call the run function
run(combined_args)
finally:
# Restore stdout and stderr
captured_stdout, captured_stderr = (
sys.stdout.getvalue(),
sys.stderr.getvalue(),
)
sys.stdout, sys.stderr = original_stdout, original_stderr
combined_args = ["--model", "test_model"] + arg
_ = parser.parse_args(combined_args)

assert expected_output in captured_stdout
assert "" == captured_stderr # Assuming no error, adjust if needed
# Capture that the correct message was displayed
captured = capsys.readouterr()
assert expected_output in captured.out

def test_arguments_model_not_provided(self):
with pytest.raises(SystemExit) as exc_info:
run()
parser.parse_args()

# Check that the exit was unsuccessful
assert exc_info.value.code != 0

0 comments on commit 26f976a

Please sign in to comment.