|
15 | 15 | from pathlib import Path |
16 | 16 | import sys |
17 | 17 |
|
18 | | -# Add the project root to the Python path to allow for application-specific imports. |
19 | | -sys.path.insert(0, str(Path(__file__).resolve().parents[3])) |
20 | | - |
21 | | -from scripts import run_and_publish_benchmark # noqa: E402 |
| 18 | +from scripts import run_and_publish_benchmark |
22 | 19 |
|
| 20 | +sys.path.insert(0, str(Path(__file__).resolve().parents[3])) |
23 | 21 |
|
24 | | -def test_collect_benchmark_result(tmp_path: Path): |
25 | | - """Tests the collect_benchmark_result function. |
26 | | -
|
27 | | - This test verifies that the function correctly reads benchmark result |
28 | | - files from a specified directory, processes them, and returns a |
29 | | - pandas DataFrame with the expected data and types. |
30 | 22 |
|
31 | | - Args: |
32 | | - tmp_path (Path): The pytest fixture providing a temporary directory path. |
33 | | - """ |
34 | | - # Arrange: Create dummy log files with benchmark data. |
| 23 | +def test_collect_benchmark_result(tmp_path): |
| 24 | + # Create dummy log files |
35 | 25 | (tmp_path / "benchmark1.bytesprocessed").write_text("100") |
36 | 26 | (tmp_path / "benchmark1.slotmillis").write_text("1000") |
37 | 27 | (tmp_path / "benchmark1.bq_exec_time_seconds").write_text("1.0") |
38 | 28 | (tmp_path / "benchmark1.local_exec_time_seconds").write_text("2.0") |
39 | 29 | (tmp_path / "benchmark1.query_char_count").write_text("50") |
40 | 30 | (tmp_path / "benchmark1.totalrows").write_text("10") |
41 | 31 |
|
42 | | - # Act: Collect the benchmark results from the temporary directory. |
43 | | - # The second argument '1' is a placeholder for the number of runs. |
| 32 | + # Collect the benchmark results |
44 | 33 | df, error_message = run_and_publish_benchmark.collect_benchmark_result( |
45 | 34 | str(tmp_path), 1 |
46 | 35 | ) |
47 | 36 |
|
48 | | - # Assert: Verify the contents and structure of the resulting DataFrame. |
49 | | - assert error_message is None, "Expected no error messages." |
50 | | - assert len(df) == 1, "DataFrame should contain exactly one row." |
| 37 | + # Assert that the DataFrame is correct |
| 38 | + assert error_message is None |
| 39 | + assert len(df) == 1 |
51 | 40 | assert df["Benchmark_Name"][0] == "benchmark1" |
52 | 41 | assert df["Bytes_Processed"][0] == 100 |
53 | 42 | assert df["Slot_Millis"][0] == 1000 |
|
0 commit comments