final implementation
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
48
tests/test_cache.py
Normal file
48
tests/test_cache.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for cache module."""
|
||||
|
||||
import time
|
||||
|
||||
from fhi_statistikk_mcp.cache import TTLCache
|
||||
|
||||
|
||||
def test_set_and_get():
|
||||
cache = TTLCache()
|
||||
cache.set("key", "value", 60)
|
||||
assert cache.get("key") == "value"
|
||||
|
||||
|
||||
def test_get_missing_key():
|
||||
cache = TTLCache()
|
||||
assert cache.get("nonexistent") is None
|
||||
|
||||
|
||||
def test_expiry():
|
||||
cache = TTLCache()
|
||||
cache.set("key", "value", 0.1)
|
||||
time.sleep(0.15)
|
||||
assert cache.get("key") is None
|
||||
|
||||
|
||||
def test_clear():
|
||||
cache = TTLCache()
|
||||
cache.set("a", 1, 60)
|
||||
cache.set("b", 2, 60)
|
||||
cache.clear()
|
||||
assert cache.get("a") is None
|
||||
assert cache.get("b") is None
|
||||
|
||||
|
||||
def test_overwrite():
|
||||
cache = TTLCache()
|
||||
cache.set("key", "old", 60)
|
||||
cache.set("key", "new", 60)
|
||||
assert cache.get("key") == "new"
|
||||
|
||||
|
||||
def test_different_ttls():
|
||||
cache = TTLCache()
|
||||
cache.set("short", "value", 0.1)
|
||||
cache.set("long", "value", 60)
|
||||
time.sleep(0.15)
|
||||
assert cache.get("short") is None
|
||||
assert cache.get("long") == "value"
|
||||
Reference in New Issue
Block a user