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')
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)
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)
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')
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')
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')
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')
def test_pattern_match_trailing_spaces(): pat = codeowners.parse_pattern('a/b ') assert pat.match('a/b ') assert not pat.match('a/b')
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')