final implementation
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
Torbjørn Lindahl
2026-03-27 23:38:52 +01:00
parent 4b2e7376bd
commit 3b3721091b
31 changed files with 5107 additions and 0 deletions

48
tests/test_cache.py Normal file
View 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"