File size: 780 Bytes
c641d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from cache import AnswerCache, ResultStore


def test_cache_round_trip_and_run_resume(tmp_path):
    cache = AnswerCache(tmp_path / "answers.json")
    cache.put("one", {"answer": "A"})
    assert cache.get("one") == {"answer": "A"}

    run = AnswerCache(tmp_path / "run.json")
    rows = [{"task_id": "1", "status": "ok"}]
    run.save_run(rows)
    assert run.load_run() == rows


def test_task_keyed_result_store(tmp_path):
    store = ResultStore(tmp_path / "results.json")
    store.save_result("b", {"task_id": "b", "status": "ok"})
    store.save_result("a", {"task_id": "a", "status": "ok"})
    assert set(store.load()) == {"a", "b"}
    assert [row["task_id"] for row in store.ordered(["a", "b"])] == ["a", "b"]
    store.remove("a")
    assert "a" not in store.load()