Show More
@@ -5,6 +5,7 b' import itertools' | |||||
5 | import silenttestrunner |
|
5 | import silenttestrunner | |
6 |
|
6 | |||
7 | from mercurial import manifest as manifestmod |
|
7 | from mercurial import manifest as manifestmod | |
|
8 | from mercurial import match as matchmod | |||
8 |
|
9 | |||
9 | HASH_1 = '1' * 40 |
|
10 | HASH_1 = '1' * 40 | |
10 | HASH_2 = 'f' * 40 |
|
11 | HASH_2 = 'f' * 40 | |
@@ -26,6 +27,9 b" A_HUGE_MANIFEST = ''.join(sorted(" | |||||
26 | itertools.cycle((HASH_1, HASH_2)), |
|
27 | itertools.cycle((HASH_1, HASH_2)), | |
27 | itertools.cycle(('', 'x', 'l'))))) |
|
28 | itertools.cycle(('', 'x', 'l'))))) | |
28 |
|
29 | |||
|
30 | def parsemanifest(text): | |||
|
31 | return manifestmod.manifestdict(text) | |||
|
32 | ||||
29 | class testmanifest(unittest.TestCase): |
|
33 | class testmanifest(unittest.TestCase): | |
30 |
|
34 | |||
31 | def assertIn(self, thing, container, msg=None): |
|
35 | def assertIn(self, thing, container, msg=None): | |
@@ -38,41 +42,55 b' class testmanifest(unittest.TestCase):' | |||||
38 | self.assert_(thing in container, msg) |
|
42 | self.assert_(thing in container, msg) | |
39 |
|
43 | |||
40 | def testEmptyManifest(self): |
|
44 | def testEmptyManifest(self): | |
41 |
m = |
|
45 | m = parsemanifest('') | |
42 | self.assertEqual(0, len(m)) |
|
46 | self.assertEqual(0, len(m)) | |
43 |
self.assertEqual([], list(m |
|
47 | self.assertEqual([], list(m)) | |
44 |
|
48 | |||
45 | def testManifest(self): |
|
49 | def testManifest(self): | |
46 |
m = |
|
50 | m = parsemanifest(A_SHORT_MANIFEST) | |
47 | want = [ |
|
51 | self.assertEqual(['bar/baz/qux.py', 'foo'], list(m)) | |
48 |
|
|
52 | self.assertEqual(binascii.unhexlify(HASH_2), m['bar/baz/qux.py']) | |
49 | ('foo', binascii.unhexlify(HASH_1), ''), |
|
53 | self.assertEqual('l', m.flags('bar/baz/qux.py')) | |
50 | ] |
|
54 | self.assertEqual(binascii.unhexlify(HASH_1), m['foo']) | |
51 |
self.assertEqual( |
|
55 | self.assertEqual('', m.flags('foo')) | |
52 | self.assertEqual(want, list(m.iterentries())) |
|
|||
53 | self.assertEqual((binascii.unhexlify(HASH_1), ''), m['foo']) |
|
|||
54 | self.assertRaises(KeyError, lambda : m['wat']) |
|
56 | self.assertRaises(KeyError, lambda : m['wat']) | |
55 | self.assertEqual((binascii.unhexlify(HASH_2), 'l'), |
|
|||
56 | m['bar/baz/qux.py']) |
|
|||
57 |
|
57 | |||
58 | def testSetItem(self): |
|
58 | def testSetItem(self): | |
59 |
want = binascii.unhexlify(HASH_1) |
|
59 | want = binascii.unhexlify(HASH_1) | |
60 |
|
60 | |||
61 |
m = |
|
61 | m = parsemanifest('') | |
62 | m['a'] = want |
|
62 | m['a'] = want | |
63 | self.assertIn('a', m) |
|
63 | self.assertIn('a', m) | |
64 | self.assertEqual(want, m['a']) |
|
64 | self.assertEqual(want, m['a']) | |
65 | self.assertEqual('a\0' + HASH_1 + '\n', m.text()) |
|
65 | self.assertEqual('a\0' + HASH_1 + '\n', m.text()) | |
66 |
|
66 | |||
67 |
m = |
|
67 | m = parsemanifest(A_SHORT_MANIFEST) | |
68 | m['a'] = want |
|
68 | m['a'] = want | |
69 | self.assertEqual(want, m['a']) |
|
69 | self.assertEqual(want, m['a']) | |
70 | self.assertEqual('a\0' + HASH_1 + '\n' + A_SHORT_MANIFEST, |
|
70 | self.assertEqual('a\0' + HASH_1 + '\n' + A_SHORT_MANIFEST, | |
71 | m.text()) |
|
71 | m.text()) | |
72 |
|
72 | |||
|
73 | def testSetFlag(self): | |||
|
74 | want = 'x' | |||
|
75 | ||||
|
76 | m = parsemanifest('') | |||
|
77 | # first add a file; a file-less flag makes no sense | |||
|
78 | m['a'] = binascii.unhexlify(HASH_1) | |||
|
79 | m.setflag('a', want) | |||
|
80 | self.assertEqual(want, m.flags('a')) | |||
|
81 | self.assertEqual('a\0' + HASH_1 + want + '\n', m.text()) | |||
|
82 | ||||
|
83 | m = parsemanifest(A_SHORT_MANIFEST) | |||
|
84 | # first add a file; a file-less flag makes no sense | |||
|
85 | m['a'] = binascii.unhexlify(HASH_1) | |||
|
86 | m.setflag('a', want) | |||
|
87 | self.assertEqual(want, m.flags('a')) | |||
|
88 | self.assertEqual('a\0' + HASH_1 + want + '\n' + A_SHORT_MANIFEST, | |||
|
89 | m.text()) | |||
|
90 | ||||
73 | def testCopy(self): |
|
91 | def testCopy(self): | |
74 |
m = |
|
92 | m = parsemanifest(A_SHORT_MANIFEST) | |
75 |
m['a'] = binascii.unhexlify(HASH_1) |
|
93 | m['a'] = binascii.unhexlify(HASH_1) | |
76 | m2 = m.copy() |
|
94 | m2 = m.copy() | |
77 | del m |
|
95 | del m | |
78 | del m2 # make sure we don't double free() anything |
|
96 | del m2 # make sure we don't double free() anything | |
@@ -80,65 +98,74 b' class testmanifest(unittest.TestCase):' | |||||
80 | def testCompaction(self): |
|
98 | def testCompaction(self): | |
81 | unhex = binascii.unhexlify |
|
99 | unhex = binascii.unhexlify | |
82 | h1, h2 = unhex(HASH_1), unhex(HASH_2) |
|
100 | h1, h2 = unhex(HASH_1), unhex(HASH_2) | |
83 |
m = |
|
101 | m = parsemanifest(A_SHORT_MANIFEST) | |
84 |
m['alpha'] = h1 |
|
102 | m['alpha'] = h1 | |
85 |
m['beta'] = h2 |
|
103 | m['beta'] = h2 | |
86 | del m['foo'] |
|
104 | del m['foo'] | |
87 | want = 'alpha\0%s\nbar/baz/qux.py\0%sl\nbeta\0%s\n' % ( |
|
105 | want = 'alpha\0%s\nbar/baz/qux.py\0%sl\nbeta\0%s\n' % ( | |
88 | HASH_1, HASH_2, HASH_2) |
|
106 | HASH_1, HASH_2, HASH_2) | |
89 | self.assertEqual(want, m.text()) |
|
107 | self.assertEqual(want, m.text()) | |
90 | self.assertEqual(3, len(m)) |
|
108 | self.assertEqual(3, len(m)) | |
91 |
self.assertEqual( |
|
109 | self.assertEqual(['alpha', 'bar/baz/qux.py', 'beta'], list(m)) | |
92 |
self.assertEqual( |
|
110 | self.assertEqual(h1, m['alpha']) | |
|
111 | self.assertEqual(h2, m['bar/baz/qux.py']) | |||
|
112 | self.assertEqual(h2, m['beta']) | |||
|
113 | self.assertEqual('', m.flags('alpha')) | |||
|
114 | self.assertEqual('l', m.flags('bar/baz/qux.py')) | |||
|
115 | self.assertEqual('', m.flags('beta')) | |||
93 | self.assertRaises(KeyError, lambda : m['foo']) |
|
116 | self.assertRaises(KeyError, lambda : m['foo']) | |
94 | w = [('alpha', h1, ''), ('bar/baz/qux.py', h2, 'l'), ('beta', h2, '')] |
|
|||
95 | self.assertEqual(w, list(m.iterentries())) |
|
|||
96 |
|
117 | |||
97 | def testSetGetNodeSuffix(self): |
|
118 | def testSetGetNodeSuffix(self): | |
98 |
clean = |
|
119 | clean = parsemanifest(A_SHORT_MANIFEST) | |
99 |
m = |
|
120 | m = parsemanifest(A_SHORT_MANIFEST) | |
100 |
h |
|
121 | h = m['foo'] | |
101 | want = h + 'a', f |
|
122 | f = m.flags('foo') | |
|
123 | want = h + 'a' | |||
102 | # Merge code wants to set 21-byte fake hashes at times |
|
124 | # Merge code wants to set 21-byte fake hashes at times | |
103 | m['foo'] = want |
|
125 | m['foo'] = want | |
104 | self.assertEqual(want, m['foo']) |
|
126 | self.assertEqual(want, m['foo']) | |
105 |
self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2) |
|
127 | self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2)), | |
106 |
('foo', binascii.unhexlify(HASH_1) + 'a' |
|
128 | ('foo', binascii.unhexlify(HASH_1) + 'a')], | |
107 |
list(m.iter |
|
129 | list(m.iteritems())) | |
108 | # Sometimes it even tries a 22-byte fake hash, but we can |
|
130 | # Sometimes it even tries a 22-byte fake hash, but we can | |
109 | # return 21 and it'll work out |
|
131 | # return 21 and it'll work out | |
110 |
m['foo'] = want |
|
132 | m['foo'] = want + '+' | |
111 | self.assertEqual(want, m['foo']) |
|
133 | self.assertEqual(want, m['foo']) | |
112 | # make sure the suffix survives a copy |
|
134 | # make sure the suffix survives a copy | |
113 | m2 = m.filtercopy(lambda x: x == 'foo') |
|
135 | match = matchmod.match('', '', ['re:foo']) | |
|
136 | m2 = m.matches(match) | |||
114 | self.assertEqual(want, m2['foo']) |
|
137 | self.assertEqual(want, m2['foo']) | |
115 | self.assertEqual(1, len(m2)) |
|
138 | self.assertEqual(1, len(m2)) | |
116 | self.assertEqual(('foo\0%s\n' % HASH_1), m2.text()) |
|
139 | self.assertEqual(('foo\0%s\n' % HASH_1), m2.text()) | |
117 | m2 = m.copy() |
|
140 | m2 = m.copy() | |
118 | self.assertEqual(want, m2['foo']) |
|
141 | self.assertEqual(want, m2['foo']) | |
119 | # suffix with iteration |
|
142 | # suffix with iteration | |
120 |
self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2) |
|
143 | self.assertEqual([('bar/baz/qux.py', binascii.unhexlify(HASH_2)), | |
121 |
('foo', want |
|
144 | ('foo', want)], | |
|
145 | list(m.iteritems())) | |||
|
146 | ||||
122 | # shows up in diff |
|
147 | # shows up in diff | |
123 | self.assertEqual({'foo': (want, (h, ''))}, m.diff(clean)) |
|
148 | self.assertEqual({'foo': ((want, f), (h, ''))}, m.diff(clean)) | |
124 | self.assertEqual({'foo': ((h, ''), want)}, clean.diff(m)) |
|
149 | self.assertEqual({'foo': ((h, ''), (want, f))}, clean.diff(m)) | |
125 |
|
150 | |||
126 |
def test |
|
151 | def testMatchException(self): | |
127 |
m = |
|
152 | m = parsemanifest(A_SHORT_MANIFEST) | |
|
153 | match = matchmod.match('', '', ['re:.*']) | |||
128 | def filt(path): |
|
154 | def filt(path): | |
129 | if path == 'foo': |
|
155 | if path == 'foo': | |
130 | assert False |
|
156 | assert False | |
131 | return True |
|
157 | return True | |
132 | self.assertRaises(AssertionError, m.filtercopy, filt) |
|
158 | match.matchfn = filt | |
|
159 | self.assertRaises(AssertionError, m.matches, match) | |||
133 |
|
160 | |||
134 | def testRemoveItem(self): |
|
161 | def testRemoveItem(self): | |
135 |
m = |
|
162 | m = parsemanifest(A_SHORT_MANIFEST) | |
136 | del m['foo'] |
|
163 | del m['foo'] | |
137 | self.assertRaises(KeyError, lambda : m['foo']) |
|
164 | self.assertRaises(KeyError, lambda : m['foo']) | |
138 | self.assertEqual(1, len(m)) |
|
165 | self.assertEqual(1, len(m)) | |
139 | self.assertEqual(1, len(list(m))) |
|
166 | self.assertEqual(1, len(list(m))) | |
140 | # now restore and make sure everything works right |
|
167 | # now restore and make sure everything works right | |
141 |
m['foo'] = 'a' * 20 |
|
168 | m['foo'] = 'a' * 20 | |
142 | self.assertEqual(2, len(m)) |
|
169 | self.assertEqual(2, len(m)) | |
143 | self.assertEqual(2, len(list(m))) |
|
170 | self.assertEqual(2, len(list(m))) | |
144 |
|
171 | |||
@@ -146,9 +173,9 b' class testmanifest(unittest.TestCase):' | |||||
146 | MISSING = (None, '') |
|
173 | MISSING = (None, '') | |
147 | addl = 'z-only-in-left\0' + HASH_1 + '\n' |
|
174 | addl = 'z-only-in-left\0' + HASH_1 + '\n' | |
148 | addr = 'z-only-in-right\0' + HASH_2 + 'x\n' |
|
175 | addr = 'z-only-in-right\0' + HASH_2 + 'x\n' | |
149 |
left = |
|
176 | left = parsemanifest( | |
150 | A_SHORT_MANIFEST.replace(HASH_1, HASH_3 + 'x') + addl) |
|
177 | A_SHORT_MANIFEST.replace(HASH_1, HASH_3 + 'x') + addl) | |
151 |
right = |
|
178 | right = parsemanifest(A_SHORT_MANIFEST + addr) | |
152 | want = { |
|
179 | want = { | |
153 | 'foo': ((binascii.unhexlify(HASH_3), 'x'), |
|
180 | 'foo': ((binascii.unhexlify(HASH_3), 'x'), | |
154 | (binascii.unhexlify(HASH_1), '')), |
|
181 | (binascii.unhexlify(HASH_1), '')), | |
@@ -162,14 +189,14 b' class testmanifest(unittest.TestCase):' | |||||
162 | 'foo': (MISSING, (binascii.unhexlify(HASH_3), 'x')), |
|
189 | 'foo': (MISSING, (binascii.unhexlify(HASH_3), 'x')), | |
163 | 'z-only-in-left': (MISSING, (binascii.unhexlify(HASH_1), '')), |
|
190 | 'z-only-in-left': (MISSING, (binascii.unhexlify(HASH_1), '')), | |
164 | } |
|
191 | } | |
165 |
self.assertEqual(want, |
|
192 | self.assertEqual(want, parsemanifest('').diff(left)) | |
166 |
|
193 | |||
167 | want = { |
|
194 | want = { | |
168 | 'bar/baz/qux.py': ((binascii.unhexlify(HASH_2), 'l'), MISSING), |
|
195 | 'bar/baz/qux.py': ((binascii.unhexlify(HASH_2), 'l'), MISSING), | |
169 | 'foo': ((binascii.unhexlify(HASH_3), 'x'), MISSING), |
|
196 | 'foo': ((binascii.unhexlify(HASH_3), 'x'), MISSING), | |
170 | 'z-only-in-left': ((binascii.unhexlify(HASH_1), ''), MISSING), |
|
197 | 'z-only-in-left': ((binascii.unhexlify(HASH_1), ''), MISSING), | |
171 | } |
|
198 | } | |
172 |
self.assertEqual(want, left.diff( |
|
199 | self.assertEqual(want, left.diff(parsemanifest(''))) | |
173 | copy = right.copy() |
|
200 | copy = right.copy() | |
174 | del copy['z-only-in-right'] |
|
201 | del copy['z-only-in-right'] | |
175 | del right['foo'] |
|
202 | del right['foo'] | |
@@ -179,7 +206,7 b' class testmanifest(unittest.TestCase):' | |||||
179 | } |
|
206 | } | |
180 | self.assertEqual(want, right.diff(copy)) |
|
207 | self.assertEqual(want, right.diff(copy)) | |
181 |
|
208 | |||
182 |
short = |
|
209 | short = parsemanifest(A_SHORT_MANIFEST) | |
183 | pruned = short.copy() |
|
210 | pruned = short.copy() | |
184 | del pruned['foo'] |
|
211 | del pruned['foo'] | |
185 | want = { |
|
212 | want = { | |
@@ -200,32 +227,32 b' class testmanifest(unittest.TestCase):' | |||||
200 | backwards = ''.join( |
|
227 | backwards = ''.join( | |
201 | l + '\n' for l in reversed(A_SHORT_MANIFEST.split('\n')) if l) |
|
228 | l + '\n' for l in reversed(A_SHORT_MANIFEST.split('\n')) if l) | |
202 | try: |
|
229 | try: | |
203 |
|
|
230 | parsemanifest(backwards) | |
204 | self.fail('Should have raised ValueError') |
|
231 | self.fail('Should have raised ValueError') | |
205 | except ValueError, v: |
|
232 | except ValueError, v: | |
206 | self.assertIn('Manifest lines not in sorted order.', str(v)) |
|
233 | self.assertIn('Manifest lines not in sorted order.', str(v)) | |
207 |
|
234 | |||
208 | def testNoTerminalNewline(self): |
|
235 | def testNoTerminalNewline(self): | |
209 | try: |
|
236 | try: | |
210 |
|
|
237 | parsemanifest(A_SHORT_MANIFEST + 'wat') | |
211 | self.fail('Should have raised ValueError') |
|
238 | self.fail('Should have raised ValueError') | |
212 | except ValueError, v: |
|
239 | except ValueError, v: | |
213 | self.assertIn('Manifest did not end in a newline.', str(v)) |
|
240 | self.assertIn('Manifest did not end in a newline.', str(v)) | |
214 |
|
241 | |||
215 | def testNoNewLineAtAll(self): |
|
242 | def testNoNewLineAtAll(self): | |
216 | try: |
|
243 | try: | |
217 |
|
|
244 | parsemanifest('wat') | |
218 | self.fail('Should have raised ValueError') |
|
245 | self.fail('Should have raised ValueError') | |
219 | except ValueError, v: |
|
246 | except ValueError, v: | |
220 | self.assertIn('Manifest did not end in a newline.', str(v)) |
|
247 | self.assertIn('Manifest did not end in a newline.', str(v)) | |
221 |
|
248 | |||
222 | def testHugeManifest(self): |
|
249 | def testHugeManifest(self): | |
223 |
m = |
|
250 | m = parsemanifest(A_HUGE_MANIFEST) | |
224 | self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m)) |
|
251 | self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m)) | |
225 | self.assertEqual(len(m), len(list(m))) |
|
252 | self.assertEqual(len(m), len(list(m))) | |
226 |
|
253 | |||
227 | def testIntersectFiles(self): |
|
254 | def testIntersectFiles(self): | |
228 |
m = |
|
255 | m = parsemanifest(A_HUGE_MANIFEST) | |
229 | m2 = m.intersectfiles(['file1', 'file200', 'file300']) |
|
256 | m2 = m.intersectfiles(['file1', 'file200', 'file300']) | |
230 | w = ('file1\0%sx\n' |
|
257 | w = ('file1\0%sx\n' | |
231 | 'file200\0%sl\n' |
|
258 | 'file200\0%sl\n' |
General Comments 0
You need to be logged in to leave comments.
Login now