def test_artefact_wrong_type() -> None: """Test storing non-bytes in implicit artefacts.""" server = MockServer() db, store = server.new_connection() art = _graph.variable_artefact(db, hash_t("1"), "file", Encoding.blob) _graph.set_data( db, store, art.hash, _serdes.encode(art.kind, "what"), _graph.ArtefactStatus.done, ) out = _graph.get_data(db, store, art) assert isinstance(out, Error) assert out.kind == ErrorKind.WrongType art = _graph.variable_artefact(db, hash_t("2"), "file", Encoding.json) _graph.set_data( db, store, art.hash, _serdes.encode(art.kind, ["what", 1]), _graph.ArtefactStatus.done, ) out = _graph.get_data(db, store, art) assert out == ["what", 1]
def test_artefact_update() -> None: """Test updating a const artefact.""" db = Redis() store = RedisStorage(db) art = _graph.constant_artefact(db, store, b"bla bla") with pytest.raises(TypeError): _graph.set_data(db, store, art.hash, b"b", _graph.ArtefactStatus.done)
def test_artefact_add_large() -> None: """Test adding large artefacts to a Redis store.""" db = Redis() store = RedisStorage(db, block_size=8) art = _graph.variable_artefact(db, hash_t("1"), "file", cons.Encoding.blob) data = b"12345" * 100 _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done) data2 = _graph.get_data(db, store, art) assert db.llen(cons.join(cons.ARTEFACTS, art.hash, "data")) == 63 assert data == data2
def test_artefact_disk() -> None: """Test saving an artefact to disk and restoring it.""" with tempfile.TemporaryDirectory() as td: db = Redis() store = DiskStorage(td) art = _graph.variable_artefact(db, hash_t("12345678"), "file", cons.Encoding.blob) data = b"12345" * 100 _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done) data2 = _graph.get_data(db, store, art) assert data == data2
def test_artefact_replace_large() -> None: """Test replacing large artefacts.""" db = Redis() store = RedisStorage(db, block_size=8) art = _graph.variable_artefact(db, hash_t("1"), "file", cons.Encoding.blob) data = b"12345" * 100 _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done) store.block_size = 1000000 _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done) data2 = _graph.get_data(db, store, art) assert data == data2
def test_artefact_disk_json() -> None: """Test saving an artefact to disk and restoring it.""" with tempfile.TemporaryDirectory() as td: db = Redis() store = DiskStorage(td) art = _graph.variable_artefact(db, hash_t("12345678"), "file", cons.Encoding.json) dat = [0, 1, 2, 3, "a string"] bdat = _serdes.encode(_serdes.kind(dat), dat) _graph.set_data(db, store, art.hash, bdat, _graph.ArtefactStatus.done) data2 = _graph.get_data(db, store, art) assert dat == data2