Skip to content

Commit 6d8aa28

Browse files
committed
Add tests
1 parent 07f8abc commit 6d8aa28

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/unit_tests/converters/test_lookup_tables_converters.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,43 @@ def test_undulator_gap_lut_gives_expected_result():
113113
)
114114
result = undulator_energy_gap_lut(input)
115115
assert result == expected
116+
117+
118+
@pytest.mark.parametrize(
119+
"args, expected_value",
120+
[
121+
(("detector_distances_mm", 150, "beam_centre_x_mm", True), 152.2),
122+
(("beam_centre_y_mm", 160.96, "detector_distances_mm", True), 800),
123+
(
124+
("beam_centre_x_mm", 153, "beam_centre_y_mm", False),
125+
166.26, # get closest value when value_must_exist == False
126+
),
127+
],
128+
)
129+
def test_generic_lut_model_get_value_function(
130+
args: tuple[str, int | float, str, bool], expected_value: int | float
131+
):
132+
my_lut = GenericLookupTable(
133+
column_names=["detector_distances_mm", "beam_centre_x_mm", "beam_centre_y_mm"],
134+
rows=[[150, 152.2, 166.26], [800, 152.08, 160.96]],
135+
)
136+
assert my_lut.get_value(*args) == expected_value
137+
138+
139+
def test_generic_lut_model_get_value_errors_if_value_doesnt_exist():
140+
my_lut = GenericLookupTable(
141+
column_names=["detector_distances_mm", "beam_centre_x_mm", "beam_centre_y_mm"],
142+
rows=[[150, 152.2, 166.26], [800, 152.08, 160.96]],
143+
)
144+
with pytest.raises(ValueError):
145+
# value doesn't exist
146+
my_lut.get_value("beam_centre_y_mm", 160.97, "detector_distances_mm")
147+
148+
149+
def test_generic_lut_model_columns_function():
150+
my_lut = GenericLookupTable(
151+
column_names=["detector_distances_mm", "beam_centre_x_mm", "beam_centre_y_mm"],
152+
rows=[[150, 152.2, 166.26], [800, 152.08, 160.96]],
153+
)
154+
expected_columns = [[150, 800], [152.2, 152.08], [166.26, 160.96]]
155+
assert my_lut.columns() == expected_columns

0 commit comments

Comments
 (0)