Skip to content

Commit 46b5e87

Browse files
[GuideLLM Refactor] Fix output tests (#387)
## Summary The output formats changed, and therefore the existing tests broke. Keep in mind that some of the tested code may be replaced in the near future, as a new console output is in the list of things for 0.5.0. I ran into issues with duplicate fields on the mock objects for all computed fields. Those tests are skipped. Let me know if you have a plan on how to fix this. This PR will be in a draft state until the CSV changes are merged. ## Test Plan - Run the tests with pytest. - Run the tox type lints. --- - [x] "I certify that all code in this PR is my own, except as noted below." ## Use of AI - [x] Includes AI-assisted code completion - [ ] Includes code generated by an AI application - [ ] Includes AI-generated tests (NOTE: AI written tests should have a docstring that includes `## WRITTEN BY AI ##`)
2 parents 89113d8 + ff9a61a commit 46b5e87

File tree

4 files changed

+38
-90
lines changed

4 files changed

+38
-90
lines changed

src/guidellm/benchmark/output.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,6 @@ def _get_profile_str(self, benchmark: GenerativeBenchmark) -> str:
330330

331331
return ", ".join(f"{key}={value}" for key, value in profile_args.items())
332332

333-
def _get_args_str(self, benchmark: GenerativeBenchmark) -> str:
334-
args = benchmark.args
335-
args_dict = OrderedDict(
336-
{
337-
"max_number": args.max_number,
338-
"max_duration": args.max_duration,
339-
"warmup_number": args.warmup_number,
340-
"warmup_duration": args.warmup_duration,
341-
"cooldown_number": args.cooldown_number,
342-
"cooldown_duration": args.cooldown_duration,
343-
}
344-
)
345-
return ", ".join(f"{key}={value}" for key, value in args_dict.items())
346-
347333
def _print_section_header(self, title: str, indent: int = 0, new_lines: int = 2):
348334
self._print_line(
349335
f"{title}:",

src/guidellm/scheduler/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ScheduledRequestInfo(StandardBaseModel):
174174
)
175175
scheduler_start_time: float = Field(
176176
description="Unix timestamp for the local time when scheduler processing began",
177-
default=-1,
177+
default=-1.0,
178178
)
179179

180180
error: str | None = Field(

tests/unit/benchmark/test_output.py

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from guidellm.benchmark import (
1111
GenerativeBenchmarksReport,
1212
)
13-
from guidellm.benchmark.output import GenerativeBenchmarksConsole
13+
from guidellm.benchmark.output import GenerativeBenchmarkerConsole, GenerativeBenchmarkerCSV
1414
from tests.unit.mock_benchmark import mock_generative_benchmark
1515

1616

@@ -37,8 +37,8 @@ def test_generative_benchmark_marshalling():
3737
deserialized = GenerativeBenchmarksReport.model_validate(serialized)
3838
deserialized_benchmark = deserialized.benchmarks[0]
3939

40-
for field in mock_benchmark.model_fields:
41-
assert getattr(mock_benchmark, field) == getattr(deserialized_benchmark, field)
40+
# model_dump as workaround for duplicate fields for computed fields.
41+
assert mock_benchmark.model_dump() == deserialized_benchmark.model_dump()
4242

4343

4444
def test_file_json():
@@ -55,8 +55,8 @@ def test_file_json():
5555
loaded_report = GenerativeBenchmarksReport.load_file(mock_path)
5656
loaded_benchmark = loaded_report.benchmarks[0]
5757

58-
for field in mock_benchmark.model_fields:
59-
assert getattr(mock_benchmark, field) == getattr(loaded_benchmark, field)
58+
# model_dump as workaround for duplicate fields for computed fields.
59+
assert mock_benchmark.model_dump() == loaded_benchmark.model_dump()
6060

6161
mock_path.unlink()
6262

@@ -75,18 +75,20 @@ def test_file_yaml():
7575
loaded_report = GenerativeBenchmarksReport.load_file(mock_path)
7676
loaded_benchmark = loaded_report.benchmarks[0]
7777

78-
for field in mock_benchmark.model_fields:
79-
assert getattr(mock_benchmark, field) == getattr(loaded_benchmark, field)
78+
# model_dump as workaround for duplicate fields for computed fields.
79+
assert mock_benchmark.model_dump() == loaded_benchmark.model_dump()
8080

8181
mock_path.unlink()
8282

83-
84-
def test_file_csv():
83+
@pytest.mark.skip(reason="CSV fix not merged yet")
84+
@pytest.mark.asyncio
85+
async def test_file_csv():
8586
mock_benchmark = mock_generative_benchmark()
8687
report = GenerativeBenchmarksReport(benchmarks=[mock_benchmark])
8788

8889
mock_path = Path("mock_report.csv")
89-
report.save_csv(mock_path)
90+
csv_benchmarker = GenerativeBenchmarkerCSV(output_path=mock_path)
91+
await csv_benchmarker.finalize(report)
9092

9193
with mock_path.open("r") as file:
9294
reader = csv.reader(file)
@@ -100,109 +102,72 @@ def test_file_csv():
100102

101103

102104
def test_console_benchmarks_profile_str():
103-
console = GenerativeBenchmarksConsole(enabled=True)
105+
console = GenerativeBenchmarkerConsole()
104106
mock_benchmark = mock_generative_benchmark()
105-
console.benchmarks = [mock_benchmark]
106107
assert (
107-
console.benchmarks_profile_str == "type=synchronous, strategies=['synchronous']"
108-
)
109-
110-
111-
def test_console_benchmarks_args_str():
112-
console = GenerativeBenchmarksConsole(enabled=True)
113-
mock_benchmark = mock_generative_benchmark()
114-
console.benchmarks = [mock_benchmark]
115-
assert console.benchmarks_args_str == (
116-
"max_number=None, max_duration=10.0, warmup_number=None, "
117-
"warmup_duration=None, cooldown_number=None, cooldown_duration=None"
108+
console._get_profile_str(mock_benchmark) == "type=synchronous, strategies=['synchronous']"
118109
)
119110

120111

121-
def test_console_benchmarks_worker_desc_str():
122-
console = GenerativeBenchmarksConsole(enabled=True)
123-
mock_benchmark = mock_generative_benchmark()
124-
console.benchmarks = [mock_benchmark]
125-
assert console.benchmarks_worker_desc_str == str(mock_benchmark.worker)
126-
127-
128-
def test_console_benchmarks_request_loader_desc_str():
129-
console = GenerativeBenchmarksConsole(enabled=True)
130-
mock_benchmark = mock_generative_benchmark()
131-
console.benchmarks = [mock_benchmark]
132-
assert console.benchmarks_request_loader_desc_str == str(
133-
mock_benchmark.request_loader
134-
)
135-
136-
137-
def test_console_benchmarks_extras_str():
138-
console = GenerativeBenchmarksConsole(enabled=True)
139-
mock_benchmark = mock_generative_benchmark()
140-
console.benchmarks = [mock_benchmark]
141-
assert console.benchmarks_extras_str == "None"
142-
143-
144112
def test_console_print_section_header():
145-
console = GenerativeBenchmarksConsole(enabled=True)
113+
console = GenerativeBenchmarkerConsole()
146114
with patch.object(console.console, "print") as mock_print:
147-
console.print_section_header("Test Header")
115+
console._print_section_header("Test Header")
148116
mock_print.assert_called_once()
149117

150118

151119
def test_console_print_labeled_line():
152-
console = GenerativeBenchmarksConsole(enabled=True)
120+
console = GenerativeBenchmarkerConsole()
153121
with patch.object(console.console, "print") as mock_print:
154-
console.print_labeled_line("Label", "Value")
122+
console._print_labeled_line("Label", "Value")
155123
mock_print.assert_called_once()
156124

157125

158126
def test_console_print_line():
159-
console = GenerativeBenchmarksConsole(enabled=True)
127+
console = GenerativeBenchmarkerConsole()
160128
with patch.object(console.console, "print") as mock_print:
161-
console.print_line("Test Line")
129+
console._print_line("Test Line")
162130
mock_print.assert_called_once()
163131

164132

165133
def test_console_print_table():
166-
console = GenerativeBenchmarksConsole(enabled=True)
134+
console = GenerativeBenchmarkerConsole()
167135
headers = ["Header1", "Header2"]
168136
rows = [["Row1Col1", "Row1Col2"], ["Row2Col1", "Row2Col2"]]
169137
with (
170-
patch.object(console, "print_section_header") as mock_header,
171-
patch.object(console, "print_table_divider") as mock_divider,
172-
patch.object(console, "print_table_row") as mock_row,
138+
patch.object(console, "_print_section_header") as mock_header,
139+
patch.object(console, "_print_table_divider") as mock_divider,
140+
patch.object(console, "_print_table_row") as mock_row,
173141
):
174-
console.print_table(headers, rows, "Test Table")
142+
console._print_table(headers, rows, "Test Table")
175143
mock_header.assert_called_once()
176144
mock_divider.assert_called()
177145
mock_row.assert_called()
178146

179147

180148
def test_console_print_benchmarks_metadata():
181-
console = GenerativeBenchmarksConsole(enabled=True)
149+
console = GenerativeBenchmarkerConsole()
182150
mock_benchmark = mock_generative_benchmark()
183-
console.benchmarks = [mock_benchmark]
184151
with (
185-
patch.object(console, "print_section_header") as mock_header,
186-
patch.object(console, "print_labeled_line") as mock_labeled,
152+
patch.object(console, "_print_section_header") as mock_header,
153+
patch.object(console, "_print_labeled_line") as mock_labeled,
187154
):
188-
console.print_benchmarks_metadata()
155+
console._print_benchmarks_metadata([mock_benchmark])
189156
mock_header.assert_called_once()
190157
mock_labeled.assert_called()
191158

192159

193160
def test_console_print_benchmarks_info():
194-
console = GenerativeBenchmarksConsole(enabled=True)
161+
console = GenerativeBenchmarkerConsole()
195162
mock_benchmark = mock_generative_benchmark()
196-
console.benchmarks = [mock_benchmark]
197-
with patch.object(console, "print_table") as mock_table:
198-
console.print_benchmarks_info()
163+
with patch.object(console, "_print_table") as mock_table:
164+
console._print_benchmarks_info([mock_benchmark])
199165
mock_table.assert_called_once()
200166

201167

202168
def test_console_print_benchmarks_stats():
203-
console = GenerativeBenchmarksConsole(enabled=True)
169+
console = GenerativeBenchmarkerConsole()
204170
mock_benchmark = mock_generative_benchmark()
205-
console.benchmarks = [mock_benchmark]
206-
with patch.object(console, "print_table") as mock_table:
207-
console.print_benchmarks_stats()
171+
with patch.object(console, "_print_table") as mock_table:
172+
console._print_benchmarks_stats([mock_benchmark])
208173
mock_table.assert_called_once()

tests/unit/mock_benchmark.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Mock benchmark objects for unit testing."""
2-
3-
from guidellm.backend import GenerationRequestTimings
2+
from guidellm.backends import GenerationRequestTimings
43
from guidellm.benchmark import (
54
BenchmarkSchedulerStats,
65
GenerativeBenchmark,
@@ -101,7 +100,7 @@ def mock_generative_benchmark() -> GenerativeBenchmark:
101100
worker_targeted_start_delay_avg=0.1,
102101
request_start_delay_avg=0.1,
103102
request_time_avg=0.1,
104-
request_targeted_delay_avg=0.1,
103+
request_targeted_start_delay_avg=0.1,
105104
),
106105
start_time=1000.0,
107106
end_time=2000.0,
@@ -130,8 +129,6 @@ def mock_generative_benchmark() -> GenerativeBenchmark:
130129
scheduler_info=ScheduledRequestInfo(
131130
request_timings=GenerationRequestTimings(
132131
request_start=1,
133-
first_iteration=2,
134-
last_iteration=6,
135132
request_end=6,
136133
)
137134
),

0 commit comments

Comments
 (0)