15 'foo\0%(hash1)s%(flag1)s\n' |
15 'foo\0%(hash1)s%(flag1)s\n' |
16 ) % {'hash1': HASH_1, |
16 ) % {'hash1': HASH_1, |
17 'flag1': '', |
17 'flag1': '', |
18 'hash2': HASH_2, |
18 'hash2': HASH_2, |
19 'flag2': 'l', |
19 'flag2': 'l', |
|
20 } |
|
21 |
|
22 A_DEEPER_MANIFEST = ( |
|
23 'a/b/c/bar.py\0%(hash3)s%(flag1)s\n' |
|
24 'a/b/c/bar.txt\0%(hash1)s%(flag1)s\n' |
|
25 'a/b/c/foo.py\0%(hash3)s%(flag1)s\n' |
|
26 'a/b/c/foo.txt\0%(hash2)s%(flag2)s\n' |
|
27 'a/b/d/baz.py\0%(hash3)s%(flag1)s\n' |
|
28 'a/b/d/qux.py\0%(hash1)s%(flag2)s\n' |
|
29 'a/b/d/ten.txt\0%(hash3)s%(flag2)s\n' |
|
30 'a/b/dog.py\0%(hash3)s%(flag1)s\n' |
|
31 'a/b/fish.py\0%(hash2)s%(flag1)s\n' |
|
32 'a/c/london.py\0%(hash3)s%(flag2)s\n' |
|
33 'a/c/paper.txt\0%(hash2)s%(flag2)s\n' |
|
34 'a/c/paris.py\0%(hash2)s%(flag1)s\n' |
|
35 'a/d/apple.py\0%(hash3)s%(flag1)s\n' |
|
36 'a/d/pizza.py\0%(hash3)s%(flag2)s\n' |
|
37 'a/green.py\0%(hash1)s%(flag2)s\n' |
|
38 'a/purple.py\0%(hash2)s%(flag1)s\n' |
|
39 'app.py\0%(hash3)s%(flag1)s\n' |
|
40 'readme.txt\0%(hash2)s%(flag1)s\n' |
|
41 ) % {'hash1': HASH_1, |
|
42 'flag1': '', |
|
43 'hash2': HASH_2, |
|
44 'flag2': 'l', |
|
45 'hash3': HASH_3, |
20 } |
46 } |
21 |
47 |
22 HUGE_MANIFEST_ENTRIES = 200001 |
48 HUGE_MANIFEST_ENTRIES = 200001 |
23 |
49 |
24 A_HUGE_MANIFEST = ''.join(sorted( |
50 A_HUGE_MANIFEST = ''.join(sorted( |
248 def testHugeManifest(self): |
274 def testHugeManifest(self): |
249 m = parsemanifest(A_HUGE_MANIFEST) |
275 m = parsemanifest(A_HUGE_MANIFEST) |
250 self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m)) |
276 self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m)) |
251 self.assertEqual(len(m), len(list(m))) |
277 self.assertEqual(len(m), len(list(m))) |
252 |
278 |
253 def testMatches(self): |
279 def testMatchesMetadata(self): |
|
280 '''Tests matches() for a few specific files to make sure that both |
|
281 the set of files as well as their flags and nodeids are correct in |
|
282 the resulting manifest.''' |
254 m = parsemanifest(A_HUGE_MANIFEST) |
283 m = parsemanifest(A_HUGE_MANIFEST) |
255 |
284 |
256 match = matchmod.match('/', '', |
285 match = matchmod.match('/', '', |
257 ['file1', 'file200', 'file300'], exact=True) |
286 ['file1', 'file200', 'file300'], exact=True) |
258 m2 = m.matches(match) |
287 m2 = m.matches(match) |
260 w = ('file1\0%sx\n' |
289 w = ('file1\0%sx\n' |
261 'file200\0%sl\n' |
290 'file200\0%sl\n' |
262 'file300\0%s\n') % (HASH_2, HASH_1, HASH_1) |
291 'file300\0%s\n') % (HASH_2, HASH_1, HASH_1) |
263 self.assertEqual(w, m2.text()) |
292 self.assertEqual(w, m2.text()) |
264 |
293 |
|
294 def testMatchesNonexistentFile(self): |
|
295 '''Tests matches() for a small set of specific files, including one |
|
296 nonexistent file to make sure in only matches against existing files. |
|
297 ''' |
|
298 m = parsemanifest(A_DEEPER_MANIFEST) |
|
299 |
|
300 match = matchmod.match('/', '', |
|
301 ['a/b/c/bar.txt', 'a/b/d/qux.py', 'readme.txt', 'nonexistent'], |
|
302 exact=True) |
|
303 m2 = m.matches(match) |
|
304 |
|
305 self.assertEqual( |
|
306 ['a/b/c/bar.txt', 'a/b/d/qux.py', 'readme.txt'], |
|
307 m2.keys()) |
|
308 |
|
309 def testMatchesNonexistentDirectory(self): |
|
310 '''Tests matches() for a relpath match on a directory that doesn't |
|
311 actually exist.''' |
|
312 m = parsemanifest(A_DEEPER_MANIFEST) |
|
313 |
|
314 match = matchmod.match('/', '', ['a/f'], default='relpath') |
|
315 m2 = m.matches(match) |
|
316 |
|
317 self.assertEqual([], m2.keys()) |
|
318 |
|
319 def testMatchesExactLarge(self): |
|
320 '''Tests matches() for files matching a large list of exact files. |
|
321 ''' |
|
322 m = parsemanifest(A_HUGE_MANIFEST) |
|
323 |
|
324 flist = m.keys()[80:300] |
|
325 match = matchmod.match('/', '', flist, exact=True) |
|
326 m2 = m.matches(match) |
|
327 |
|
328 self.assertEqual(flist, m2.keys()) |
|
329 |
|
330 def testMatchesFull(self): |
|
331 '''Tests matches() for what should be a full match.''' |
|
332 m = parsemanifest(A_DEEPER_MANIFEST) |
|
333 |
|
334 match = matchmod.match('/', '', ['']) |
|
335 m2 = m.matches(match) |
|
336 |
|
337 self.assertEqual(m.keys(), m2.keys()) |
|
338 |
|
339 def testMatchesDirectory(self): |
|
340 '''Tests matches() on a relpath match on a directory, which should |
|
341 match against all files within said directory.''' |
|
342 m = parsemanifest(A_DEEPER_MANIFEST) |
|
343 |
|
344 match = matchmod.match('/', '', ['a/b'], default='relpath') |
|
345 m2 = m.matches(match) |
|
346 |
|
347 self.assertEqual([ |
|
348 'a/b/c/bar.py', 'a/b/c/bar.txt', 'a/b/c/foo.py', 'a/b/c/foo.txt', |
|
349 'a/b/d/baz.py', 'a/b/d/qux.py', 'a/b/d/ten.txt', 'a/b/dog.py', |
|
350 'a/b/fish.py'], m2.keys()) |
|
351 |
|
352 def testMatchesExactPath(self): |
|
353 '''Tests matches() on an exact match on a directory, which should |
|
354 result in an empty manifest because you can't perform an exact match |
|
355 against a directory.''' |
|
356 m = parsemanifest(A_DEEPER_MANIFEST) |
|
357 |
|
358 match = matchmod.match('/', '', ['a/b'], exact=True) |
|
359 m2 = m.matches(match) |
|
360 |
|
361 self.assertEqual([], m2.keys()) |
|
362 |
|
363 def testMatchesCwd(self): |
|
364 '''Tests matches() on a relpath match with the current directory ('.') |
|
365 when not in the root directory.''' |
|
366 m = parsemanifest(A_DEEPER_MANIFEST) |
|
367 |
|
368 match = matchmod.match('/', 'a/b', ['.'], default='relpath') |
|
369 m2 = m.matches(match) |
|
370 |
|
371 self.assertEqual([ |
|
372 'a/b/c/bar.py', 'a/b/c/bar.txt', 'a/b/c/foo.py', 'a/b/c/foo.txt', |
|
373 'a/b/d/baz.py', 'a/b/d/qux.py', 'a/b/d/ten.txt', 'a/b/dog.py', |
|
374 'a/b/fish.py'], m2.keys()) |
|
375 |
|
376 def testMatchesWithPattern(self): |
|
377 '''Tests matches() for files matching a pattern that reside |
|
378 deeper than the specified directory.''' |
|
379 m = parsemanifest(A_DEEPER_MANIFEST) |
|
380 |
|
381 match = matchmod.match('/', '', ['a/b/*/*.txt']) |
|
382 m2 = m.matches(match) |
|
383 |
|
384 self.assertEqual( |
|
385 ['a/b/c/bar.txt', 'a/b/c/foo.txt', 'a/b/d/ten.txt'], |
|
386 m2.keys()) |
|
387 |
265 if __name__ == '__main__': |
388 if __name__ == '__main__': |
266 silenttestrunner.main(__name__) |
389 silenttestrunner.main(__name__) |