Passed
Pull Request — master (#33)
by Konstantinos
02:17
created

test_utils.test_memoize   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_simple_memoize() 0 8 1
A simple_memoize() 0 12 1
1
import pytest
2
3
4
@pytest.fixture
5
def simple_memoize():
6
    from so_magic.utils import ObjectsPool
7
    import attr
8
    @attr.s
9
    class TestClass:
10
        number: int = attr.ib()
11
        name: str = attr.ib()
12
        @staticmethod
13
        def factory_method(arg1, arg2, **kwargs):
14
            return TestClass(arg1, arg2)
15
    return ObjectsPool.new_empty(TestClass.factory_method)
16
17
18
def test_simple_memoize(simple_memoize):
19
    runtime_args = (7, 'gg')
20
    runtime_kwargs = dict(kwarg1='something', kwarg2=[1, 2])
21
    instance1 = simple_memoize.get_object(*runtime_args, **runtime_kwargs)
22
    instance2 = simple_memoize.get_object(*runtime_args, **runtime_kwargs)
23
    assert instance1 == instance2
24
    hash1 = simple_memoize._build_hash(*runtime_args, **runtime_kwargs)
25
    assert hash1 == hash('-'.join([str(_) for _ in runtime_args] + [f'{key}={str(value)}' for key, value in runtime_kwargs.items()]))
26