Esempio n. 1
0
def test_shell_cp() -> None:
    """Test runnign shell commands."""
    cmd = s.shell_funsie(["cp file1 file2"], {"file1": Encoding.json}, ["file2"])
    inp = {"file1": BytesIO(b"bla bla")}
    out = s.run_shell_funsie(cmd, inp)
    assert out[f"{s.STDOUT}0"] == b""
    assert out["file2"] == b"bla bla"
Esempio n. 2
0
def test_shell_env() -> None:
    """Test env variables in shell funsie."""
    cmd = s.shell_funsie(["echo $VARIABLE"], {}, [], env={"VARIABLE": "bla"})
    out = s.run_shell_funsie(cmd, {})
    assert out[f"{s.STDOUT}0"] == b"bla\n"

    # Check that env variables don't propagate to other commands
    cmd = s.shell_funsie(["echo $VARIABLE"], {}, [])
    out = s.run_shell_funsie(cmd, {})
    assert out[f"{s.STDOUT}0"] == b"\n"

    k = "PATH"
    v = os.environ[k]

    cmd = s.shell_funsie([f"echo ${k}"], {}, [])
    out = s.run_shell_funsie(cmd, {})
    assert out[f"{s.STDOUT}0"] == f"{v}\n".encode()

    cmd = s.shell_funsie([f"echo ${k} $VAR"], {}, [], {"VAR": "bla"})
    out = s.run_shell_funsie(cmd, {})
    assert out[f"{s.STDOUT}0"] == f"{v} bla\n".encode()
Esempio n. 3
0
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"
Esempio n. 4
0
def test_shell_run() -> None:
    """Test runnign shell commands."""
    cmd = s.shell_funsie(["cat file1"], {"file1": Encoding.blob}, [])
    inp = {"file1": BytesIO(b"bla bla")}
    out = s.run_shell_funsie(cmd, inp)
    assert out[f"{s.STDOUT}0"] == b"bla bla"
Esempio n. 5
0
def test_shell_wrap() -> None:
    """Test the instantiation of a shell Funsie."""
    out = s.shell_funsie(["cat file1"], {"file1": Encoding.blob}, [])
    assert out is not None