Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG0dc3ed4e712c: tests: replace match.match(exact=True) by match.exact()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | tests/test-manifest.py (13 lines) | |||
M | tests/test-match.py (17 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Martin von Zweigbergk | Feb 9 2019, 2:03 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz |
self.assertEqual(len(m), len(list(m))) | self.assertEqual(len(m), len(list(m))) | ||||
def testMatchesMetadata(self): | def testMatchesMetadata(self): | ||||
'''Tests matches() for a few specific files to make sure that both | '''Tests matches() for a few specific files to make sure that both | ||||
the set of files as well as their flags and nodeids are correct in | the set of files as well as their flags and nodeids are correct in | ||||
the resulting manifest.''' | the resulting manifest.''' | ||||
m = self.parsemanifest(A_HUGE_MANIFEST) | m = self.parsemanifest(A_HUGE_MANIFEST) | ||||
match = matchmod.match(b'/', b'', | match = matchmod.exact(b'/', b'', | ||||
[b'file1', b'file200', b'file300'], exact=True) | [b'file1', b'file200', b'file300']) | ||||
m2 = m.matches(match) | m2 = m.matches(match) | ||||
w = (b'file1\0%sx\n' | w = (b'file1\0%sx\n' | ||||
b'file200\0%sl\n' | b'file200\0%sl\n' | ||||
b'file300\0%s\n') % (HASH_2, HASH_1, HASH_1) | b'file300\0%s\n') % (HASH_2, HASH_1, HASH_1) | ||||
self.assertEqual(w, m2.text()) | self.assertEqual(w, m2.text()) | ||||
def testMatchesNonexistentFile(self): | def testMatchesNonexistentFile(self): | ||||
'''Tests matches() for a small set of specific files, including one | '''Tests matches() for a small set of specific files, including one | ||||
nonexistent file to make sure in only matches against existing files. | nonexistent file to make sure in only matches against existing files. | ||||
''' | ''' | ||||
m = self.parsemanifest(A_DEEPER_MANIFEST) | m = self.parsemanifest(A_DEEPER_MANIFEST) | ||||
match = matchmod.match(b'/', b'', | match = matchmod.exact(b'/', b'', | ||||
[b'a/b/c/bar.txt', b'a/b/d/qux.py', | [b'a/b/c/bar.txt', b'a/b/d/qux.py', | ||||
b'readme.txt', b'nonexistent'], | b'readme.txt', b'nonexistent']) | ||||
exact=True) | |||||
m2 = m.matches(match) | m2 = m.matches(match) | ||||
self.assertEqual( | self.assertEqual( | ||||
[b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], | [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], | ||||
m2.keys()) | m2.keys()) | ||||
def testMatchesNonexistentDirectory(self): | def testMatchesNonexistentDirectory(self): | ||||
'''Tests matches() for a relpath match on a directory that doesn't | '''Tests matches() for a relpath match on a directory that doesn't | ||||
actually exist.''' | actually exist.''' | ||||
m = self.parsemanifest(A_DEEPER_MANIFEST) | m = self.parsemanifest(A_DEEPER_MANIFEST) | ||||
match = matchmod.match(b'/', b'', [b'a/f'], default=b'relpath') | match = matchmod.match(b'/', b'', [b'a/f'], default=b'relpath') | ||||
m2 = m.matches(match) | m2 = m.matches(match) | ||||
self.assertEqual([], m2.keys()) | self.assertEqual([], m2.keys()) | ||||
def testMatchesExactLarge(self): | def testMatchesExactLarge(self): | ||||
'''Tests matches() for files matching a large list of exact files. | '''Tests matches() for files matching a large list of exact files. | ||||
''' | ''' | ||||
m = self.parsemanifest(A_HUGE_MANIFEST) | m = self.parsemanifest(A_HUGE_MANIFEST) | ||||
flist = m.keys()[80:300] | flist = m.keys()[80:300] | ||||
match = matchmod.match(b'/', b'', flist, exact=True) | match = matchmod.exact(b'/', b'', flist) | ||||
m2 = m.matches(match) | m2 = m.matches(match) | ||||
self.assertEqual(flist, m2.keys()) | self.assertEqual(flist, m2.keys()) | ||||
def testMatchesFull(self): | def testMatchesFull(self): | ||||
'''Tests matches() for what should be a full match.''' | '''Tests matches() for what should be a full match.''' | ||||
m = self.parsemanifest(A_DEEPER_MANIFEST) | m = self.parsemanifest(A_DEEPER_MANIFEST) | ||||
b'a/b/fish.py'], m2.keys()) | b'a/b/fish.py'], m2.keys()) | ||||
def testMatchesExactPath(self): | def testMatchesExactPath(self): | ||||
'''Tests matches() on an exact match on a directory, which should | '''Tests matches() on an exact match on a directory, which should | ||||
result in an empty manifest because you can't perform an exact match | result in an empty manifest because you can't perform an exact match | ||||
against a directory.''' | against a directory.''' | ||||
m = self.parsemanifest(A_DEEPER_MANIFEST) | m = self.parsemanifest(A_DEEPER_MANIFEST) | ||||
match = matchmod.match(b'/', b'', [b'a/b'], exact=True) | match = matchmod.exact(b'/', b'', [b'a/b']) | ||||
m2 = m.matches(match) | m2 = m.matches(match) | ||||
self.assertEqual([], m2.keys()) | self.assertEqual([], m2.keys()) | ||||
def testMatchesCwd(self): | def testMatchesCwd(self): | ||||
'''Tests matches() on a relpath match with the current directory ('.') | '''Tests matches() on a relpath match with the current directory ('.') | ||||
when not in the root directory.''' | when not in the root directory.''' | ||||
m = self.parsemanifest(A_DEEPER_MANIFEST) | m = self.parsemanifest(A_DEEPER_MANIFEST) |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
# OPT: these should probably be set(). | # OPT: these should probably be set(). | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
class ExactMatcherTests(unittest.TestCase): | class ExactMatcherTests(unittest.TestCase): | ||||
def testVisitdir(self): | def testVisitdir(self): | ||||
m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'], | m = matchmod.exact(b'x', b'', files=[b'dir/subdir/foo.txt']) | ||||
exact=True) | |||||
assert isinstance(m, matchmod.exactmatcher) | assert isinstance(m, matchmod.exactmatcher) | ||||
self.assertTrue(m.visitdir(b'.')) | self.assertTrue(m.visitdir(b'.')) | ||||
self.assertTrue(m.visitdir(b'dir')) | self.assertTrue(m.visitdir(b'dir')) | ||||
self.assertTrue(m.visitdir(b'dir/subdir')) | self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) | self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) | ||||
self.assertFalse(m.visitdir(b'dir/foo')) | self.assertFalse(m.visitdir(b'dir/foo')) | ||||
self.assertFalse(m.visitdir(b'dir/subdir/x')) | self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir(b'folder')) | self.assertFalse(m.visitdir(b'folder')) | ||||
def testVisitchildrenset(self): | def testVisitchildrenset(self): | ||||
m = matchmod.match(b'x', b'', patterns=[b'dir/subdir/foo.txt'], | m = matchmod.exact(b'x', b'', files=[b'dir/subdir/foo.txt']) | ||||
exact=True) | |||||
assert isinstance(m, matchmod.exactmatcher) | assert isinstance(m, matchmod.exactmatcher) | ||||
self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'dir'}) | ||||
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) | self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) | self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
def testVisitchildrensetFilesAndDirs(self): | def testVisitchildrensetFilesAndDirs(self): | ||||
m = matchmod.match(b'x', b'', patterns=[b'rootfile.txt', | m = matchmod.exact(b'x', b'', files=[b'rootfile.txt', | ||||
b'a/file1.txt', | b'a/file1.txt', | ||||
b'a/b/file2.txt', | b'a/b/file2.txt', | ||||
# no file in a/b/c | # no file in a/b/c | ||||
b'a/b/c/d/file4.txt'], | b'a/b/c/d/file4.txt']) | ||||
exact=True) | |||||
assert isinstance(m, matchmod.exactmatcher) | assert isinstance(m, matchmod.exactmatcher) | ||||
self.assertEqual(m.visitchildrenset(b'.'), {b'a', b'rootfile.txt'}) | self.assertEqual(m.visitchildrenset(b'.'), {b'a', b'rootfile.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) | self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) | self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) | self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) | self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) | self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | self.assertEqual(m.visitchildrenset(b'folder'), set()) |