Skip to content

Commit 84a4169

Browse files
committed
added warning for fields clearing
1 parent 6aff106 commit 84a4169

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

RATapi/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Signal(RATModel):
5959

6060
def __setattr__(self, name, value):
6161
if name == "type":
62+
warnings.warn(f"Changing the type of {self.name} clears its source and value fields.", stacklevel=2)
6263
for attr in ["source", "value_1", "value_2", "value_3", "value_4", "value_5"]:
6364
with warnings.catch_warnings():
6465
warnings.simplefilter("ignore")

tests/test_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def test_contrast_bad_ratio():
336336

337337
@pytest.mark.parametrize("model", [RATapi.models.Background, RATapi.models.Resolution])
338338
def test_type_change_clear(model):
339-
"""If the type of a background or resolution is changed, it should wipe the other fields."""
339+
"""If the type of a background or resolution is changed, it should wipe the other fields and warn the user."""
340340

341341
model_instance = model(
342342
name="Test",
@@ -349,6 +349,7 @@ def test_type_change_clear(model):
349349
value_5="val5",
350350
)
351351

352-
model_instance.type = "data"
352+
with pytest.warns(UserWarning, match="Changing the type of Test clears its source and value fields."):
353+
model_instance.type = "data"
353354
for attr in ["source", "value_1", "value_2", "value_3", "value_4", "value_5"]:
354355
assert getattr(model_instance, attr) == ""

0 commit comments

Comments
 (0)