tests/test-manifest.py
changeset 44352 0bf3b5e80d30
parent 43964 8f67735344ae
child 44707 9d569983668b
equal deleted inserted replaced
44351:8ec186c1ccfe 44352:0bf3b5e80d30
   169         # return 21 and it'll work out
   169         # return 21 and it'll work out
   170         m[b'foo'] = want + b'+'
   170         m[b'foo'] = want + b'+'
   171         self.assertEqual(want, m[b'foo'])
   171         self.assertEqual(want, m[b'foo'])
   172         # make sure the suffix survives a copy
   172         # make sure the suffix survives a copy
   173         match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo'])
   173         match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo'])
   174         m2 = m.matches(match)
   174         m2 = m._matches(match)
   175         self.assertEqual(want, m2[b'foo'])
   175         self.assertEqual(want, m2[b'foo'])
   176         self.assertEqual(1, len(m2))
   176         self.assertEqual(1, len(m2))
   177         m2 = m.copy()
   177         m2 = m.copy()
   178         self.assertEqual(want, m2[b'foo'])
   178         self.assertEqual(want, m2[b'foo'])
   179         # suffix with iteration
   179         # suffix with iteration
   194                 assert False
   194                 assert False
   195             return True
   195             return True
   196 
   196 
   197         match.matchfn = filt
   197         match.matchfn = filt
   198         with self.assertRaises(AssertionError):
   198         with self.assertRaises(AssertionError):
   199             m.matches(match)
   199             m._matches(match)
   200 
   200 
   201     def testRemoveItem(self):
   201     def testRemoveItem(self):
   202         m = self.parsemanifest(A_SHORT_MANIFEST)
   202         m = self.parsemanifest(A_SHORT_MANIFEST)
   203         del m[b'foo']
   203         del m[b'foo']
   204         with self.assertRaises(KeyError):
   204         with self.assertRaises(KeyError):
   298         the set of files as well as their flags and nodeids are correct in
   298         the set of files as well as their flags and nodeids are correct in
   299         the resulting manifest.'''
   299         the resulting manifest.'''
   300         m = self.parsemanifest(A_HUGE_MANIFEST)
   300         m = self.parsemanifest(A_HUGE_MANIFEST)
   301 
   301 
   302         match = matchmod.exact([b'file1', b'file200', b'file300'])
   302         match = matchmod.exact([b'file1', b'file200', b'file300'])
   303         m2 = m.matches(match)
   303         m2 = m._matches(match)
   304 
   304 
   305         w = (b'file1\0%sx\n' b'file200\0%sl\n' b'file300\0%s\n') % (
   305         w = (b'file1\0%sx\n' b'file200\0%sl\n' b'file300\0%s\n') % (
   306             HASH_2,
   306             HASH_2,
   307             HASH_1,
   307             HASH_1,
   308             HASH_1,
   308             HASH_1,
   316         m = self.parsemanifest(A_DEEPER_MANIFEST)
   316         m = self.parsemanifest(A_DEEPER_MANIFEST)
   317 
   317 
   318         match = matchmod.exact(
   318         match = matchmod.exact(
   319             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
   319             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
   320         )
   320         )
   321         m2 = m.matches(match)
   321         m2 = m._matches(match)
   322 
   322 
   323         self.assertEqual(
   323         self.assertEqual(
   324             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
   324             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
   325         )
   325         )
   326 
   326 
   330         m = self.parsemanifest(A_DEEPER_MANIFEST)
   330         m = self.parsemanifest(A_DEEPER_MANIFEST)
   331 
   331 
   332         match = matchmod.match(
   332         match = matchmod.match(
   333             util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
   333             util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
   334         )
   334         )
   335         m2 = m.matches(match)
   335         m2 = m._matches(match)
   336 
   336 
   337         self.assertEqual([], m2.keys())
   337         self.assertEqual([], m2.keys())
   338 
   338 
   339     def testMatchesExactLarge(self):
   339     def testMatchesExactLarge(self):
   340         '''Tests matches() for files matching a large list of exact files.
   340         '''Tests matches() for files matching a large list of exact files.
   341         '''
   341         '''
   342         m = self.parsemanifest(A_HUGE_MANIFEST)
   342         m = self.parsemanifest(A_HUGE_MANIFEST)
   343 
   343 
   344         flist = m.keys()[80:300]
   344         flist = m.keys()[80:300]
   345         match = matchmod.exact(flist)
   345         match = matchmod.exact(flist)
   346         m2 = m.matches(match)
   346         m2 = m._matches(match)
   347 
   347 
   348         self.assertEqual(flist, m2.keys())
   348         self.assertEqual(flist, m2.keys())
   349 
   349 
   350     def testMatchesFull(self):
   350     def testMatchesFull(self):
   351         '''Tests matches() for what should be a full match.'''
   351         '''Tests matches() for what should be a full match.'''
   352         m = self.parsemanifest(A_DEEPER_MANIFEST)
   352         m = self.parsemanifest(A_DEEPER_MANIFEST)
   353 
   353 
   354         match = matchmod.match(util.localpath(b'/repo'), b'', [b''])
   354         match = matchmod.match(util.localpath(b'/repo'), b'', [b''])
   355         m2 = m.matches(match)
   355         m2 = m._matches(match)
   356 
   356 
   357         self.assertEqual(m.keys(), m2.keys())
   357         self.assertEqual(m.keys(), m2.keys())
   358 
   358 
   359     def testMatchesDirectory(self):
   359     def testMatchesDirectory(self):
   360         '''Tests matches() on a relpath match on a directory, which should
   360         '''Tests matches() on a relpath match on a directory, which should
   362         m = self.parsemanifest(A_DEEPER_MANIFEST)
   362         m = self.parsemanifest(A_DEEPER_MANIFEST)
   363 
   363 
   364         match = matchmod.match(
   364         match = matchmod.match(
   365             util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
   365             util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
   366         )
   366         )
   367         m2 = m.matches(match)
   367         m2 = m._matches(match)
   368 
   368 
   369         self.assertEqual(
   369         self.assertEqual(
   370             [
   370             [
   371                 b'a/b/c/bar.py',
   371                 b'a/b/c/bar.py',
   372                 b'a/b/c/bar.txt',
   372                 b'a/b/c/bar.txt',
   386         result in an empty manifest because you can't perform an exact match
   386         result in an empty manifest because you can't perform an exact match
   387         against a directory.'''
   387         against a directory.'''
   388         m = self.parsemanifest(A_DEEPER_MANIFEST)
   388         m = self.parsemanifest(A_DEEPER_MANIFEST)
   389 
   389 
   390         match = matchmod.exact([b'a/b'])
   390         match = matchmod.exact([b'a/b'])
   391         m2 = m.matches(match)
   391         m2 = m._matches(match)
   392 
   392 
   393         self.assertEqual([], m2.keys())
   393         self.assertEqual([], m2.keys())
   394 
   394 
   395     def testMatchesCwd(self):
   395     def testMatchesCwd(self):
   396         '''Tests matches() on a relpath match with the current directory ('.')
   396         '''Tests matches() on a relpath match with the current directory ('.')
   398         m = self.parsemanifest(A_DEEPER_MANIFEST)
   398         m = self.parsemanifest(A_DEEPER_MANIFEST)
   399 
   399 
   400         match = matchmod.match(
   400         match = matchmod.match(
   401             util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
   401             util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
   402         )
   402         )
   403         m2 = m.matches(match)
   403         m2 = m._matches(match)
   404 
   404 
   405         self.assertEqual(
   405         self.assertEqual(
   406             [
   406             [
   407                 b'a/b/c/bar.py',
   407                 b'a/b/c/bar.py',
   408                 b'a/b/c/bar.txt',
   408                 b'a/b/c/bar.txt',
   421         '''Tests matches() for files matching a pattern that reside
   421         '''Tests matches() for files matching a pattern that reside
   422         deeper than the specified directory.'''
   422         deeper than the specified directory.'''
   423         m = self.parsemanifest(A_DEEPER_MANIFEST)
   423         m = self.parsemanifest(A_DEEPER_MANIFEST)
   424 
   424 
   425         match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
   425         match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
   426         m2 = m.matches(match)
   426         m2 = m._matches(match)
   427 
   427 
   428         self.assertEqual(
   428         self.assertEqual(
   429             [b'a/b/c/bar.txt', b'a/b/c/foo.txt', b'a/b/d/ten.txt'], m2.keys()
   429             [b'a/b/c/bar.txt', b'a/b/c/foo.txt', b'a/b/d/ten.txt'], m2.keys()
   430         )
   430         )
   431 
   431