diff --git a/tests/test_selection.py b/tests/test_selection.py index 021af9d22..99d87f584 100644 --- a/tests/test_selection.py +++ b/tests/test_selection.py @@ -21,3 +21,9 @@ def test_selection(server, s22): vis.selection = [0, 7, 6, 5, 4] assert vis.selection == [0, 7, 6, 5, 4] + + with pytest.raises(ValueError): + vis.selection = [0, 0, 2] + + with pytest.raises(ValueError): + vis.selection = "Hello" diff --git a/zndraw/zndraw.py b/zndraw/zndraw.py index 0b026b96e..98c670570 100644 --- a/zndraw/zndraw.py +++ b/zndraw/zndraw.py @@ -252,8 +252,12 @@ def selection(self) -> list[int]: @selection.setter def selection(self, value: list[int]): + if not isinstance(value, list): + raise ValueError("Selection must be a list") if not all(isinstance(x, int) for x in value): raise ValueError("Selection must be a list of integers") + if len(value) != len(set(value)): + raise ValueError("Selection must not contain duplicates") max_index = len(self.atoms) if any(x >= max_index for x in value):