Skip to content

Commit ad6a417

Browse files
committed
Split heatmap tests in the new TestHeatmapsForCurrentModel class
1 parent 2864801 commit ad6a417

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

tests/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def eval_paths_fixture(
154154
@pytest.fixture(scope="session")
155155
def plot_paths_fixture(
156156
eval_paths_fixture, config
157-
) -> Generator[tuple[Path, list], None, None]:
157+
) -> Generator[tuple[Path, list, Path, Path], None, None]:
158158
"""Fixture to generate plots after evaluating puzzles by the eval_paths fixture."""
159159
# Run the plotting script
160160
n_puzzles = config.n_puzzles
@@ -163,6 +163,8 @@ def plot_paths_fixture(
163163
clue_types = list(config.clue_weights.keys())
164164
red_herring_clue_types = list(config.red_herring_clue_weights.keys())
165165
n_red_herring_clues = config.n_red_herring_clues
166+
model = config.model
167+
n_red_herring_clues_evaluated = config.n_red_herring_clues_evaluated
166168

167169
plot_results(
168170
n_puzzles=n_puzzles,
@@ -182,7 +184,11 @@ def plot_paths_fixture(
182184
if p.is_dir() and p.name != "clue_type_frequencies"
183185
]
184186

185-
yield plots_path, plots_model_paths
187+
model_folder = plots_path / model
188+
189+
red_herring_folder = model_folder / f"{n_red_herring_clues_evaluated}rh"
190+
191+
yield plots_path, plots_model_paths, model_folder, red_herring_folder
186192

187193
# Cleanup
188194
rmtree(plots_path, ignore_errors=True)

tests/test_plot_pipeline.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,44 @@
1010
import os
1111

1212

13-
def test_heatmaps_for_current_model(plot_paths_fixture, config) -> None:
14-
"""Test that the model in the config has folders and files saved in the plots folder."""
15-
# Get the plotting path
16-
plots_path = plot_paths_fixture[0]
17-
18-
# Get the path to the model currently in the config
19-
model = config.model
20-
model_folder = plots_path / model
21-
22-
# Check that the model folder exists
23-
assert model_folder.exists()
24-
assert model_folder.is_dir()
25-
26-
# Check that the model folder contains a subfolder for the number of evaluated red herring clues
27-
n_red_herring_clues_evaluated = config.n_red_herring_clues_evaluated
28-
red_herring_folder = model_folder / f"{n_red_herring_clues_evaluated}rh"
29-
assert red_herring_folder.exists()
30-
assert red_herring_folder.is_dir()
13+
class TestHeatmapsForCurrentModel:
14+
"""Tests related to heatmaps for the current model."""
15+
16+
def test_model_plot_folder_exists(self, plot_paths_fixture, config) -> None:
17+
"""Test that the model in the config has a folder in the plots folder."""
18+
# Get the path to the model currently in the config
19+
model_folder = plot_paths_fixture[2]
20+
21+
# Check that the model folder exists
22+
assert model_folder.exists()
23+
assert model_folder.is_dir()
24+
25+
def test_red_herring_plot_folder_exists(self, plot_paths_fixture, config) -> None:
26+
"""Test that the model in the config has a folder for the chosen number of evaluated red herrings in the plots folder."""
27+
# Get the path to the model and number of evaluated red herring clues currently in the config
28+
red_herring_folder = plot_paths_fixture[3]
29+
30+
# Check that the model folder contains a subfolder for the number of evaluated red herring clues
31+
assert red_herring_folder.exists()
32+
assert red_herring_folder.is_dir()
33+
34+
def test_heatmaps_for_current_model(self, plot_paths_fixture, config) -> None:
35+
"""Test that the cell score heatmap for the current evaluation is saved in the plots folder."""
36+
# Get the path to the model and number of evaluated red herring clues currently in the config
37+
red_herring_folder = plot_paths_fixture[3]
38+
39+
# Get the path to the model currently in the config
40+
model = config.model
41+
n_red_herring_clues_evaluated = config.n_red_herring_clues_evaluated
3142

32-
# Check that the folder contains the expected cell score file
33-
n_puzzles = config.n_puzzles
34-
cell_score_plot_filename = f"mean_cell_score_{model}_{n_red_herring_clues_evaluated}rh_{n_puzzles}_puzzles.png"
35-
cell_score_plot_file_path = red_herring_folder / cell_score_plot_filename
43+
# Check that the folder contains the expected cell score file
44+
n_puzzles = config.n_puzzles
45+
cell_score_plot_filename = f"mean_cell_score_{model}_{n_red_herring_clues_evaluated}rh_{n_puzzles}_puzzles.png"
46+
cell_score_plot_file_path = red_herring_folder / cell_score_plot_filename
3647

37-
assert cell_score_plot_file_path.exists()
38-
assert cell_score_plot_file_path.is_file()
39-
assert os.path.getsize(cell_score_plot_file_path) > 0
48+
assert cell_score_plot_file_path.exists()
49+
assert cell_score_plot_file_path.is_file()
50+
assert os.path.getsize(cell_score_plot_file_path) > 0
4051

4152

4253
def test_clue_type_difficulty_plot(plot_paths_fixture, config) -> None:

0 commit comments

Comments
 (0)