Beispiel #1
0
def test_parse_pattern():
    with pytest.raises(ValueError):
        codeowners.parse_pattern('a/**b/c')

    pat1 = codeowners.parse_pattern('!a/b')
    assert pat1.invert, "Prefix '!' should negate the pattern."
    assert pat1.pattern == PurePath('a/b')

    pat2 = codeowners.parse_pattern('a/b/')
    assert pat2.dir_only, "Prefix '!' should negate the pattern."
    assert pat2.pattern == PurePath('a/b')
Beispiel #2
0
def test_pattern_match_single_component():
    pat1 = codeowners.parse_pattern('*.py')
    assert pat1.match('file.py')
    assert pat1.match('a/file.py')
    assert pat1.match('a/b/file.py')
    assert not pat1.match('file.txt')

    assert codeowners.parse_pattern('*.txt').match('test.txt')

    pat2 = codeowners.parse_pattern('docs*')
    assert pat2.match('docs.txt')
    assert pat2.match('docs1/', is_dir=True)
    assert pat2.match('docs1/output.txt')
    assert pat2.match('output/docs1/', is_dir=True)
    assert pat2.match('output/docs1/output.txt', is_dir=True)
Beispiel #3
0
def test_pattern_match_directory_only():
    dir_pat = codeowners.parse_pattern('bin/')
    assert dir_pat.match('bin', is_dir=True)
    assert dir_pat.match('output/bin', is_dir=True)

    assert not dir_pat.match('bin', is_dir=False)
    assert not dir_pat.match('output/bin', is_dir=False)
Beispiel #4
0
def test_pattern_match_recursive():
    rec_pat = codeowners.parse_pattern('a/**/b')
    assert rec_pat.match('a/b')
    assert rec_pat.match('a/x/b')
    assert rec_pat.match('a/x/y/z/b')
    # Does not end in 'b', no match.
    assert not rec_pat.match('a/x/y/z/c')
Beispiel #5
0
def test_pattern_match():
    nested_pat = codeowners.parse_pattern('a/b')
    assert not nested_pat.match('a')
    assert nested_pat.match('a/b')
    assert nested_pat.match('a/b/c')
    assert nested_pat.match('a/b/c/d')
    assert not nested_pat.match('a/z')
    assert not nested_pat.match('b')
    assert not nested_pat.match('a/bbbb')
    assert not nested_pat.match('z/a/b')

    pat = codeowners.parse_pattern('a/*.py')
    assert not pat.match('a')
    assert pat.match('a/file.py')
    assert not pat.match('file.py')
    assert not pat.match('b/file.py')
    assert not pat.match('b/c/file.py')
Beispiel #6
0
def test_pattern_match_inverted():
    inv_pat = codeowners.parse_pattern('!a/*.py')
    assert not inv_pat.match('a/file.py')
    assert inv_pat.match('file.py')
    assert inv_pat.match('b/file.py')
    assert inv_pat.match('b/file.txt')
Beispiel #7
0
def test_pattern_match_rooted():
    root_pat = codeowners.parse_pattern('/a')
    assert root_pat.match('a')
    assert root_pat.match('a/b')
    assert not root_pat.match('x/a')
    assert not root_pat.match('b')
Beispiel #8
0
def test_pattern_match_trailing_spaces():
    pat = codeowners.parse_pattern('a/b ')
    assert pat.match('a/b ')
    assert not pat.match('a/b')
Beispiel #9
0
def test_pattern_match_recursive():
    rec_pat = codeowners.parse_pattern('a/**/b')
    assert rec_pat.match('a/b')
    assert rec_pat.match('a/x/b')
    assert rec_pat.match('a/x/y/z/b')
    assert rec_pat.match('a/x/y/z/c')