Skip to content

Commit 280dcaa

Browse files
authored
Merge branch 'main' into feat/pr_issue_templates
2 parents ffc2649 + 71f1e3c commit 280dcaa

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

.github/workflows/development.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
- name: Install dependencies
125125
run: pip install tox
126126
- name: Run unit tests
127-
run: tox -e test-unit -- -m "smoke or sanity"
127+
run: tox -e test-unit
128128

129129
ui-unit-tests:
130130
permissions:

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
- name: Install dependencies
126126
run: pip install tox
127127
- name: Run unit tests
128-
run: tox -e test-unit -- -m "smoke or sanity"
128+
run: tox -e test-unit
129129

130130
ui-unit-tests:
131131
permissions:

src/guidellm/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
@click.group()
28+
@click.version_option(package_name="guidellm", message="guidellm version: %(version)s")
2829
def cli():
2930
pass
3031

@@ -51,7 +52,7 @@ def benchmark():
5152
readable=True,
5253
file_okay=True,
5354
dir_okay=False,
54-
path_type=Path, # type: ignore[type-var]
55+
path_type=Path,
5556
),
5657
click.Choice(get_builtin_scenarios()),
5758
),

tests/unit/entrypoints/test_benchmark_from_file_entrypoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def cleanup():
2828
item.unlink() # Deletes the file
2929

3030

31+
@pytest.mark.skip(reason="currently broken")
3132
def test_display_entrypoint_json(capfd, get_test_asset_dir):
3233
generic_test_display_entrypoint(
3334
"benchmarks_stripped.json",
@@ -36,6 +37,7 @@ def test_display_entrypoint_json(capfd, get_test_asset_dir):
3637
)
3738

3839

40+
@pytest.mark.skip(reason="currently broken")
3941
def test_display_entrypoint_yaml(capfd, get_test_asset_dir):
4042
generic_test_display_entrypoint(
4143
"benchmarks_stripped.yaml",
@@ -60,6 +62,7 @@ def generic_test_display_entrypoint(filename, capfd, get_test_asset_dir):
6062
assert out == expected_output
6163

6264

65+
@pytest.mark.skip(reason="currently broken")
6366
def test_reexporting_benchmark(get_test_asset_dir, cleanup):
6467
asset_dir = get_test_asset_dir()
6568
source_file = asset_dir / "benchmarks_stripped.json"

tests/unit/test_cli.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""
2+
Unit tests for CLI functionality, specifically the version flag.
3+
"""
4+
5+
import pytest
6+
from click.testing import CliRunner
7+
8+
from guidellm.__main__ import cli
9+
10+
11+
@pytest.mark.smoke
12+
def test_version_flag_long():
13+
"""Test that --version flag works correctly."""
14+
runner = CliRunner()
15+
result = runner.invoke(cli, ["--version"])
16+
17+
assert result.exit_code == 0
18+
assert "guidellm version:" in result.output
19+
assert result.output.strip().startswith("guidellm version:")
20+
21+
22+
@pytest.mark.smoke
23+
def test_version_flag_displays_actual_version():
24+
"""Test that --version displays the actual version from version.py."""
25+
runner = CliRunner()
26+
result = runner.invoke(cli, ["--version"])
27+
28+
assert result.exit_code == 0
29+
import re
30+
31+
version_pattern = r"guidellm version: \d+\.\d+"
32+
assert re.search(version_pattern, result.output)
33+
34+
35+
@pytest.mark.smoke
36+
def test_version_flag_exits_cleanly():
37+
"""Test that --version exits without processing other commands."""
38+
runner = CliRunner()
39+
result = runner.invoke(cli, ["--version", "benchmark"])
40+
41+
assert result.exit_code == 0
42+
assert "guidellm version:" in result.output
43+
assert "Commands to run a new benchmark" not in result.output
44+
45+
46+
@pytest.mark.smoke
47+
def test_help_shows_version_option():
48+
"""Test that --help shows the --version option."""
49+
runner = CliRunner()
50+
result = runner.invoke(cli, ["--help"])
51+
52+
assert result.exit_code == 0
53+
assert "--version" in result.output
54+
assert "Show the version and exit" in result.output
55+
56+
57+
@pytest.mark.smoke
58+
def test_other_commands_still_work():
59+
"""Test that other CLI commands still work after adding version flag."""
60+
runner = CliRunner()
61+
result = runner.invoke(cli, ["--help"])
62+
63+
assert result.exit_code == 0
64+
assert "benchmark" in result.output
65+
assert "config" in result.output
66+
assert "preprocess" in result.output
67+
68+
69+
@pytest.mark.smoke
70+
def test_version_flag_case_sensitivity():
71+
"""Test that --version flag is case sensitive."""
72+
runner = CliRunner()
73+
74+
result = runner.invoke(cli, ["--version"])
75+
assert result.exit_code == 0
76+
assert "guidellm version:" in result.output
77+
78+
# --VERSION should not work
79+
result = runner.invoke(cli, ["--VERSION"])
80+
assert result.exit_code != 0
81+
assert "No such option" in result.output
82+
83+
84+
@pytest.mark.integration
85+
def test_version_integration_with_actual_version():
86+
"""Integration test to verify version matches importlib.metadata."""
87+
import importlib.metadata
88+
89+
try:
90+
actual_version = importlib.metadata.version("guidellm")
91+
92+
runner = CliRunner()
93+
result = runner.invoke(cli, ["--version"])
94+
95+
assert result.exit_code == 0
96+
expected_output = f"guidellm version: {actual_version}"
97+
assert expected_output in result.output
98+
except importlib.metadata.PackageNotFoundError:
99+
# If package is not installed, the CLI should show an error
100+
# This is expected behavior when the package isn't properly installed
101+
runner = CliRunner()
102+
result = runner.invoke(cli, ["--version"])
103+
104+
# Click will handle the error when package is not found
105+
assert result.exit_code != 0

0 commit comments

Comments
 (0)