tests/test-manifest.py
changeset 45942 89a2afe31e82
parent 45118 d0ef8c1dddd4
child 46780 6266d19556ad
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
    20 BIN_HASH_2 = binascii.unhexlify(HASH_2)
    20 BIN_HASH_2 = binascii.unhexlify(HASH_2)
    21 HASH_3 = b'1234567890abcdef0987654321deadbeef0fcafe'
    21 HASH_3 = b'1234567890abcdef0987654321deadbeef0fcafe'
    22 BIN_HASH_3 = binascii.unhexlify(HASH_3)
    22 BIN_HASH_3 = binascii.unhexlify(HASH_3)
    23 A_SHORT_MANIFEST = (
    23 A_SHORT_MANIFEST = (
    24     b'bar/baz/qux.py\0%(hash2)s%(flag2)s\n' b'foo\0%(hash1)s%(flag1)s\n'
    24     b'bar/baz/qux.py\0%(hash2)s%(flag2)s\n' b'foo\0%(hash1)s%(flag1)s\n'
    25 ) % {b'hash1': HASH_1, b'flag1': b'', b'hash2': HASH_2, b'flag2': b'l',}
    25 ) % {
       
    26     b'hash1': HASH_1,
       
    27     b'flag1': b'',
       
    28     b'hash2': HASH_2,
       
    29     b'flag2': b'l',
       
    30 }
    26 
    31 
    27 A_DEEPER_MANIFEST = (
    32 A_DEEPER_MANIFEST = (
    28     b'a/b/c/bar.py\0%(hash3)s%(flag1)s\n'
    33     b'a/b/c/bar.py\0%(hash3)s%(flag1)s\n'
    29     b'a/b/c/bar.txt\0%(hash1)s%(flag1)s\n'
    34     b'a/b/c/bar.txt\0%(hash1)s%(flag1)s\n'
    30     b'a/b/c/foo.py\0%(hash3)s%(flag1)s\n'
    35     b'a/b/c/foo.py\0%(hash3)s%(flag1)s\n'
   263         m = self.parsemanifest(A_HUGE_MANIFEST)
   268         m = self.parsemanifest(A_HUGE_MANIFEST)
   264         self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m))
   269         self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m))
   265         self.assertEqual(len(m), len(list(m)))
   270         self.assertEqual(len(m), len(list(m)))
   266 
   271 
   267     def testMatchesMetadata(self):
   272     def testMatchesMetadata(self):
   268         '''Tests matches() for a few specific files to make sure that both
   273         """Tests matches() for a few specific files to make sure that both
   269         the set of files as well as their flags and nodeids are correct in
   274         the set of files as well as their flags and nodeids are correct in
   270         the resulting manifest.'''
   275         the resulting manifest."""
   271         m = self.parsemanifest(A_HUGE_MANIFEST)
   276         m = self.parsemanifest(A_HUGE_MANIFEST)
   272 
   277 
   273         match = matchmod.exact([b'file1', b'file200', b'file300'])
   278         match = matchmod.exact([b'file1', b'file200', b'file300'])
   274         m2 = m._matches(match)
   279         m2 = m._matches(match)
   275 
   280 
   279             HASH_1,
   284             HASH_1,
   280         )
   285         )
   281         self.assertEqual(w, m2.text())
   286         self.assertEqual(w, m2.text())
   282 
   287 
   283     def testMatchesNonexistentFile(self):
   288     def testMatchesNonexistentFile(self):
   284         '''Tests matches() for a small set of specific files, including one
   289         """Tests matches() for a small set of specific files, including one
   285         nonexistent file to make sure in only matches against existing files.
   290         nonexistent file to make sure in only matches against existing files.
   286         '''
   291         """
   287         m = self.parsemanifest(A_DEEPER_MANIFEST)
   292         m = self.parsemanifest(A_DEEPER_MANIFEST)
   288 
   293 
   289         match = matchmod.exact(
   294         match = matchmod.exact(
   290             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
   295             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
   291         )
   296         )
   294         self.assertEqual(
   299         self.assertEqual(
   295             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
   300             [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
   296         )
   301         )
   297 
   302 
   298     def testMatchesNonexistentDirectory(self):
   303     def testMatchesNonexistentDirectory(self):
   299         '''Tests matches() for a relpath match on a directory that doesn't
   304         """Tests matches() for a relpath match on a directory that doesn't
   300         actually exist.'''
   305         actually exist."""
   301         m = self.parsemanifest(A_DEEPER_MANIFEST)
   306         m = self.parsemanifest(A_DEEPER_MANIFEST)
   302 
   307 
   303         match = matchmod.match(
   308         match = matchmod.match(
   304             util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
   309             util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
   305         )
   310         )
   306         m2 = m._matches(match)
   311         m2 = m._matches(match)
   307 
   312 
   308         self.assertEqual([], m2.keys())
   313         self.assertEqual([], m2.keys())
   309 
   314 
   310     def testMatchesExactLarge(self):
   315     def testMatchesExactLarge(self):
   311         '''Tests matches() for files matching a large list of exact files.
   316         """Tests matches() for files matching a large list of exact files."""
   312         '''
       
   313         m = self.parsemanifest(A_HUGE_MANIFEST)
   317         m = self.parsemanifest(A_HUGE_MANIFEST)
   314 
   318 
   315         flist = m.keys()[80:300]
   319         flist = m.keys()[80:300]
   316         match = matchmod.exact(flist)
   320         match = matchmod.exact(flist)
   317         m2 = m._matches(match)
   321         m2 = m._matches(match)
   326         m2 = m._matches(match)
   330         m2 = m._matches(match)
   327 
   331 
   328         self.assertEqual(m.keys(), m2.keys())
   332         self.assertEqual(m.keys(), m2.keys())
   329 
   333 
   330     def testMatchesDirectory(self):
   334     def testMatchesDirectory(self):
   331         '''Tests matches() on a relpath match on a directory, which should
   335         """Tests matches() on a relpath match on a directory, which should
   332         match against all files within said directory.'''
   336         match against all files within said directory."""
   333         m = self.parsemanifest(A_DEEPER_MANIFEST)
   337         m = self.parsemanifest(A_DEEPER_MANIFEST)
   334 
   338 
   335         match = matchmod.match(
   339         match = matchmod.match(
   336             util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
   340             util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
   337         )
   341         )
   351             ],
   355             ],
   352             m2.keys(),
   356             m2.keys(),
   353         )
   357         )
   354 
   358 
   355     def testMatchesExactPath(self):
   359     def testMatchesExactPath(self):
   356         '''Tests matches() on an exact match on a directory, which should
   360         """Tests matches() on an exact match on a directory, which should
   357         result in an empty manifest because you can't perform an exact match
   361         result in an empty manifest because you can't perform an exact match
   358         against a directory.'''
   362         against a directory."""
   359         m = self.parsemanifest(A_DEEPER_MANIFEST)
   363         m = self.parsemanifest(A_DEEPER_MANIFEST)
   360 
   364 
   361         match = matchmod.exact([b'a/b'])
   365         match = matchmod.exact([b'a/b'])
   362         m2 = m._matches(match)
   366         m2 = m._matches(match)
   363 
   367 
   364         self.assertEqual([], m2.keys())
   368         self.assertEqual([], m2.keys())
   365 
   369 
   366     def testMatchesCwd(self):
   370     def testMatchesCwd(self):
   367         '''Tests matches() on a relpath match with the current directory ('.')
   371         """Tests matches() on a relpath match with the current directory ('.')
   368         when not in the root directory.'''
   372         when not in the root directory."""
   369         m = self.parsemanifest(A_DEEPER_MANIFEST)
   373         m = self.parsemanifest(A_DEEPER_MANIFEST)
   370 
   374 
   371         match = matchmod.match(
   375         match = matchmod.match(
   372             util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
   376             util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
   373         )
   377         )
   387             ],
   391             ],
   388             m2.keys(),
   392             m2.keys(),
   389         )
   393         )
   390 
   394 
   391     def testMatchesWithPattern(self):
   395     def testMatchesWithPattern(self):
   392         '''Tests matches() for files matching a pattern that reside
   396         """Tests matches() for files matching a pattern that reside
   393         deeper than the specified directory.'''
   397         deeper than the specified directory."""
   394         m = self.parsemanifest(A_DEEPER_MANIFEST)
   398         m = self.parsemanifest(A_DEEPER_MANIFEST)
   395 
   399 
   396         match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
   400         match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
   397         m2 = m._matches(match)
   401         m2 = m._matches(match)
   398 
   402