|
15 | 15 | from pathlib import Path |
16 | 16 | import sys |
17 | 17 |
|
18 | | -from scripts import run_and_publish_benchmark |
19 | | - |
| 18 | +# Add the project root to the Python path to allow for application-specific imports. |
20 | 19 | sys.path.insert(0, str(Path(__file__).resolve().parents[3])) |
21 | 20 |
|
| 21 | +from scripts import run_and_publish_benchmark # noqa: E402 |
| 22 | + |
| 23 | + |
| 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. |
22 | 30 |
|
23 | | -def test_collect_benchmark_result(tmp_path): |
24 | | - # Create dummy log files |
| 31 | + Args: |
| 32 | + tmp_path (Path): The pytest fixture providing a temporary directory path. |
| 33 | + """ |
| 34 | + # Arrange: Create dummy log files with benchmark data. |
25 | 35 | (tmp_path / "benchmark1.bytesprocessed").write_text("100") |
26 | 36 | (tmp_path / "benchmark1.slotmillis").write_text("1000") |
27 | 37 | (tmp_path / "benchmark1.bq_exec_time_seconds").write_text("1.0") |
28 | 38 | (tmp_path / "benchmark1.local_exec_time_seconds").write_text("2.0") |
29 | 39 | (tmp_path / "benchmark1.query_char_count").write_text("50") |
30 | 40 | (tmp_path / "benchmark1.totalrows").write_text("10") |
31 | 41 |
|
32 | | - # Collect the benchmark results |
| 42 | + # Act: Collect the benchmark results from the temporary directory. |
| 43 | + # The second argument '1' is a placeholder for the number of runs. |
33 | 44 | df, error_message = run_and_publish_benchmark.collect_benchmark_result( |
34 | 45 | str(tmp_path), 1 |
35 | 46 | ) |
36 | 47 |
|
37 | | - # Assert that the DataFrame is correct |
38 | | - assert error_message is None |
39 | | - assert len(df) == 1 |
| 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." |
40 | 51 | assert df["Benchmark_Name"][0] == "benchmark1" |
41 | 52 | assert df["Bytes_Processed"][0] == 100 |
42 | 53 | assert df["Slot_Millis"][0] == 1000 |
|
0 commit comments