Ejemplo n.º 1
0
def test_pipe_error():

    with pytest.raises(cmdy.CmdyActionError):
        cmdy.cat().h() | cmdy.grep(cmdy_raise=False)

    h = cmdy.cat().h()
    h.stdout = sys.stderr
    with pytest.raises(cmdy.CmdyActionError):
        h.p() | cmdy.grep()
Ejemplo n.º 2
0
Archivo: aggr.py Proyecto: pwwang/ceQTL
def pipeline(opts):
    """Construct the pipeline"""

    # get the column index of the column name
    colidx = cmdy.head(opts.infile, n=1, _pipe=True) | \
        cmdy.tr("\t", "\n", _pipe=True) | \
        cmdy.nl(_pipe=True) | \
        cmdy.grep(w=opts.on)
    colidx = colidx.strip().split()[0]

    # sort by that column, make sure the first element we remain
    # is the corresponding record
    pSort.input = [opts.infile]
    pSort.args.inopts.skip = 1
    pSort.args.params.k = '%sg' % colidx

    pTsvAggregate.depends = pSort
    pTsvAggregate.args.sort = False
    pTsvAggregate.args.aggrs.Padj_aggr = "$%s:%s" % (opts.method, opts.on)
    #pTsvAggregate.args.on = "Case"
    pTsvAggregate.args.origin = "keep0"
    pTsvAggregate.output = "outfile:file:%s" % Path(opts.outfile).name
    pTsvAggregate.config.export_dir = Path(opts.outfile).parent

    return pSort
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def test_mixed_actions_pipe_then_iter(capsys):
    c = cmdy.bash(c='echo "1\n2\n3" 1>&2').p(STDERR).iter(STDOUT)
    d = c | cmdy.grep(2, cmdy_okcode='0,1')
    assert isinstance(d, CmdyResult)
    assert isinstance(c, CmdyHolding)
    assert d == '2\n'
Ejemplo n.º 5
0
def test_mixed_actions_pipe_then_fg(capsys):

    c = cmdy.bash(c='echo 123 1>&2 && echo 456').p(STDERR).fg() | cmdy.grep(
        4, cmdy_okcode='0,1')
    assert capsys.readouterr().out == '456\n'
    assert c.str() == ''  # have been redirected by fg
Ejemplo n.º 6
0
def test_multi_pipe():
    c = cmdy.echo("11\n12\n22\n23").p() | cmdy.grep(2).p() | cmdy.grep(22)
    assert c == '22\n'
Ejemplo n.º 7
0
def test_pipe():

    c = cmdy.echo("1\n2\n3").p() | cmdy.grep(2)
    assert c == '2\n'