File size: 1,322 Bytes
d1ceb73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Tests for the ``sympy.physics.biomechanics._mixin.py`` module."""

import pytest

from sympy.physics.biomechanics._mixin import _NamedMixin


class TestNamedMixin:

    @staticmethod
    def test_subclass():

        class Subclass(_NamedMixin):

            def __init__(self, name):
                self.name = name

        instance = Subclass('name')
        assert instance.name == 'name'

    @pytest.fixture(autouse=True)
    def _named_mixin_fixture(self):

        class Subclass(_NamedMixin):

            def __init__(self, name):
                self.name = name

        self.Subclass = Subclass

    @pytest.mark.parametrize('name', ['a', 'name', 'long_name'])
    def test_valid_name_argument(self, name):
        instance = self.Subclass(name)
        assert instance.name == name

    @pytest.mark.parametrize('invalid_name', [0, 0.0, None, False])
    def test_invalid_name_argument_not_str(self, invalid_name):
        with pytest.raises(TypeError):
            _ = self.Subclass(invalid_name)

    def test_invalid_name_argument_zero_length_str(self):
        with pytest.raises(ValueError):
            _ = self.Subclass('')

    def test_name_attribute_is_immutable(self):
        instance = self.Subclass('name')
        with pytest.raises(AttributeError):
            instance.name = 'new_name'