Skip to content

Commit

Permalink
fix error reporting on unknown attribute inquiry (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo authored Sep 26, 2024
1 parent 80043a8 commit 163b6d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PySDM/attributes/impl/attribute_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_attribute_class(name, dynamics=None, formulae=None):
if name not in _ATTRIBUTES_REGISTRY:
raise ValueError(
f"Unknown attribute name: {name};"
" valid names: {', '.join(sorted(_ATTRIBUTES_REGISTRY))}"
f" valid names: {', '.join(sorted(_ATTRIBUTES_REGISTRY))}"
)
for cls, func in _ATTRIBUTES_REGISTRY[name].items():
if func(dynamics, formulae):
Expand Down
11 changes: 9 additions & 2 deletions tests/unit_tests/attributes/test_impl_attribute_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_get_attribute_class_ok():
def test_get_attribute_class_fail():
"""checks if inquiring for an invalid attribute name raises an exception"""
with pytest.raises(ValueError):
assert get_attribute_class("lorem ipsum")
get_attribute_class("lorem ipsum")

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

with pytest.raises(AssertionError):
assert get_attribute_class("umaminess")
get_attribute_class("umaminess")

@staticmethod
def test_get_attribute_class_error_message_hints():
"""check if error message thrown on unknown attribute error contains list of valid names"""
with pytest.raises(ValueError) as excinfo:
get_attribute_class("XXX")
assert "multiplicity" in str(excinfo.value)

@staticmethod
def test_register_attribute_fail_on_repeated_name():
Expand Down

0 comments on commit 163b6d9

Please sign in to comment.