示例#1
0
def test_mixed_actions_pipe_then():
    # actions could be
    # hold
    # async_
    # redirect
    # fg
    # iter
    # pipe
    c = cmdy.echo().h().pipe().r()
    assert isinstance(c, CmdyHolding)
    _CMDY_EVENT.clear()

    with pytest.raises(CmdyActionError):
        cmdy.echo().p().h()

    c = cmdy.echo().p().a()
    assert isinstance(c, CmdyHolding)
    _CMDY_EVENT.clear()

    c = cmdy.bash(
        c='echo "1\n2\n3" 1>&2').p().r(STDERR) ^ STDOUT | cmdy.grep(2)
    assert c.str() == '2\n'

    with pytest.raises(CmdyActionError) as ex:
        cmdy.echo().p().p()
    assert 'Unconsumed piping' in str(ex.value)
示例#2
0
def test_mixed_actions_hold_then():
    # actions could be
    # hold
    # async_
    # redirect
    # fg
    # iter
    # pipe
    a = cmdy.echo(123).h().a()
    assert isinstance(a, CmdyHolding)

    r = cmdy.echo(123).h().r()
    assert isinstance(r, CmdyHolding)

    fg = cmdy.echo(123).h().fg()
    assert isinstance(fg, CmdyHolding)

    it = cmdy.echo(123).h().iter()
    assert isinstance(it, CmdyHolding)

    p = cmdy.echo(123).h().p()
    # release the lock
    _CMDY_EVENT.clear()
    assert isinstance(p, CmdyHolding)

    c = cmdy.echo(123).h()
    a = c.a()
    assert isinstance(a, CmdyHolding)
    assert isinstance(a.run(), CmdyAsyncResult)

    c = cmdy.echo(123).h()
    r = c.r() > DEVNULL
    assert isinstance(r, CmdyHolding)
    assert isinstance(r.run(), CmdyResult)

    c = cmdy.echo(123).h()
    r = c.fg()
    assert isinstance(r, CmdyHolding)
    assert isinstance(r.run(), CmdyResult)

    c = cmdy.echo(123).h()
    r = c.iter()
    assert isinstance(r, CmdyHolding)
    assert isinstance(r.run(), CmdyResult)

    c = cmdy.echo(123).h()
    r = c.p()
    assert isinstance(r, CmdyHolding)
    assert _CMDY_EVENT.is_set()
示例#3
0
def test_mixed_actions_async_then_run():
    c = cmdy.echo('1 1>&2', cmdy_shell=True).h()
    r = c.a().run()
    assert isinstance(r, CmdyAsyncResult)

    a = cmdy.echo().a().fg()
    assert isinstance(a, CmdyAsyncResult)

    it = cmdy.echo().a().iter()
    assert isinstance(it, CmdyAsyncResult)

    it = cmdy.echo().h().a().run().iter()
    assert isinstance(it, CmdyAsyncResult)

    c = cmdy.echo().a().p()
    _CMDY_EVENT.clear()
    assert isinstance(c, CmdyHolding)
示例#4
0
def test_piped_cmds():
    c = cmdy.echo(123).p() | cmdy.cat().r() ^ DEVNULL
    assert c.piped_cmds == [['echo', '123'], ['cat']]
    assert c.piped_strcmds == ['echo 123', 'cat']

    # works on holding objects too
    c = cmdy.echo(123).p() | cmdy.cat().h()
    assert c.piped_strcmds == ['echo 123', 'cat']
    assert c.piped_cmds == [['echo', '123'], ['cat']]

    piped_cmds = cmdy.echo(123).piped_cmds
    assert piped_cmds == [['echo', '123']]
    piped_strcmds = cmdy.echo(123).piped_strcmds
    assert piped_strcmds == ['echo 123']
    _CMDY_EVENT.clear()
    c = cmdy.echo(123)
    assert isinstance(c, CmdyResult)
    piped_cmds = c.piped_cmds
    assert piped_cmds == [['echo', '123']]
示例#5
0
def teardown_function():
    _CMDY_EVENT.clear()