Mercurial > hg
comparison tests/test-manifest.py @ 24569:5491248e148a
test-manifest: create constant for empty manifest
For symmetry with manifest v2, once we add that, let's extract a
constant for the empty v1 manifest.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 31 Mar 2015 14:46:05 -0700 |
parents | bcf0de51326e |
children | 487245cbf1ab |
comparison
equal
deleted
inserted
replaced
24568:2e5f6cdf01f6 | 24569:5491248e148a |
---|---|
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 | |
10 EMTPY_MANIFEST = '' | |
9 | 11 |
10 HASH_1 = '1' * 40 | 12 HASH_1 = '1' * 40 |
11 HASH_2 = 'f' * 40 | 13 HASH_2 = 'f' * 40 |
12 HASH_3 = '1234567890abcdef0987654321deadbeef0fcafe' | 14 HASH_3 = '1234567890abcdef0987654321deadbeef0fcafe' |
13 A_SHORT_MANIFEST = ( | 15 A_SHORT_MANIFEST = ( |
66 if not msg: | 68 if not msg: |
67 msg = 'Expected %r in %r' % (thing, container) | 69 msg = 'Expected %r in %r' % (thing, container) |
68 self.assert_(thing in container, msg) | 70 self.assert_(thing in container, msg) |
69 | 71 |
70 def testEmptyManifest(self): | 72 def testEmptyManifest(self): |
71 m = parsemanifest('') | 73 m = parsemanifest(EMTPY_MANIFEST) |
72 self.assertEqual(0, len(m)) | 74 self.assertEqual(0, len(m)) |
73 self.assertEqual([], list(m)) | 75 self.assertEqual([], list(m)) |
74 | 76 |
75 def testManifest(self): | 77 def testManifest(self): |
76 m = parsemanifest(A_SHORT_MANIFEST) | 78 m = parsemanifest(A_SHORT_MANIFEST) |
82 self.assertRaises(KeyError, lambda : m['wat']) | 84 self.assertRaises(KeyError, lambda : m['wat']) |
83 | 85 |
84 def testSetItem(self): | 86 def testSetItem(self): |
85 want = binascii.unhexlify(HASH_1) | 87 want = binascii.unhexlify(HASH_1) |
86 | 88 |
87 m = parsemanifest('') | 89 m = parsemanifest(EMTPY_MANIFEST) |
88 m['a'] = want | 90 m['a'] = want |
89 self.assertIn('a', m) | 91 self.assertIn('a', m) |
90 self.assertEqual(want, m['a']) | 92 self.assertEqual(want, m['a']) |
91 self.assertEqual('a\0' + HASH_1 + '\n', m.text()) | 93 self.assertEqual('a\0' + HASH_1 + '\n', m.text()) |
92 | 94 |
97 m.text()) | 99 m.text()) |
98 | 100 |
99 def testSetFlag(self): | 101 def testSetFlag(self): |
100 want = 'x' | 102 want = 'x' |
101 | 103 |
102 m = parsemanifest('') | 104 m = parsemanifest(EMTPY_MANIFEST) |
103 # first add a file; a file-less flag makes no sense | 105 # first add a file; a file-less flag makes no sense |
104 m['a'] = binascii.unhexlify(HASH_1) | 106 m['a'] = binascii.unhexlify(HASH_1) |
105 m.setflag('a', want) | 107 m.setflag('a', want) |
106 self.assertEqual(want, m.flags('a')) | 108 self.assertEqual(want, m.flags('a')) |
107 self.assertEqual('a\0' + HASH_1 + want + '\n', m.text()) | 109 self.assertEqual('a\0' + HASH_1 + want + '\n', m.text()) |
212 want = { | 214 want = { |
213 'bar/baz/qux.py': (MISSING, (binascii.unhexlify(HASH_2), 'l')), | 215 'bar/baz/qux.py': (MISSING, (binascii.unhexlify(HASH_2), 'l')), |
214 'foo': (MISSING, (binascii.unhexlify(HASH_3), 'x')), | 216 'foo': (MISSING, (binascii.unhexlify(HASH_3), 'x')), |
215 'z-only-in-left': (MISSING, (binascii.unhexlify(HASH_1), '')), | 217 'z-only-in-left': (MISSING, (binascii.unhexlify(HASH_1), '')), |
216 } | 218 } |
217 self.assertEqual(want, parsemanifest('').diff(left)) | 219 self.assertEqual(want, parsemanifest(EMTPY_MANIFEST).diff(left)) |
218 | 220 |
219 want = { | 221 want = { |
220 'bar/baz/qux.py': ((binascii.unhexlify(HASH_2), 'l'), MISSING), | 222 'bar/baz/qux.py': ((binascii.unhexlify(HASH_2), 'l'), MISSING), |
221 'foo': ((binascii.unhexlify(HASH_3), 'x'), MISSING), | 223 'foo': ((binascii.unhexlify(HASH_3), 'x'), MISSING), |
222 'z-only-in-left': ((binascii.unhexlify(HASH_1), ''), MISSING), | 224 'z-only-in-left': ((binascii.unhexlify(HASH_1), ''), MISSING), |
223 } | 225 } |
224 self.assertEqual(want, left.diff(parsemanifest(''))) | 226 self.assertEqual(want, left.diff(parsemanifest(EMTPY_MANIFEST))) |
225 copy = right.copy() | 227 copy = right.copy() |
226 del copy['z-only-in-right'] | 228 del copy['z-only-in-right'] |
227 del right['foo'] | 229 del right['foo'] |
228 want = { | 230 want = { |
229 'foo': (MISSING, (binascii.unhexlify(HASH_1), '')), | 231 'foo': (MISSING, (binascii.unhexlify(HASH_1), '')), |