test_mixin.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Tests for the ``sympy.physics.biomechanics._mixin.py`` module."""
  2. import pytest
  3. from sympy.physics.biomechanics._mixin import _NamedMixin
  4. class TestNamedMixin:
  5. @staticmethod
  6. def test_subclass():
  7. class Subclass(_NamedMixin):
  8. def __init__(self, name):
  9. self.name = name
  10. instance = Subclass('name')
  11. assert instance.name == 'name'
  12. @pytest.fixture(autouse=True)
  13. def _named_mixin_fixture(self):
  14. class Subclass(_NamedMixin):
  15. def __init__(self, name):
  16. self.name = name
  17. self.Subclass = Subclass
  18. @pytest.mark.parametrize('name', ['a', 'name', 'long_name'])
  19. def test_valid_name_argument(self, name):
  20. instance = self.Subclass(name)
  21. assert instance.name == name
  22. @pytest.mark.parametrize('invalid_name', [0, 0.0, None, False])
  23. def test_invalid_name_argument_not_str(self, invalid_name):
  24. with pytest.raises(TypeError):
  25. _ = self.Subclass(invalid_name)
  26. def test_invalid_name_argument_zero_length_str(self):
  27. with pytest.raises(ValueError):
  28. _ = self.Subclass('')
  29. def test_name_attribute_is_immutable(self):
  30. instance = self.Subclass('name')
  31. with pytest.raises(AttributeError):
  32. instance.name = 'new_name'