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