|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from codeflash.models.models import TestFile, TestFiles |
| 6 | +from codeflash.models.test_type import TestType |
| 7 | + |
| 8 | + |
| 9 | +class TestTestFilesAdd: |
| 10 | + def test_add_unique_test_file(self) -> None: |
| 11 | + tf = TestFiles(test_files=[]) |
| 12 | + test_file = TestFile( |
| 13 | + instrumented_behavior_file_path=Path("/tmp/test_behavior.py"), |
| 14 | + benchmarking_file_path=Path("/tmp/test_perf.py"), |
| 15 | + test_type=TestType.GENERATED_REGRESSION, |
| 16 | + ) |
| 17 | + tf.add(test_file) |
| 18 | + assert len(tf.test_files) == 1 |
| 19 | + assert tf.test_files[0] is test_file |
| 20 | + |
| 21 | + def test_add_duplicate_raises(self) -> None: |
| 22 | + tf = TestFiles(test_files=[]) |
| 23 | + test_file = TestFile( |
| 24 | + instrumented_behavior_file_path=Path("/tmp/test_behavior.py"), |
| 25 | + benchmarking_file_path=Path("/tmp/test_perf.py"), |
| 26 | + test_type=TestType.GENERATED_REGRESSION, |
| 27 | + ) |
| 28 | + tf.add(test_file) |
| 29 | + with pytest.raises(ValueError, match="Test file already exists"): |
| 30 | + tf.add(test_file) |
| 31 | + |
| 32 | + def test_add_many_files_performance(self) -> None: |
| 33 | + tf = TestFiles(test_files=[]) |
| 34 | + for i in range(100): |
| 35 | + test_file = TestFile( |
| 36 | + instrumented_behavior_file_path=Path(f"/tmp/test_behavior_{i}.py"), |
| 37 | + benchmarking_file_path=Path(f"/tmp/test_perf_{i}.py"), |
| 38 | + test_type=TestType.GENERATED_REGRESSION, |
| 39 | + ) |
| 40 | + tf.add(test_file) |
| 41 | + |
| 42 | + assert len(tf.test_files) == 100 |
| 43 | + assert len(tf._seen_paths) == 100 |
| 44 | + # Verify all paths are unique in the set |
| 45 | + expected_paths = {Path(f"/tmp/test_behavior_{i}.py") for i in range(100)} |
| 46 | + assert tf._seen_paths == expected_paths |
0 commit comments