Ejemplo n.º 1
0
def test_constraints_everything_match():
    tc_check_constraints(ps(), 'CMD', {
        '-a': '1',
        '-b': rxc(r'ab+c'),
        '-c': lambda x: int(x) > 5,
        '-d': 'xyz'
    }, [('-c', '99'), ('-b', 'abbbc'), ('-e', 'not checked')])
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def test_parse_cmdline_multiple_redirect():
    with pytest.raises(TF):
        tc_parse_cmdline(ps('b > c > d'))
Ejemplo n.º 4
0
def test_chunk_args_and_filenames_match():
    tc_check_chunk(ps(), [['a', 'b'], 'c:d', ['p', {'q', 'r'}, 's'], {
        '-c': 'NNN'
    }], 'a b -c NNN -d p r q s'.split())
Ejemplo n.º 5
0
def test_parse_cmdline_pipe_after_redirect():
    with pytest.raises(TF):
        tc_parse_cmdline(ps('b > c | d'))
Ejemplo n.º 6
0
def test_files_nonempty_empty_fails():
    with pytest.raises(TF):
        tc_check_files(ps(), 'CMD', ['whoops'], [])
Ejemplo n.º 7
0
def test_files_text_lengthy_match_succeeds():
    tc_check_files(ps(), 'CMD', ['a', 'b'], ['a', 'b'])
Ejemplo n.º 8
0
def test_match_str_regex_match():
    tc_match_str(ps(), rxc(r'ab+c'), 'abbbc', 'regex fails to match')
Ejemplo n.º 9
0
def test_match_str_equal_strings():
    tc_match_str(ps(), 'abc', 'abc', 'equal strings fail to match')
Ejemplo n.º 10
0
def test_match_str_unequal_strings():
    with pytest.raises(TF):
        tc_match_str(ps(), 'abc', 'def', 'unequal strings match')
Ejemplo n.º 11
0
def test_parse_cmdline_double_bare_commands():
    assert tc_parse_cmdline(ps('a | b')) == ([['a'], ['b']], None)
Ejemplo n.º 12
0
def test_optional_present_still_too_short():
    with pytest.raises(TF):
        assert tc_handle_optional(ps(), [['a'], Optional()],
                                  [['a'], ['b'], ['c']])
Ejemplo n.º 13
0
def test_parse_cmdline_single_bare_command():
    assert tc_parse_cmdline(ps('a')) == ([['a']], None)
Ejemplo n.º 14
0
def test_optional_present_needed():
    assert tc_handle_optional(ps(), [['a'], Optional()], [['a'], ['b']])
Ejemplo n.º 15
0
def test_optional_absent_needed():
    with pytest.raises(TF):
        assert tc_handle_optional(ps(), [['a']], [['a'], ['b']])
Ejemplo n.º 16
0
def test_optional_absent_unneeded():
    assert tc_handle_optional(ps(), [['a']], [['a']]) == ([['a']], [['a']])
Ejemplo n.º 17
0
def test_parse_cmdline_last_line_flag_not_set():
    with pytest.raises(TF):
        assert tc_parse_cmdline(ps('a\nb'))
Ejemplo n.º 18
0
def test_match_str_regex_mismatch():
    with pytest.raises(TF):
        tc_match_str(ps(), rxc(r'ab+c'), 'ac', 'regex matches incorrectly')
Ejemplo n.º 19
0
def test_parse_cmdline_last_line_flag_set():
    assert tc_parse_cmdline(ps('a\nb'), last_line_only=True) == ([['b']], None)
Ejemplo n.º 20
0
def test_match_str_callable_mismatch():
    with pytest.raises(TF):
        tc_match_str(ps(), lambda x: x > 0, -999,
                     'callable matches incorrectly')
Ejemplo n.º 21
0
def test_parse_cmdline_single_command_with_args():
    assert tc_parse_cmdline(ps('a -b')) == ([['a', '-b']], None)
Ejemplo n.º 22
0
def test_chunk_args_and_filenames_filename_mismatch():
    with pytest.raises(TF):
        tc_check_chunk(ps(), [['a', 'b'], 'c:d', ['p', 'q', 'r', 's'], {
            '-c': 'NNN'
        }], 'a b -c NNN -d p r q s'.split())
Ejemplo n.º 23
0
def test_match_str_callable_match():
    tc_match_str(ps(), lambda x: x > 0, 123, 'callable fails to match')
Ejemplo n.º 24
0
def test_parse_cmdline_single_command_with_redirect():
    assert tc_parse_cmdline(ps('a > b')) == ([['a']], 'b')
Ejemplo n.º 25
0
def test_files_empty_empty_passes():
    tc_check_files(ps(), 'CMD', [], [])
Ejemplo n.º 26
0
def test_parse_cmdline_pipe_with_redirect():
    assert tc_parse_cmdline(ps('a|b -c -d  "eee"  | f g  -h > z')) \
        == \
        ([['a'], ['b', '-c', '-d', 'eee'], ['f', 'g', '-h']], 'z')
Ejemplo n.º 27
0
def test_files_text_match_succeeds():
    tc_check_files(ps(), 'CMD', ['a'], ['a'])
Ejemplo n.º 28
0
def test_parse_cmdline_leading_redirect():
    with pytest.raises(TF):
        tc_parse_cmdline(ps('> b'))
Ejemplo n.º 29
0
def test_files_text_lengthy_mismatch_fails():
    with pytest.raises(TF):
        tc_check_files(ps(), 'CMD', ['b', 'a'], ['a', 'b'])
Ejemplo n.º 30
0
def test_parse_cmdline_trailing_redirect():
    with pytest.raises(TF):
        tc_parse_cmdline(ps('b >'))