42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
from pipewright.items import Item
|
|
from pipewright.store import Store
|
|
|
|
|
|
def test_item_ids_are_content_and_lineage_hashes():
|
|
a = Item(key="k", kind="issue", payload={"x": 1})
|
|
b = Item(key="k", kind="issue", payload={"x": 1})
|
|
assert a.id == b.id and len(a.id) == 24
|
|
assert Item(key="k", kind="issue", payload={"x": 2}).id != a.id
|
|
d = a.derive(update_labels={"y": True})
|
|
assert d.parents == (a.id,) and d.labels == {"y": True} and d.payload == a.payload
|
|
assert d.id != a.id
|
|
s = d.stamped("node1", "label.expr@1")
|
|
assert s.producer == "node1" and s.id != d.id and s.parents == d.parents
|
|
assert a.content_hash == Item(key="other", kind="issue", payload={"x": 1}).content_hash
|
|
|
|
|
|
def test_item_get_paths():
|
|
it = Item(key="k", kind="t", payload={"a": {"b": [1, {"c": 3}]}}, labels={"s": 0.5})
|
|
assert it.get("payload.a.b.1.c") == 3
|
|
assert it.get("labels.s") == 0.5
|
|
assert it.get("key") == "k"
|
|
assert it.get("payload.missing", "d") == "d"
|
|
|
|
|
|
def test_store_roundtrip(tmp_path):
|
|
st = Store(tmp_path / "s")
|
|
a = Item(key="k", kind="t", payload={"x": 1})
|
|
b = a.derive(update_payload={"x": 2}).stamped("n", "op@1")
|
|
st.put_item(a)
|
|
st.put_item(b)
|
|
st2 = Store(tmp_path / "s")
|
|
assert st2.get_item(b.id) == b
|
|
assert [i.id for i in st2.lineage(b.id)] == [b.id, a.id]
|
|
assert st2.children(a.id) == [b.id]
|
|
ref = st2.put_blob(b"hello", "text/plain", "h.txt")
|
|
assert st2.get_blob(ref) == b"hello" and ref.size == 5
|
|
st2.memo_put("sig", a.id, "n", "ok", {"out": [b.id]}, None, "r1", 0.1)
|
|
m = st2.memo_get("sig", a.id)
|
|
assert m.status == "ok" and m.outputs == {"out": [b.id]}
|
|
assert st2.memo_get("sig", "nope") is None
|