Passed
Push — master ( 96da92...a1b572 )
by Konstantinos
37s queued 14s
created

test_utils.test_memoize.simple_memoize()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 0
dl 0
loc 12
rs 9.8
c 0
b 0
f 0
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