Exemplo n.º 1
0
def test_defer(test):
    """Tests _defer option."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    assert sh.true(_defer = False).status() == 0
Exemplo n.º 2
0
def test_defer(test):
    """Tests _defer option."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    assert sh.true(_defer=False).status() == 0
Exemplo n.º 3
0
def test_program_customization(test):
    """Tests customization of a Program instance."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    true = psh.Program("true", _defer=False)
    assert true().status() == 0
Exemplo n.º 4
0
def test_sh_customization(test):
    """Tests customization of a Sh instance."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    csh = psh.Sh(_defer = False)
    assert csh.true().status() == 0
Exemplo n.º 5
0
def test_program_customization(test):
    """Tests customization of a Program instance."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    true = psh.Program("true", _defer = False)
    assert true().status() == 0
Exemplo n.º 6
0
def test_sh_customization(test):
    """Tests customization of a Sh instance."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().status()

    csh = psh.Sh(_defer=False)
    assert csh.true().status() == 0
Exemplo n.º 7
0
def test_wait_status(test):
    """Tests wait() return value."""

    assert sh.true().execute(wait = False).wait() == 0
    assert sh.true().execute(wait = False).wait(check_status = True) == 0

    assert sh.false().execute(wait = False).wait() == 1
    assert pytest.raises(psh.ExecutionError,
        lambda: sh.false().execute(wait = False).wait(check_status = True)).value.status() == 1
Exemplo n.º 8
0
def test_wait_status(test):
    """Tests wait() return value."""

    assert sh.true().execute(wait=False).wait() == 0
    assert sh.true().execute(wait=False).wait(check_status=True) == 0

    assert sh.false().execute(wait=False).wait() == 1
    assert pytest.raises(
        psh.ExecutionError, lambda: sh.false().execute(wait=False).wait(
            check_status=True)).value.status() == 1
Exemplo n.º 9
0
def test_on_execute_with_exeption(test):
    """Tests _on_execute option with function that throws an exception."""

    allow = False
    state = { "executed": False }

    class NotAllowed(Exception):
        pass

    def func(process):
        if allow:
            state["executed"] = True
        else:
            raise NotAllowed()

    process = sh.true(_on_execute = func)
    assert state["executed"] == False

    with pytest.raises(NotAllowed):
        process.execute()
    assert state["executed"] == False

    allow = True
    process.execute()
    assert state["executed"] == True
Exemplo n.º 10
0
def test_on_execute_with_exception(test):
    """Tests _on_execute option with function that throws an exception."""

    allow = False
    state = {"executed": False}

    class NotAllowed(Exception):
        pass

    def func(process):
        if allow:
            state["executed"] = True
        else:
            raise NotAllowed()

    process = sh.true(_on_execute=func)
    assert state["executed"] is False

    with pytest.raises(NotAllowed):
        process.execute()
    assert state["executed"] is False

    allow = True
    process.execute()
    assert state["executed"] is True
Exemplo n.º 11
0
def test_ok_statuses(test):
    """Tests _ok_statuses option."""

    assert sh.false(_ok_statuses=(0, 1)).execute().status() == 1
    assert pytest.raises(
        psh.ExecutionError,
        lambda: sh.true(_ok_statuses=[]).execute()).value.status() == 0
Exemplo n.º 12
0
def test_on_execute(test):
    """Tests _on_execute option."""

    state = { "executed": False }

    def func(process):
        state["executed"] = True

    process = sh.true(_on_execute = func)
    assert state["executed"] == False

    process.execute()
    assert state["executed"] == True
Exemplo n.º 13
0
def test_on_execute(test):
    """Tests _on_execute option."""

    state = {"executed": False}

    def func(process):
        state["executed"] = True

    process = sh.true(_on_execute=func)
    assert state["executed"] is False

    process.execute()
    assert state["executed"] is True
Exemplo n.º 14
0
def test_error_codes(test):
    """Tests error codes."""

    sh.sh("-c", sh.true(), _shell=True).execute().status() == 0

    assert pytest.raises(psh.ExecutionError,
        lambda: sh.sh("-c", sh.false(), _shell=True).execute()).value.status() == 1


    pipe = sh.cat() | sh.egrep("bbb|ccc") | sh.grep("ccc")

    assert pytest.raises(psh.ExecutionError,
        lambda: sh.sh("-c", pipe, _stdin="aaa\n", _shell=True).execute()).value.status() == 128

    assert pytest.raises(psh.ExecutionError,
        lambda: sh.sh("-c", pipe, _stdin="bbb\n", _shell=True).execute()).value.status() == 1
Exemplo n.º 15
0
def test_error_codes(test):
    """Tests error codes."""

    sh.sh("-c", sh.true(), _shell=True).execute().status() == 0

    assert pytest.raises(
        psh.ExecutionError, lambda: sh.sh("-c", sh.false(), _shell=True).
        execute()).value.status() == 1

    pipe = sh.cat() | sh.egrep("bbb|ccc") | sh.grep("ccc")

    assert pytest.raises(
        psh.ExecutionError,
        lambda: sh.sh("-c", pipe, _stdin="aaa\n", _shell=True).execute(
        )).value.status() == 128

    assert pytest.raises(
        psh.ExecutionError,
        lambda: sh.sh("-c", pipe, _stdin="bbb\n", _shell=True).execute(
        )).value.status() == 1
Exemplo n.º 16
0
def test_invalid_wait(test):
    """Tests wait() on a pending process."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().wait()
Exemplo n.º 17
0
def test_repeated_execution(test):
    """Tests repeated execution."""

    process = sh.true().execute()
    with pytest.raises(psh.InvalidOperation):
        process.execute()
Exemplo n.º 18
0
def test_zero_exit_status(test):
    """Tests zero exit status."""

    assert sh.true().execute().status() == 0
Exemplo n.º 19
0
def test_ok_statuses(test):
    """Tests _ok_statuses option."""

    assert sh.false(_ok_statuses = [ 0, 1 ] ).execute().status() == 1
    assert pytest.raises(psh.ExecutionError,
        lambda: sh.true(_ok_statuses = []).execute()).value.status() == 0
Exemplo n.º 20
0
def test_repeated_execution(test):
    """Tests repeated execution."""

    process = sh.true().execute()
    with pytest.raises(psh.InvalidOperation):
        process.execute()
Exemplo n.º 21
0
def test_invalid_wait(test):
    """Tests wait() on a pending process."""

    with pytest.raises(psh.InvalidProcessState):
        sh.true().wait()
Exemplo n.º 22
0
def test_zero_exit_status(test):
    """Tests zero exit status."""

    assert sh.true().execute().status() == 0