Skip to content

Commit b817bd7

Browse files
improve tests
1 parent 4bce4b2 commit b817bd7

2 files changed

Lines changed: 58 additions & 59 deletions

File tree

tests/unit_tests/beamlines/i02_1/test_i02_1_gridscan_plan.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,22 @@ def fgs_composite(
7878
)
7979

8080

81+
class SpecifiedTwoDTest(SpecifiedTwoDGridScan):
82+
# Skip parent validation for easier testing
83+
def _check_lengths_are_same(self): # type: ignore
84+
return self
85+
86+
8187
@pytest.mark.parametrize(
8288
"y_starts_um, z_starts_um, omega_starts_deg, y_step_sizes_um, y_steps, should_raise",
8389
[
8490
([1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], True),
91+
([1], [1], [1], [1, 1], [1], True),
92+
([1], [1], [1, 1], [1], [1], True),
8593
([1], [1], [1], [1], [1], False),
8694
],
8795
)
88-
def test_three_d_grid_scan_validation(
96+
def test_two_d_grid_scan_validation(
8997
y_starts_um: list[float],
9098
z_starts_um: list[float],
9199
omega_starts_deg: list[float],
@@ -94,38 +102,28 @@ def test_three_d_grid_scan_validation(
94102
should_raise: bool,
95103
tmp_path,
96104
):
97-
if should_raise:
98-
with pytest.raises(ValidationError, match="must be length 1 for 2D scans"):
99-
SpecifiedTwoDGridScan(
100-
x_start_um=0,
101-
y_starts_um=y_starts_um,
102-
z_starts_um=z_starts_um,
103-
y_step_sizes_um=y_step_sizes_um,
104-
omega_starts_deg=omega_starts_deg,
105-
parameter_model_version=get_param_version(),
106-
sample_id=0,
107-
visit="visit",
108-
file_name="test_file",
109-
storage_directory=str(tmp_path),
110-
x_steps=5,
111-
y_steps=y_steps,
112-
)
113-
else:
114-
SpecifiedTwoDGridScan(
105+
def create_params():
106+
SpecifiedTwoDTest(
115107
x_start_um=0,
116-
y_starts_um=[0],
117-
z_starts_um=[0],
118-
y_step_sizes_um=[10],
119-
omega_starts_deg=[0],
108+
y_starts_um=y_starts_um,
109+
z_starts_um=z_starts_um,
110+
y_step_sizes_um=y_step_sizes_um,
111+
omega_starts_deg=omega_starts_deg,
120112
parameter_model_version=get_param_version(),
121113
sample_id=0,
122114
visit="visit",
123115
file_name="test_file",
124116
storage_directory=str(tmp_path),
125117
x_steps=5,
126-
y_steps=[3],
118+
y_steps=y_steps,
127119
)
128120

121+
if should_raise:
122+
with pytest.raises(ValidationError, match="must be length 1 for 2D scans"):
123+
create_params()
124+
else:
125+
create_params()
126+
129127

130128
@patch(
131129
"mx_bluesky.beamlines.i02_1.i02_1_gridscan_plan.construct_i02_1_specific_features",

tests/unit_tests/common/parameters/test_gridscan.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,7 @@ def test_specified_grids_validation_error(
3939
y_steps: list[int],
4040
should_raise: bool,
4141
):
42-
if should_raise:
43-
with pytest.raises(
44-
ValidationError, match="Fields must all have the same length:"
45-
):
46-
GridParamsTest(
47-
x_start_um=0,
48-
y_starts_um=y_starts_um,
49-
z_starts_um=z_starts_um,
50-
omega_starts_deg=omega_starts_deg,
51-
y_step_sizes_um=y_step_sizes_um,
52-
y_steps=y_steps,
53-
sample_id=0,
54-
visit="/tmp",
55-
parameter_model_version=get_param_version(),
56-
file_name="/tmp",
57-
storage_directory="/tmp",
58-
x_steps=5,
59-
)
60-
else:
42+
def make_params():
6143
GridParamsTest(
6244
x_start_um=0,
6345
y_starts_um=y_starts_um,
@@ -73,13 +55,27 @@ def test_specified_grids_validation_error(
7355
x_steps=5,
7456
)
7557

58+
if should_raise:
59+
with pytest.raises(
60+
ValidationError, match="Fields must all have the same length:"
61+
):
62+
make_params()
63+
else:
64+
make_params()
65+
66+
67+
class SpecifiedThreeDTest(SpecifiedThreeDGridScan):
68+
# Skip parent validation for easier testing
69+
def _check_lengths_are_same(self): # type: ignore
70+
return self
71+
7672

7773
@pytest.mark.parametrize(
7874
"y_starts_um, z_starts_um, omega_starts_deg, y_step_sizes_um, y_steps, should_raise",
7975
[
8076
([1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], True),
81-
([1, 1], [1, 1], [1, 1], [1, 1, 1], [1, 1], False),
82-
([1, 1], [1, 1], [1, 1, 1], [1, 1], [1, 1], False),
77+
([1, 1], [1, 1], [1, 1], [1, 1, 1], [1, 1], True),
78+
([1, 1], [1, 1], [1, 1, 1], [1, 1], [1, 1], True),
8379
([1, 1], [1, 1], [1, 1], [1, 1], [1, 1], False),
8480
],
8581
)
@@ -91,19 +87,24 @@ def test_three_d_grid_scan_validation(
9187
y_steps: list[int],
9288
should_raise: bool,
9389
):
90+
def make_params():
91+
SpecifiedThreeDTest(
92+
x_start_um=0,
93+
y_starts_um=y_starts_um,
94+
z_starts_um=z_starts_um,
95+
omega_starts_deg=omega_starts_deg,
96+
y_step_sizes_um=y_step_sizes_um,
97+
y_steps=y_steps,
98+
sample_id=0,
99+
visit="/tmp",
100+
parameter_model_version=get_param_version(),
101+
file_name="/tmp",
102+
storage_directory="/tmp",
103+
x_steps=5,
104+
)
105+
94106
if should_raise:
95107
with pytest.raises(ValidationError, match="must be length 2 for 3D scans"):
96-
SpecifiedThreeDGridScan(
97-
x_start_um=0,
98-
y_starts_um=y_starts_um,
99-
z_starts_um=z_starts_um,
100-
omega_starts_deg=omega_starts_deg,
101-
y_step_sizes_um=y_step_sizes_um,
102-
y_steps=y_steps,
103-
sample_id=0,
104-
visit="/tmp",
105-
parameter_model_version=get_param_version(),
106-
file_name="/tmp",
107-
storage_directory="/tmp",
108-
x_steps=5,
109-
)
108+
make_params()
109+
else:
110+
make_params()

0 commit comments

Comments
 (0)