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_dependencies() -> None: """Test cached result.""" opt = options() serv = MockServer() db, store = serv.new_connection() cmd = p.python_funsie(capitalize, {"inp": Encoding.json}, {"inp": Encoding.json}, name="capit") cmd2 = p.python_funsie(uncapitalize, {"inp": Encoding.json}, {"inp": Encoding.json}, name="uncap") operation = _graph.make_op( db, cmd, inp={"inp": _graph.constant_artefact(db, store, "bla bla")}, opt=opt) operation2 = _graph.make_op( db, cmd2, inp={"inp": _graph.Artefact.grab(db, operation.out["inp"])}, opt=opt) status = run_op(db, store, operation2.hash) assert status == RunStatus.unmet_dependencies status = run_op(db, store, operation.hash) assert status == RunStatus.executed status = run_op(db, store, operation2.hash) assert status == RunStatus.executed
def test_operation_pack() -> None: """Test packing and unpacking of operations.""" opt = options() server = MockServer() db, store = server.new_connection() a = _graph.constant_artefact(db, store, b"bla bla") b = _graph.constant_artefact(db, store, b"bla bla bla") fun = f.Funsie( how=f.FunsieHow.shell, what="cat infile", inp={"infile": Encoding.blob}, out={"out": Encoding.json}, extra={}, ) op = _graph.make_op(db, fun, {"infile": a}, opt) op2 = _graph.Operation.grab(db, op.hash) assert op == op2 with pytest.raises(AttributeError): op = _graph.make_op(db, fun, {}, opt) with pytest.raises(AttributeError): # no inputs op = _graph.make_op(db, fun, {}, opt) with pytest.raises(AttributeError): # too many inputs op = _graph.make_op(db, fun, {"infile": a, "infile2": b}, opt) with pytest.raises(RuntimeError): op = _graph.Operation.grab(db, hash_t("b"))
def test_artefact_add_implicit() -> None: """Test adding implicit artefacts.""" options() server = MockServer() db, store = server.new_connection() art = _graph.variable_artefact(db, hash_t("1"), "file", Encoding.blob) out = _graph.get_data(db, store, art) assert isinstance(out, Error) assert out.kind == ErrorKind.NotFound
def test_artefact_add() -> None: """Test adding const artefacts.""" options() server = MockServer() db, store = server.new_connection() a = _graph.constant_artefact(db, store, b"bla bla") b = _graph.Artefact[bytes].grab(db, a.hash) c = _graph.get_data(db, store, a) assert b is not None assert a == b assert c == b"bla bla"
def test_cached_run() -> None: """Test cached result.""" opt = options() serv = MockServer() db, store = serv.new_connection() cmd = p.python_funsie(capitalize, {"inp": Encoding.json}, {"inp": Encoding.json}, name="capit") inp = {"inp": _graph.constant_artefact(db, store, "bla bla")} operation = _graph.make_op(db, cmd, inp, opt) status = run_op(db, store, operation.hash) # test return values assert status == RunStatus.executed status = run_op(db, store, operation.hash) assert status == RunStatus.using_cached
def test_shell_run() -> None: """Test run on a shell command.""" opt = options() serv = MockServer() db, store = serv.new_connection() cmd = s.shell_funsie(["cat file1"], {"file1": Encoding.blob}, []) inp = {"file1": _graph.constant_artefact(db, store, b"bla bla")} operation = _graph.make_op(db, cmd, inp, opt) status = run_op(db, store, operation.hash) # test return values assert status == RunStatus.executed # check data is good dat = _graph.get_data( db, store, _graph.Artefact[bytes].grab(db, operation.inp["file1"])) assert dat == b"bla bla" dat = _graph.get_data( db, store, _graph.Artefact[bytes].grab(db, operation.out[f"{s.STDOUT}0"])) assert dat == b"bla bla"
def test_pyfunc_run() -> None: """Test run on a python function.""" opt = options() serv = MockServer() db, store = serv.new_connection() cmd = p.python_funsie(capitalize, {"inp": Encoding.json}, {"inp": Encoding.json}, name="capit") inp = {"inp": _graph.constant_artefact(db, store, "bla bla")} operation = _graph.make_op(db, cmd, inp, opt) status = run_op(db, store, operation.hash) # test return values assert status == RunStatus.executed # check data is good dat = _graph.get_data(db, store, _graph.Artefact[str].grab(db, operation.inp["inp"])) assert dat == "bla bla" dat = _graph.get_data(db, store, _graph.Artefact[str].grab(db, operation.out["inp"])) assert dat == "BLA BLA"