Skip to content

Commit a3ed1ce

Browse files
committed
Updates tests
1 parent 5965028 commit a3ed1ce

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

RATapi/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def check_unsupported_parameters(self):
131131
non_empty_fields = [v for v in expected_empty_fields if getattr(self, v) != ""]
132132
if non_empty_fields:
133133
raise ValueError(
134-
f'The following values are not supported by the "{self.type}" background type: '
134+
f'The following values are not supported by the "{self.type}" Background type: '
135135
f"{', '.join(non_empty_fields)}"
136136
)
137137

@@ -641,7 +641,7 @@ def check_unsupported_parameters(self):
641641
non_empty_fields = [v for v in expected_empty_fields if getattr(self, v) != ""]
642642
if non_empty_fields:
643643
raise ValueError(
644-
f'The following values are not supported by the "{self.type}" resolution type: '
644+
f'The following values are not supported by the "{self.type}" Resolution type: '
645645
f"{', '.join(non_empty_fields)}"
646646
)
647647

tests/test_models.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,22 +334,50 @@ def test_contrast_bad_ratio():
334334
RATapi.models.Contrast(name="My Contrast", domain_ratio="bad ratio")
335335

336336

337-
@pytest.mark.parametrize("model", [RATapi.models.Background, RATapi.models.Resolution])
338-
@pytest.mark.filterwarnings("ignore:The following values are not recognised by this*:UserWarning")
339-
def test_type_change_clear(model):
337+
@pytest.mark.parametrize(
338+
["model", "type", "values"],
339+
[
340+
(RATapi.models.Background, "function", ["val1", "val2", "val3", "val4", "val5"]),
341+
(RATapi.models.Resolution, "constant", ["", "", "", "", ""]),
342+
],
343+
)
344+
def test_type_change_clear(model, type, values):
340345
"""If the type of a background or resolution is changed, it should wipe the other fields and warn the user."""
341346
model_instance = model(
342347
name="Test",
343-
type="constant",
348+
type=type,
344349
source="src",
345-
value_1="val1",
346-
value_2="val2",
347-
value_3="val3",
348-
value_4="val4",
349-
value_5="val5",
350+
value_1=values[0],
351+
value_2=values[1],
352+
value_3=values[2],
353+
value_4=values[3],
354+
value_5=values[4],
350355
)
351356

352357
with pytest.warns(UserWarning, match="Changing the type of Test clears its source and value fields."):
353358
model_instance.type = "data"
354359
for attr in ["source", "value_1", "value_2", "value_3", "value_4", "value_5"]:
355360
assert getattr(model_instance, attr) == ""
361+
362+
363+
@pytest.mark.parametrize(
364+
["model", "signal_type", "values"],
365+
[
366+
(RATapi.models.Background, "constant", ["value_1", "value_2", "value_3", "value_4", "value_5"]),
367+
(RATapi.models.Background, "data", ["value_2", "value_3", "value_4", "value_5"]),
368+
(RATapi.models.Resolution, "constant", ["value_1", "value_2", "value_3", "value_4", "value_5"]),
369+
(RATapi.models.Resolution, "data", ["value_1", "value_2", "value_3", "value_4", "value_5"]),
370+
],
371+
)
372+
def test_unsupported_parameters_error(model, signal_type, values):
373+
"""If a value is inputted for an unsupported field for a particular type of background or resolution then we should
374+
raise an error."""
375+
for value in values:
376+
with pytest.raises(
377+
pydantic.ValidationError,
378+
match=(
379+
f"1 validation error for {model.__name__}\n Value error, The following values are not supported"
380+
f' by the "{signal_type}" {model.__name__} type: {value}'
381+
),
382+
):
383+
model(**{"type": signal_type, value: "unsupported"})

