Skip to content

Commit 163b6d9

Browse files
authored
fix error reporting on unknown attribute inquiry (#1393)
1 parent 80043a8 commit 163b6d9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

PySDM/attributes/impl/attribute_registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_attribute_class(name, dynamics=None, formulae=None):
5454
if name not in _ATTRIBUTES_REGISTRY:
5555
raise ValueError(
5656
f"Unknown attribute name: {name};"
57-
" valid names: {', '.join(sorted(_ATTRIBUTES_REGISTRY))}"
57+
f" valid names: {', '.join(sorted(_ATTRIBUTES_REGISTRY))}"
5858
)
5959
for cls, func in _ATTRIBUTES_REGISTRY[name].items():
6060
if func(dynamics, formulae):

tests/unit_tests/attributes/test_impl_attribute_registry.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_get_attribute_class_ok():
2020
def test_get_attribute_class_fail():
2121
"""checks if inquiring for an invalid attribute name raises an exception"""
2222
with pytest.raises(ValueError):
23-
assert get_attribute_class("lorem ipsum")
23+
get_attribute_class("lorem ipsum")
2424

2525
@staticmethod
2626
def test_get_attribute_class_variant_fail():
@@ -31,7 +31,14 @@ class Umaminess: # pylint: disable=unused-variable,too-few-public-methods
3131
"""Dummy class"""
3232

3333
with pytest.raises(AssertionError):
34-
assert get_attribute_class("umaminess")
34+
get_attribute_class("umaminess")
35+
36+
@staticmethod
37+
def test_get_attribute_class_error_message_hints():
38+
"""check if error message thrown on unknown attribute error contains list of valid names"""
39+
with pytest.raises(ValueError) as excinfo:
40+
get_attribute_class("XXX")
41+
assert "multiplicity" in str(excinfo.value)
3542

3643
@staticmethod
3744
def test_register_attribute_fail_on_repeated_name():

0 commit comments

Comments
 (0)