def test_parse_gitignore_string(self): parsed = versioncontrol.parse_gitignore(self.gitignore) assert len(parsed) == 9 for i in range(len(parsed)): assert len(parsed[i]) == 2 assert isinstance(parsed[i][0], list) for pat in parsed[i][0]: assert hasattr(pat, 'match') assert isinstance(parsed[i][1], int)
def test_parse_gitignore_patterns(self): with mock.patch('re.compile', lambda s: s): with mock.patch('fnmatch.translate', lambda s: s): parsed = versioncontrol.parse_gitignore(self.gitignore) assert parsed[0] == (['foo'], 0) assert parsed[1] == (['foo*'], 0) assert parsed[2] == (['foo', 'bar'], 0) assert parsed[3] == (['foo*', 'bar'], 0) assert parsed[4] == (['foo', '*', 'bar'], 0) assert parsed[5] == (['bar'], versioncontrol.MATCH_END_WITH_DIRECTORY) assert parsed[6] == (['foo'], versioncontrol.MATCH_INVERSE) assert parsed[7] == (['!foo'], 0) assert parsed[8] == (['#comment'], 0)
def test_parse_gitignore_stream(self): touch('.gitignore', self.gitignore) with open('.gitignore') as fin: parsed = versioncontrol.parse_gitignore(fin) assert len(parsed) == 9