Skip to content

Commit

Permalink
waltsims#460: improved coverage and changed ValueError to TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
precicely committed Sep 1, 2024
1 parent 9923bfe commit 176b71b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kwave/utils/kwave_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def is_close(self, other: "Element", rtol=1e-05, atol=1e-08, equal_nan=False):
:return: bool
"""
if not isinstance(other, type(self)):
raise ValueError(f"{other} is not instance of type Element")
raise TypeError(f"{other} with {type(other)} is not of type Element")

for field in fields(self):
self_attr = getattr(self, field.name)
Expand All @@ -128,7 +128,7 @@ def __eq__(self, other):
:return: bool
"""
if not isinstance(other, type(self)):
raise ValueError(f"{other} is not instance of type Element")
raise TypeError(f"{other} with {type(other)} is not of type Element")

for field in fields(self):
self_attr = getattr(self, field.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ def test_element():
element1 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1])
# element2 has a very similar position to element 1 but with a small numerical difference
element2 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1.000001])
element3 = "not an element"
# element3 is a completely different element
element3 = Element(group_id=1, type="rect", dim=2, active=True, measure=2, position=[2, 2, 2])
# element 4 is not an element
element4 = "not an element"

assert element1 != element2
assert element1.is_close(element2)
with pytest.raises(Exception):
element1 != element3
element1.is_close(element3)
assert element1 != element3
assert not element1.is_close(element3)
with pytest.raises(TypeError):
element1 != element4
element1.is_close(element4)


def test_kwave_array():
Expand Down

0 comments on commit 176b71b

Please sign in to comment.