Mercurial > hg
comparison tests/test-manifest.py @ 24298:49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
The _lazymanifest type(s) behave very much like a sorted dict with
filenames as keys and (nodeid, flags) as values. It therefore seems
surprising that its __iter__ generates 3-tuples of (path, nodeid,
flags). Let's make it match dict's behavior of generating the keys
instead, and add a new iterentries method for the 3-tuples. With this
change, the "x" in "if x in lm" and "for x in lm" now have the same
type (a filename string).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 12 Mar 2015 18:18:29 -0700 |
parents | 542c891274b2 |
children | bb8e2b1a0803 |
comparison
equal
deleted
inserted
replaced
24297:0178f500d61e | 24298:49cd847fd69a |
---|---|
38 self.assert_(thing in container, msg) | 38 self.assert_(thing in container, msg) |
39 | 39 |
40 def testEmptyManifest(self): | 40 def testEmptyManifest(self): |
41 m = manifestmod._lazymanifest('') | 41 m = manifestmod._lazymanifest('') |
42 self.assertEqual(0, len(m)) | 42 self.assertEqual(0, len(m)) |
43 self.assertEqual([], list(m)) | 43 self.assertEqual([], list(m.iterentries())) |
44 | 44 |
45 def testManifest(self): | 45 def testManifest(self): |
46 m = manifestmod._lazymanifest(A_SHORT_MANIFEST) | 46 m = manifestmod._lazymanifest(A_SHORT_MANIFEST) |
47 want = [ | 47 want = [ |
48 ('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), | 48 ('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), |
49 ('foo', binascii.unhexlify(HASH_1), ''), | 49 ('foo', binascii.unhexlify(HASH_1), ''), |
50 ] | 50 ] |
51 self.assertEqual(len(want), len(m)) | 51 self.assertEqual(len(want), len(m)) |
52 self.assertEqual(want, list(m)) | 52 self.assertEqual(want, list(m.iterentries())) |
53 self.assertEqual((binascii.unhexlify(HASH_1), ''), m['foo']) | 53 self.assertEqual((binascii.unhexlify(HASH_1), ''), m['foo']) |
54 self.assertRaises(KeyError, lambda : m['wat']) | 54 self.assertRaises(KeyError, lambda : m['wat']) |
55 self.assertEqual((binascii.unhexlify(HASH_2), 'l'), | 55 self.assertEqual((binascii.unhexlify(HASH_2), 'l'), |
56 m['bar/baz/qux.py']) | 56 m['bar/baz/qux.py']) |
57 | 57 |
86 self.assertEqual(3, len(m)) | 86 self.assertEqual(3, len(m)) |
87 self.assertEqual((h1, ''), m['alpha']) | 87 self.assertEqual((h1, ''), m['alpha']) |
88 self.assertEqual((h2, ''), m['beta']) | 88 self.assertEqual((h2, ''), m['beta']) |
89 self.assertRaises(KeyError, lambda : m['foo']) | 89 self.assertRaises(KeyError, lambda : m['foo']) |
90 w = [('alpha', h1, ''), ('bar/baz/qux.py', h2, 'l'), ('beta', h2, '')] | 90 w = [('alpha', h1, ''), ('bar/baz/qux.py', h2, 'l'), ('beta', h2, '')] |
91 self.assertEqual(w, list(m)) | 91 self.assertEqual(w, list(m.iterentries())) |
92 | 92 |
93 def testSetGetNodeSuffix(self): | 93 def testSetGetNodeSuffix(self): |
94 clean = manifestmod._lazymanifest(A_SHORT_MANIFEST) | 94 clean = manifestmod._lazymanifest(A_SHORT_MANIFEST) |
95 m = manifestmod._lazymanifest(A_SHORT_MANIFEST) | 95 m = manifestmod._lazymanifest(A_SHORT_MANIFEST) |
96 h, f = m['foo'] | 96 h, f = m['foo'] |
98 # Merge code wants to set 21-byte fake hashes at times | 98 # Merge code wants to set 21-byte fake hashes at times |
99 m['foo'] = want | 99 m['foo'] = want |
100 self.assertEqual(want, m['foo']) | 100 self.assertEqual(want, m['foo']) |
101 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), | 101 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), |
102 ('foo', binascii.unhexlify(HASH_1) + 'a', '')], | 102 ('foo', binascii.unhexlify(HASH_1) + 'a', '')], |
103 list(m)) | 103 list(m.iterentries())) |
104 # Sometimes it even tries a 22-byte fake hash, but we can | 104 # Sometimes it even tries a 22-byte fake hash, but we can |
105 # return 21 and it'll work out | 105 # return 21 and it'll work out |
106 m['foo'] = want[0] + '+', f | 106 m['foo'] = want[0] + '+', f |
107 self.assertEqual(want, m['foo']) | 107 self.assertEqual(want, m['foo']) |
108 # make sure the suffix survives a copy | 108 # make sure the suffix survives a copy |
112 self.assertEqual(('foo\0%s\n' % HASH_1), m2.text()) | 112 self.assertEqual(('foo\0%s\n' % HASH_1), m2.text()) |
113 m2 = m.copy() | 113 m2 = m.copy() |
114 self.assertEqual(want, m2['foo']) | 114 self.assertEqual(want, m2['foo']) |
115 # suffix with iteration | 115 # suffix with iteration |
116 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), | 116 self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2), 'l'), |
117 ('foo', want[0], '')], list(m)) | 117 ('foo', want[0], '')], list(m.iterentries())) |
118 # shows up in diff | 118 # shows up in diff |
119 self.assertEqual({'foo': (want, (h, ''))}, m.diff(clean)) | 119 self.assertEqual({'foo': (want, (h, ''))}, m.diff(clean)) |
120 self.assertEqual({'foo': ((h, ''), want)}, clean.diff(m)) | 120 self.assertEqual({'foo': ((h, ''), want)}, clean.diff(m)) |
121 | 121 |
122 def testFilterCopyException(self): | 122 def testFilterCopyException(self): |