def test_cmdline_example(): _test_cmdline(ps( '\n# a comment\nextract params.txt data/b.csv data/a.csv | sort -n | tail -n 3 > last.csv\n' ), [['extract', '', [rxc(r'p.+\.txt'), {'data/a.csv', 'data/b.csv'}]], ['sort', 'n'], ['tail', 'n:', [], { '-n': '3' }]], 'Use extract, sort, and tail with redirection.', redirect_out=re.compile(r'.+\.csv'), last_line_only=True)
def test_debug_match_command(): pattern = [['abc', 'l']] actual = 'wc -l' with pytest.raises(TF): _test_cmdline(ps(actual), pattern, debug='EXTRA MESSAGE')
def test_overall_command_only_mismatch(): with pytest.raises(TF): _test_cmdline(ps('a'), [['b']])
def test_overall_pipeline(): actual = 'wc -l a.txt b.txt "c.txt d.txt" | sort -n -r | head -n 3 > result.txt' pattern = [['wc', 'l', '+'], ['sort', 'nr'], ['head', 'n:', None, {'-n' : '3'}]] _test_cmdline(ps(actual), pattern, redirect=re.compile(r'.+\.txt'), incorrect_msg='Incorrect command line')
def test_overall_command_only_match(): _test_cmdline(ps('a'), [['a']])