|
1 | | -import os |
2 | | -import shutil |
3 | | - |
4 | 1 | import pytest |
| 2 | +from pathlib import Path |
5 | 3 |
|
6 | 4 | from backend.config.paths import ( |
7 | 5 | ARTIFACTS_AI_CSV_FILE, |
|
16 | 14 | TEST_RESOURCES_DIR + "ExecutionTreeContributedCoverage.csv" |
17 | 15 | ) |
18 | 16 | TEST_ARTIFACTS_AI_CSV_FILE = TEST_RESOURCES_DIR + "AI.csv" |
19 | | -TEST_RESULTS_DIR = BASE_DIR + "/utils/tests/resources/results" |
20 | | - |
21 | | - |
22 | | -@pytest.fixture(autouse=True) |
23 | | -def auto_test_results_dir(): |
24 | | - os.makedirs(TEST_RESULTS_DIR, exist_ok=True) |
25 | | - yield |
26 | | - shutil.rmtree(TEST_RESULTS_DIR) |
27 | 17 |
|
28 | 18 |
|
29 | 19 | @pytest.fixture |
30 | | -def mock_paths(monkeypatch): |
| 20 | +def test_env(tmp_path, monkeypatch): |
| 21 | + results_dir = tmp_path / "results" |
| 22 | + results_dir.mkdir() |
| 23 | + |
31 | 24 | def mock_get_thread_filepath(uid, filepath): |
32 | 25 | if "uploads" in filepath: |
33 | 26 | return filepath.replace("tmp/uploads", "utils/tests/resources") |
34 | 27 | if filepath == ARTIFACTS_AI_CSV_FILE: |
35 | 28 | return TEST_ARTIFACTS_AI_CSV_FILE |
36 | 29 | if filepath == ARTIFACTS_BASELINE_CSV_FILE: |
37 | 30 | return TEST_ARTIFACTS_BASELINE_CSV_FILE |
| 31 | + |
| 32 | + if "results" in filepath: |
| 33 | + return str(results_dir / Path(filepath).name) |
| 34 | + |
38 | 35 | return filepath.replace("tmp", "utils/tests/resources") |
39 | 36 |
|
40 | 37 | monkeypatch.setattr(docker_runner, "get_thread_filepath", mock_get_thread_filepath) |
41 | 38 |
|
| 39 | + return { |
| 40 | + "results_dir": results_dir, |
| 41 | + } |
| 42 | + |
42 | 43 |
|
43 | | -def test_runstrat_baseline(mock_paths): |
| 44 | +def test_runstrat_baseline(test_env): |
44 | 45 | uid = "test" |
45 | 46 | RunstratBaseline().run(uid) |
46 | 47 |
|
47 | 48 |
|
48 | | -def test_runstrat_ai(mock_paths): |
| 49 | +def test_runstrat_ai(test_env): |
49 | 50 | uid = "test" |
50 | 51 | RunstratAI().run(uid) |
51 | 52 |
|
52 | 53 |
|
53 | | -def test_compstrat(mock_paths): |
| 54 | +def test_compstrat(test_env): |
54 | 55 | uid = "test" |
55 | 56 | Compstrat().run(uid) |
0 commit comments