fixed cache test

This commit is contained in:
2024-04-29 09:37:02 +02:00
parent ea65ead188
commit b32d5e00c9

View File

@@ -1,3 +1,4 @@
import pytest
import scgenerator.cache as scc
from scgenerator.cache import Cache, normalize_path
@@ -72,24 +73,29 @@ class Stuff:
self.x = x
def test_decorator():
@pytest.fixture
def cache_for_test():
cache = Cache("Test")
yield cache
cache.delete()
def test_decorator(cache_for_test: Cache):
call_count = 0
@cache()
@cache_for_test(lambda x: str(x))
def func(x: str) -> str:
nonlocal call_count
call_count += 1
return x + x
@cache(lambda li: f"{li[0]}-{li[-1]} {len(li)}")
@cache_for_test(lambda li: f"{li[0]}-{li[-1]} {len(li)}")
def func2(some_list: list):
nonlocal call_count
call_count += 1
return sum(some_list)
Stuff.from_other = cache(lambda _, *args: str(args))(Stuff.from_other)
Stuff.from_other = cache_for_test(lambda _, *args: str(args))(Stuff.from_other)
assert func("hello") == "hellohello"
assert func2([0, 1, 2, 80]) == 83
@@ -103,7 +109,6 @@ def test_decorator():
assert Stuff.call_count == 1
assert call_count == 2
cache.delete()
def test_normalize():