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
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
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])
def test_sequence(text, expected): cmd = command_sequence.parse(text) assert cmd == expected assert cmd.assignments == expected.assignments
def test_dq(text, expected): assert command_sequence.parse(text) == expected
def test_throws(text): with pytest.raises(ParseError): cmd = command_sequence.parse(text)
def test_basic(text, expected): cmd = command_sequence.parse(text) assert cmd == CommandSequence([expected])