def test_invalid_command(self): with pytest.raises(InvalidCommand): parse("su") parse("sed") parse("ls | less /etc/hosts")
def test_parsing(self): commands = parse('cat dog | sed -e "s/DOG/CAT/g"') assert commands == [['cat', 'dog'], ['sed', '-e', '"s/DOG/CAT/g"']]
def test_unended_string(self): with pytest.raises(InStringError): parse("'ls | cat") parse('cat dog "dog')
def test_invalid_char(self): parse("cat dog_bird Animals") parse('sed -e "s/.\\xanimal/dogbird#$%/g"') with pytest.raises(InvalidCommand): parse("cat dog.bird") parse("cat $cat")
def test_single_command_only(self): with pytest.raises(SingleCommandOnly): parse("ls; less /etc/hosts")