tests/test-manifest.py
changeset 43964 8f67735344ae
parent 43949 8b1a9ba375e5
child 44352 0bf3b5e80d30
equal deleted inserted replaced
43963:bbcf78c4ff90 43964:8f67735344ae
     7 import zlib
     7 import zlib
     8 
     8 
     9 from mercurial import (
     9 from mercurial import (
    10     manifest as manifestmod,
    10     manifest as manifestmod,
    11     match as matchmod,
    11     match as matchmod,
       
    12     util,
    12 )
    13 )
    13 
    14 
    14 EMTPY_MANIFEST = b''
    15 EMTPY_MANIFEST = b''
    15 
    16 
    16 HASH_1 = b'1' * 40
    17 HASH_1 = b'1' * 40
   167         # Sometimes it even tries a 22-byte fake hash, but we can
   168         # Sometimes it even tries a 22-byte fake hash, but we can
   168         # return 21 and it'll work out
   169         # return 21 and it'll work out
   169         m[b'foo'] = want + b'+'
   170         m[b'foo'] = want + b'+'
   170         self.assertEqual(want, m[b'foo'])
   171         self.assertEqual(want, m[b'foo'])
   171         # make sure the suffix survives a copy
   172         # make sure the suffix survives a copy
   172         match = matchmod.match(b'/repo', b'', [b're:foo'])
   173         match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo'])
   173         m2 = m.matches(match)
   174         m2 = m.matches(match)
   174         self.assertEqual(want, m2[b'foo'])
   175         self.assertEqual(want, m2[b'foo'])
   175         self.assertEqual(1, len(m2))
   176         self.assertEqual(1, len(m2))
   176         m2 = m.copy()
   177         m2 = m.copy()
   177         self.assertEqual(want, m2[b'foo'])
   178         self.assertEqual(want, m2[b'foo'])
   184         self.assertEqual({b'foo': ((want, f), (h, b''))}, m.diff(clean))
   185         self.assertEqual({b'foo': ((want, f), (h, b''))}, m.diff(clean))
   185         self.assertEqual({b'foo': ((h, b''), (want, f))}, clean.diff(m))
   186         self.assertEqual({b'foo': ((h, b''), (want, f))}, clean.diff(m))
   186 
   187 
   187     def testMatchException(self):
   188     def testMatchException(self):
   188         m = self.parsemanifest(A_SHORT_MANIFEST)
   189         m = self.parsemanifest(A_SHORT_MANIFEST)
   189         match = matchmod.match(b'/repo', b'', [b're:.*'])
   190         match = matchmod.match(util.localpath(b'/repo'), b'', [b're:.*'])
   190 
   191 
   191         def filt(path):
   192         def filt(path):
   192             if path == b'foo':
   193             if path == b'foo':
   193                 assert False
   194                 assert False
   194             return True
   195             return True
   326     def testMatchesNonexistentDirectory(self):
   327     def testMatchesNonexistentDirectory(self):
   327         '''Tests matches() for a relpath match on a directory that doesn't
   328         '''Tests matches() for a relpath match on a directory that doesn't
   328         actually exist.'''
   329         actually exist.'''
   329         m = self.parsemanifest(A_DEEPER_MANIFEST)
   330         m = self.parsemanifest(A_DEEPER_MANIFEST)
   330 
   331 
   331         match = matchmod.match(b'/repo', b'', [b'a/f'], default=b'relpath')
   332         match = matchmod.match(
       
   333             util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
       
   334         )
   332         m2 = m.matches(match)
   335         m2 = m.matches(match)
   333 
   336 
   334         self.assertEqual([], m2.keys())
   337         self.assertEqual([], m2.keys())
   335 
   338 
   336     def testMatchesExactLarge(self):
   339     def testMatchesExactLarge(self):
   346 
   349 
   347     def testMatchesFull(self):
   350     def testMatchesFull(self):
   348         '''Tests matches() for what should be a full match.'''
   351         '''Tests matches() for what should be a full match.'''
   349         m = self.parsemanifest(A_DEEPER_MANIFEST)
   352         m = self.parsemanifest(A_DEEPER_MANIFEST)
   350 
   353 
   351         match = matchmod.match(b'/repo', b'', [b''])
   354         match = matchmod.match(util.localpath(b'/repo'), b'', [b''])
   352         m2 = m.matches(match)
   355         m2 = m.matches(match)
   353 
   356 
   354         self.assertEqual(m.keys(), m2.keys())
   357         self.assertEqual(m.keys(), m2.keys())
   355 
   358 
   356     def testMatchesDirectory(self):
   359     def testMatchesDirectory(self):
   357         '''Tests matches() on a relpath match on a directory, which should
   360         '''Tests matches() on a relpath match on a directory, which should
   358         match against all files within said directory.'''
   361         match against all files within said directory.'''
   359         m = self.parsemanifest(A_DEEPER_MANIFEST)
   362         m = self.parsemanifest(A_DEEPER_MANIFEST)
   360 
   363 
   361         match = matchmod.match(b'/repo', b'', [b'a/b'], default=b'relpath')
   364         match = matchmod.match(
       
   365             util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
       
   366         )
   362         m2 = m.matches(match)
   367         m2 = m.matches(match)
   363 
   368 
   364         self.assertEqual(
   369         self.assertEqual(
   365             [
   370             [
   366                 b'a/b/c/bar.py',
   371                 b'a/b/c/bar.py',
   390     def testMatchesCwd(self):
   395     def testMatchesCwd(self):
   391         '''Tests matches() on a relpath match with the current directory ('.')
   396         '''Tests matches() on a relpath match with the current directory ('.')
   392         when not in the root directory.'''
   397         when not in the root directory.'''
   393         m = self.parsemanifest(A_DEEPER_MANIFEST)
   398         m = self.parsemanifest(A_DEEPER_MANIFEST)
   394 
   399 
   395         match = matchmod.match(b'/repo', b'a/b', [b'.'], default=b'relpath')
   400         match = matchmod.match(
       
   401             util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
       
   402         )
   396         m2 = m.matches(match)
   403         m2 = m.matches(match)
   397 
   404 
   398         self.assertEqual(
   405         self.assertEqual(
   399             [
   406             [
   400                 b'a/b/c/bar.py',
   407                 b'a/b/c/bar.py',
   413     def testMatchesWithPattern(self):
   420     def testMatchesWithPattern(self):
   414         '''Tests matches() for files matching a pattern that reside
   421         '''Tests matches() for files matching a pattern that reside
   415         deeper than the specified directory.'''
   422         deeper than the specified directory.'''
   416         m = self.parsemanifest(A_DEEPER_MANIFEST)
   423         m = self.parsemanifest(A_DEEPER_MANIFEST)
   417 
   424 
   418         match = matchmod.match(b'/repo', b'', [b'a/b/*/*.txt'])
   425         match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
   419         m2 = m.matches(match)
   426         m2 = m.matches(match)
   420 
   427 
   421         self.assertEqual(
   428         self.assertEqual(
   422             [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()
   423         )
   430         )
   465                 [b'', b'a/', b'a/c/', b'a/d/', b'a/b/', b'a/b/c/', b'a/b/d/']
   472                 [b'', b'a/', b'a/c/', b'a/d/', b'a/b/', b'a/b/c/', b'a/b/d/']
   466             ),
   473             ),
   467             sorted(dirs),
   474             sorted(dirs),
   468         )
   475         )
   469 
   476 
   470         match = matchmod.match(b'/repo', b'', [b'path:a/b/'])
   477         match = matchmod.match(util.localpath(b'/repo'), b'', [b'path:a/b/'])
   471         dirs = [s._dir for s in m.walksubtrees(matcher=match)]
   478         dirs = [s._dir for s in m.walksubtrees(matcher=match)]
   472         self.assertEqual(sorted([b'a/b/', b'a/b/c/', b'a/b/d/']), sorted(dirs))
   479         self.assertEqual(sorted([b'a/b/', b'a/b/c/', b'a/b/d/']), sorted(dirs))
   473 
   480 
   474 
   481 
   475 if __name__ == '__main__':
   482 if __name__ == '__main__':