-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
tests/unit_tests/attributes/test_impl_attribute_registry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |