Skip to main content

tests/test_integration.py

1"""
2Integration tests for the library.
3"""
5from datetime import datetime
6import time
8from pydantic import BaseModel
10from funkycache import FunkyCache
13def test_long_mutable_key() -> None:
14 """
15 We can cache a function argument which includes a long key that
16 gets reduced during key encoding.
18 This is a regression test for a bug in 1.0.1, where the key would be
19 mutated when we checked if a value was already cached, which led to
20 cache misses and errors about overwriting values.
21 """
23 class MyType(BaseModel):
24 content: str = ""
26 cache = FunkyCache(storage="memory")
28 @cache.register
29 def upcase(tp: MyType) -> str:
30 return str(datetime.now())
32 t = MyType(content="a" * 2500)
34 upcase(t)
35 time.sleep(0.1)
36 upcase(t)