Example #1
0
def test_if():
    for i, o in (("0</dev/null if a; then b; fi >>/tmp/x",
                  CommandSequence([
                      If([
                          (CommandSequence(
                              [Command([Word([ConstantString("a")])])]),
                           CommandSequence(
                               [Command([Word([ConstantString("b")])])]))
                      ]).with_redirect(RedirectFrom(0, devnull),
                                       RedirectTo(1, w("/tmp/x"), append=True))
                  ])), ):
        cmd = command_sequence.parse(i)
        assert cmd == o
        assert cmd.redirects == o.redirects
Example #2
0
def test_while():
    for i, o in (("0</dev/null while a; do b; done >>/tmp/x",
                  CommandSequence([
                      While(
                          CommandSequence(
                              [Command([Word([ConstantString("a")])])]),
                          CommandSequence(
                              [Command([Word([ConstantString("b")])])]),
                      ).with_redirect(RedirectFrom(0, devnull),
                                      RedirectTo(1, w("/tmp/x"), append=True))
                  ])), ):
        cmd = command_sequence.parse(i)
        assert cmd == o
        assert cmd.redirects == o.redirects
Example #3
0
def test_basic(text, expected):
    cmd = command.parse(text)
    assert cmd == expected
    assert cmd.assignments == expected.assignments
    cmd = command_sequence.parse(text)
    assert cmd == CommandSequence([expected])
Example #4
0
def test_sequence(text, expected):
    cmd = command_sequence.parse(text)
    assert cmd == expected
    assert cmd.assignments == expected.assignments
Example #5
0
def test_dq(text, expected):
    assert command_sequence.parse(text) == expected
Example #6
0
def test_throws(text):
    with pytest.raises(ParseError):
        cmd = command_sequence.parse(text)
Example #7
0
def test_basic(text, expected):
    cmd = command_sequence.parse(text)
    assert cmd == CommandSequence([expected])