tests/test_project.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,17 +1137,7 @@ def test_write_script_wrong_extension(test_project, extension: str) -> None:
11371137
["class_list", "model_type", "field"],
11381138
[
11391139
("backgrounds", "constant", "source"),
1140-
("backgrounds", "", "value_1"),
1141-
("backgrounds", "", "value_2"),
1142-
("backgrounds", "", "value_3"),
1143-
("backgrounds", "", "value_4"),
1144-
("backgrounds", "", "value_5"),
11451140
("resolutions", "constant", "source"),
1146-
("resolutions", "", "value_1"),
1147-
("resolutions", "", "value_2"),
1148-
("resolutions", "", "value_3"),
1149-
("resolutions", "", "value_4"),
1150-
("resolutions", "", "value_5"),
11511141
("layers", "", "thickness"),
11521142
("layers", "", "SLD"),
11531143
("layers", "", "roughness"),
@@ -1216,17 +1206,7 @@ def test_wrap_del(test_project, class_list: str, parameter: str, field: str) ->
12161206
["class_list", "model_type", "field", "model_params"],
12171207
[
12181208
("backgrounds", "constant", "source", {}),
1219-
("backgrounds", "", "value_1", {}),
1220-
("backgrounds", "", "value_2", {}),
1221-
("backgrounds", "", "value_3", {}),
1222-
("backgrounds", "", "value_4", {}),
1223-
("backgrounds", "", "value_5", {}),
12241209
("resolutions", "constant", "source", {}),
1225-
("resolutions", "", "value_1", {}),
1226-
("resolutions", "", "value_2", {}),
1227-
("resolutions", "", "value_3", {}),
1228-
("resolutions", "", "value_4", {}),
1229-
("resolutions", "", "value_5", {}),
12301210
("layers", "", "thickness", layer_params),
12311211
("layers", "", "SLD", layer_params),
12321212
("layers", "", "roughness", layer_params),
@@ -1263,17 +1243,7 @@ def test_wrap_iadd(test_project, class_list: str, model_type: str, field: str, m
12631243
["class_list", "model_type", "field", "model_params"],
12641244
[
12651245
("backgrounds", "constant", "source", {}),
1266-
("backgrounds", "", "value_1", {}),
1267-
("backgrounds", "", "value_2", {}),
1268-
("backgrounds", "", "value_3", {}),
1269-
("backgrounds", "", "value_4", {}),
1270-
("backgrounds", "", "value_5", {}),
12711246
("resolutions", "constant", "source", {}),
1272-
("resolutions", "", "value_1", {}),
1273-
("resolutions", "", "value_2", {}),
1274-
("resolutions", "", "value_3", {}),
1275-
("resolutions", "", "value_4", {}),
1276-
("resolutions", "", "value_5", {}),
12771247
("layers", "", "thickness", layer_params),
12781248
("layers", "", "SLD", layer_params),
12791249
("layers", "", "roughness", layer_params),
@@ -1311,17 +1281,7 @@ def test_wrap_append(test_project, class_list: str, model_type: str, field: str,
13111281
["class_list", "model_type", "field", "model_params"],
13121282
[
13131283
("backgrounds", "constant", "source", {}),
1314-
("backgrounds", "", "value_1", {}),
1315-
("backgrounds", "", "value_2", {}),
1316-
("backgrounds", "", "value_3", {}),
1317-
("backgrounds", "", "value_4", {}),
1318-
("backgrounds", "", "value_5", {}),
13191284
("resolutions", "constant", "source", {}),
1320-
("resolutions", "", "value_1", {}),
1321-
("resolutions", "", "value_2", {}),
1322-
("resolutions", "", "value_3", {}),
1323-
("resolutions", "", "value_4", {}),
1324-
("resolutions", "", "value_5", {}),
13251285
("layers", "", "thickness", layer_params),
13261286
("layers", "", "SLD", layer_params),
13271287
("layers", "", "roughness", layer_params),
@@ -1492,17 +1452,7 @@ def test_wrap_clear(test_project, class_list: str, parameter: str, field: str) -
14921452
["class_list", "model_type", "field", "model_params"],
14931453
[
14941454
("backgrounds", "constant", "source", {}),
1495-
("backgrounds", "", "value_1", {}),
1496-
("backgrounds", "", "value_2", {}),
1497-
("backgrounds", "", "value_3", {}),
1498-
("backgrounds", "", "value_4", {}),
1499-
("backgrounds", "", "value_5", {}),
15001455
("resolutions", "constant", "source", {}),
1501-
("resolutions", "", "value_1", {}),
1502-
("resolutions", "", "value_2", {}),
1503-
("resolutions", "", "value_3", {}),
1504-
("resolutions", "", "value_4", {}),
1505-
("resolutions", "", "value_5", {}),
15061456
("layers", "", "thickness", layer_params),
15071457
("layers", "", "SLD", layer_params),
15081458
("layers", "", "roughness", layer_params),

0 commit comments

Comments
 (0)