diff --git a/tests/unit_tests/attributes/test_impl_attribute_registry.py b/tests/unit_tests/attributes/test_impl_attribute_registry.py new file mode 100644 index 000000000..db44e931d --- /dev/null +++ b/tests/unit_tests/attributes/test_impl_attribute_registry.py @@ -0,0 +1,34 @@ +""" checks the attribute registry logic mapping attribute names to classes implementing them + and handling different variants of these implementations picked depending on the choice of + dynamics and formulae options """ + +import pytest + +from PySDM.attributes import Multiplicity +from PySDM.attributes.impl import get_attribute_class, register_attribute + + +class TestAttributeRegistry: + """groups multiple tests to facilitate execution""" + + @staticmethod + def test_get_attribute_class_ok(): + """checks if inquiring for a valid attribute name yields a valid class""" + assert get_attribute_class("multiplicity") is Multiplicity + + @staticmethod + 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") + + @staticmethod + def test_get_attribute_class_variant_fail(): + """checks if variant logic properly throws an exception if no variant match found""" + + @register_attribute(name="umaminess", variant=lambda _, __: False) + class Umaminess: # pylint: disable=unused-variable,too-few-public-methods + """Dummy class""" + + with pytest.raises(AssertionError): + assert get_attribute_class("umaminess")