|
1 | | -import os |
2 | 1 | import unittest |
| 2 | +from pathlib import Path |
| 3 | + |
3 | 4 | import pytest |
4 | 5 |
|
5 | 6 | from guidellm.benchmark import display_benchmarks_report |
6 | 7 |
|
7 | | -@pytest.fixture() |
| 8 | + |
| 9 | +@pytest.fixture |
8 | 10 | def get_test_asset_dir(): |
9 | | - def _() -> str: |
10 | | - return os.path.dirname(os.path.abspath(__file__)) + "/assets" |
| 11 | + def _() -> Path: |
| 12 | + return Path(__file__).parent / "assets" |
11 | 13 |
|
12 | 14 | return _ |
13 | 15 |
|
14 | 16 |
|
15 | 17 | def test_display_entrypoint_json(capfd, get_test_asset_dir): |
16 | | - generic_test_display_entrypoint("benchmarks_stripped.json", capfd, get_test_asset_dir) |
| 18 | + generic_test_display_entrypoint( |
| 19 | + "benchmarks_stripped.json", |
| 20 | + capfd, |
| 21 | + get_test_asset_dir, |
| 22 | + ) |
17 | 23 |
|
18 | 24 |
|
19 | 25 | def test_display_entrypoint_yaml(capfd, get_test_asset_dir): |
20 | | - generic_test_display_entrypoint("benchmarks_stripped.yaml", capfd, get_test_asset_dir) |
| 26 | + generic_test_display_entrypoint( |
| 27 | + "benchmarks_stripped.yaml", |
| 28 | + capfd, |
| 29 | + get_test_asset_dir, |
| 30 | + ) |
21 | 31 |
|
22 | 32 |
|
23 | 33 | def generic_test_display_entrypoint(filename, capfd, get_test_asset_dir): |
24 | 34 | asset_dir = get_test_asset_dir() |
25 | | - display_benchmarks_report(asset_dir + "/" + filename) |
| 35 | + display_benchmarks_report(asset_dir / filename) |
26 | 36 | out, err = capfd.readouterr() |
27 | | - expected_output_path = asset_dir + "/benchmarks_stripped_output.txt" |
28 | | - with open(expected_output_path, 'r', encoding='utf_8') as file: |
| 37 | + expected_output_path = asset_dir / "benchmarks_stripped_output.txt" |
| 38 | + with expected_output_path.open(encoding="utf_8") as file: |
29 | 39 | expected_output = file.read() |
30 | 40 | assert out == expected_output |
31 | 41 |
|
32 | 42 |
|
33 | | -if __name__ == '__main__': |
| 43 | +if __name__ == "__main__": |
34 | 44 | unittest.main() |
0 commit comments