| Total Complexity | 2 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 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 |