Skip to content

Commit e1d4678

Browse files
authored
Merge pull request #405 from Jammy2211/claude/refactor-unit-tests
Refactor unit tests: granularity, descriptive names, parametrize
2 parents cf2138a + 9865ea8 commit e1d4678

12 files changed

Lines changed: 2827 additions & 2375 deletions

test_autolens/imaging/plot/test_fit_imaging_plots.py

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from autolens.imaging.plot.fit_imaging_plots import (
66
subplot_fit,
77
subplot_fit_log10,
8+
subplot_fit_x1_plane,
9+
subplot_fit_log10_x1_plane,
810
subplot_of_planes,
11+
subplot_tracer_from_fit,
12+
subplot_fit_combined,
13+
subplot_fit_combined_log10,
914
)
1015

1116
directory = path.dirname(path.realpath(__file__))
@@ -18,7 +23,7 @@ def make_fit_imaging_plotter_setup():
1823
)
1924

2025

21-
def test_subplot_fit_is_output(
26+
def test__subplot_fit__two_plane_tracer__output_file_created(
2227
fit_imaging_x2_plane_7x7, plot_path, plot_patch
2328
):
2429
subplot_fit(
@@ -29,7 +34,29 @@ def test_subplot_fit_is_output(
2934
assert path.join(plot_path, "subplot_fit.png") in plot_patch.paths
3035

3136

32-
def test_subplot_fit_log10_is_output(
37+
def test__subplot_fit__single_plane_tracer__delegates_to_x1_plane_and_creates_file(
38+
fit_imaging_x1_plane_7x7, plot_path, plot_patch
39+
):
40+
subplot_fit(
41+
fit=fit_imaging_x1_plane_7x7,
42+
output_path=plot_path,
43+
output_format="png",
44+
)
45+
assert path.join(plot_path, "subplot_fit_x1_plane.png") in plot_patch.paths
46+
47+
48+
def test__subplot_fit_x1_plane__single_plane_tracer__output_file_created(
49+
fit_imaging_x1_plane_7x7, plot_path, plot_patch
50+
):
51+
subplot_fit_x1_plane(
52+
fit=fit_imaging_x1_plane_7x7,
53+
output_path=plot_path,
54+
output_format="png",
55+
)
56+
assert path.join(plot_path, "subplot_fit_x1_plane.png") in plot_patch.paths
57+
58+
59+
def test__subplot_fit_log10__two_plane_tracer__output_file_created(
3360
fit_imaging_x2_plane_7x7, plot_path, plot_patch
3461
):
3562
subplot_fit_log10(
@@ -40,7 +67,29 @@ def test_subplot_fit_log10_is_output(
4067
assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths
4168

4269

43-
def test__subplot_of_planes(
70+
def test__subplot_fit_log10__single_plane_tracer__delegates_to_x1_plane_and_creates_file(
71+
fit_imaging_x1_plane_7x7, plot_path, plot_patch
72+
):
73+
subplot_fit_log10(
74+
fit=fit_imaging_x1_plane_7x7,
75+
output_path=plot_path,
76+
output_format="png",
77+
)
78+
assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths
79+
80+
81+
def test__subplot_fit_log10_x1_plane__single_plane_tracer__output_file_created(
82+
fit_imaging_x1_plane_7x7, plot_path, plot_patch
83+
):
84+
subplot_fit_log10_x1_plane(
85+
fit=fit_imaging_x1_plane_7x7,
86+
output_path=plot_path,
87+
output_format="png",
88+
)
89+
assert path.join(plot_path, "subplot_fit_log10.png") in plot_patch.paths
90+
91+
92+
def test__subplot_of_planes__no_plane_index_specified__all_plane_files_created(
4493
fit_imaging_x2_plane_7x7, plot_path, plot_patch
4594
):
4695
subplot_of_planes(
@@ -52,8 +101,10 @@ def test__subplot_of_planes(
52101
assert path.join(plot_path, "subplot_of_plane_0.png") in plot_patch.paths
53102
assert path.join(plot_path, "subplot_of_plane_1.png") in plot_patch.paths
54103

55-
plot_patch.paths = []
56104

105+
def test__subplot_of_planes__plane_index_0_specified__only_plane_0_file_created(
106+
fit_imaging_x2_plane_7x7, plot_path, plot_patch
107+
):
57108
subplot_of_planes(
58109
fit=fit_imaging_x2_plane_7x7,
59110
output_path=plot_path,
@@ -63,3 +114,36 @@ def test__subplot_of_planes(
63114

64115
assert path.join(plot_path, "subplot_of_plane_0.png") in plot_patch.paths
65116
assert path.join(plot_path, "subplot_of_plane_1.png") not in plot_patch.paths
117+
118+
119+
def test__subplot_tracer_from_fit__two_plane_tracer__output_file_created(
120+
fit_imaging_x2_plane_7x7, plot_path, plot_patch
121+
):
122+
subplot_tracer_from_fit(
123+
fit=fit_imaging_x2_plane_7x7,
124+
output_path=plot_path,
125+
output_format="png",
126+
)
127+
assert path.join(plot_path, "subplot_tracer.png") in plot_patch.paths
128+
129+
130+
def test__subplot_fit_combined__list_of_two_fits__output_file_created(
131+
fit_imaging_x1_plane_7x7, fit_imaging_x2_plane_7x7, plot_path, plot_patch
132+
):
133+
subplot_fit_combined(
134+
fit_list=[fit_imaging_x1_plane_7x7, fit_imaging_x2_plane_7x7],
135+
output_path=plot_path,
136+
output_format="png",
137+
)
138+
assert path.join(plot_path, "subplot_fit_combined.png") in plot_patch.paths
139+
140+
141+
def test__subplot_fit_combined_log10__list_of_two_fits__output_file_created(
142+
fit_imaging_x1_plane_7x7, fit_imaging_x2_plane_7x7, plot_path, plot_patch
143+
):
144+
subplot_fit_combined_log10(
145+
fit_list=[fit_imaging_x1_plane_7x7, fit_imaging_x2_plane_7x7],
146+
output_path=plot_path,
147+
output_format="png",
148+
)
149+
assert path.join(plot_path, "fit_combined_log10.png") in plot_patch.paths

0 commit comments

Comments
 (0)