blizzarman/polyglot-tutor
0
1from tutor.services.cache import FileCache2 3 4def test_key_is_stable_and_separator_safe() -> None:5 assert FileCache.key("a", "b") == FileCache.key("a", "b")6 assert FileCache.key("a", "b") != FileCache.key("ab")7 assert FileCache.key("a", "b") != FileCache.key("a:b")8 9 10def test_roundtrip_and_miss(tmp_path) -> None:11 cache = FileCache(tmp_path / "nested" / "dir") # created on init12 key = FileCache.key("text", "1", "model", "B1", "the ocean")13 assert cache.get(key) is None14 cache.set(key, {"text": "héllo", "attempts": 2})15 assert cache.get(key) == {"text": "héllo", "attempts": 2}16 17 18def test_corrupt_entry_behaves_like_a_miss(tmp_path) -> None:19 cache = FileCache(tmp_path)20 key = FileCache.key("x")21 (tmp_path / f"{key}.json").write_text("{not json", encoding="utf-8")22 assert cache.get(key) is None23 