comparison tests/test-fastannotate-revmap.py @ 41117:0fea133780bf

tests: add lots of b prefix goo to test-fastannotate-revmap.py All the paths are now bytes, so now things work correctly. # skip-blame just bytes/str issues in this test Differential Revision: https://phab.mercurial-scm.org/D5500
author Augie Fackler <raf@durin42.com>
date Sun, 06 Jan 2019 15:15:35 -0500
parents 5fd63bca43a4
children 2372284d9457
comparison
equal deleted inserted replaced
41116:1205ba8f11ac 41117:0fea133780bf
33 ensure(rm.maxrev == 0) 33 ensure(rm.maxrev == 0)
34 for i in xrange(5): 34 for i in xrange(5):
35 ensure(rm.rev2hsh(i) is None) 35 ensure(rm.rev2hsh(i) is None)
36 ensure(rm.hsh2rev(b'\0' * 20) is None) 36 ensure(rm.hsh2rev(b'\0' * 20) is None)
37 37
38 paths = ['', 'a', None, 'b', 'b', 'c', 'c', None, 'a', 'b', 'a', 'a'] 38 paths = [
39 b'', b'a', None, b'b', b'b', b'c', b'c', None, b'a', b'b', b'a', b'a']
39 for i in xrange(1, 5): 40 for i in xrange(1, 5):
40 ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i) 41 ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i)
41 42
42 ensure(rm.maxrev == 4) 43 ensure(rm.maxrev == 4)
43 for i in xrange(1, 5): 44 for i in xrange(1, 5):
86 87
87 def testcorruptformat(): 88 def testcorruptformat():
88 path = gettemppath() 89 path = gettemppath()
89 90
90 # incorrect header 91 # incorrect header
91 with open(path, 'w') as f: 92 with open(path, 'wb') as f:
92 f.write(b'NOT A VALID HEADER') 93 f.write(b'NOT A VALID HEADER')
93 try: 94 try:
94 revmap.revmap(path) 95 revmap.revmap(path)
95 ensure(False) 96 ensure(False)
96 except error.CorruptedFileError: 97 except error.CorruptedFileError:
104 rm = revmap.revmap(path) 105 rm = revmap.revmap(path)
105 ensure(rm.maxrev == 1) 106 ensure(rm.maxrev == 1)
106 107
107 # corrupt the file by appending a byte 108 # corrupt the file by appending a byte
108 size = os.stat(path).st_size 109 size = os.stat(path).st_size
109 with open(path, 'a') as f: 110 with open(path, 'ab') as f:
110 f.write('\xff') 111 f.write(b'\xff')
111 try: 112 try:
112 revmap.revmap(path) 113 revmap.revmap(path)
113 ensure(False) 114 ensure(False)
114 except error.CorruptedFileError: 115 except error.CorruptedFileError:
115 pass 116 pass
116 117
117 # corrupt the file by removing the last byte 118 # corrupt the file by removing the last byte
118 ensure(size > 0) 119 ensure(size > 0)
119 with open(path, 'w') as f: 120 with open(path, 'wb') as f:
120 f.truncate(size - 1) 121 f.truncate(size - 1)
121 try: 122 try:
122 revmap.revmap(path) 123 revmap.revmap(path)
123 ensure(False) 124 ensure(False)
124 except error.CorruptedFileError: 125 except error.CorruptedFileError:
128 129
129 def testcopyfrom(): 130 def testcopyfrom():
130 path = gettemppath() 131 path = gettemppath()
131 rm = revmap.revmap(path) 132 rm = revmap.revmap(path)
132 for i in xrange(1, 10): 133 for i in xrange(1, 10):
133 ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=str(i // 3)) == i) 134 ensure(rm.append(genhsh(i),
135 sidebranch=(i & 1), path=(b'%d' % (i // 3))) == i)
134 rm.flush() 136 rm.flush()
135 137
136 # copy rm to rm2 138 # copy rm to rm2
137 rm2 = revmap.revmap() 139 rm2 = revmap.revmap()
138 rm2.copyfrom(rm) 140 rm2.copyfrom(rm)
172 ensure((genhsh(i), None) not in rm) 174 ensure((genhsh(i), None) not in rm)
173 175
174 # "contains" checks paths 176 # "contains" checks paths
175 rm = revmap.revmap() 177 rm = revmap.revmap()
176 for i in xrange(1, 5): 178 for i in xrange(1, 5):
177 ensure(rm.append(genhsh(i), path=str(i // 2)) == i) 179 ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i)
178 for i in xrange(1, 5): 180 for i in xrange(1, 5):
179 ensure(fakefctx(genhsh(i), path=str(i // 2)) in rm) 181 ensure(fakefctx(genhsh(i), path=(b'%d' % (i // 2))) in rm)
180 ensure(fakefctx(genhsh(i), path='a') not in rm) 182 ensure(fakefctx(genhsh(i), path=b'a') not in rm)
181 183
182 def testlastnode(): 184 def testlastnode():
183 path = gettemppath() 185 path = gettemppath()
184 ensure(revmap.getlastnode(path) is None) 186 ensure(revmap.getlastnode(path) is None)
185 rm = revmap.revmap(path) 187 rm = revmap.revmap(path)
186 ensure(revmap.getlastnode(path) is None) 188 ensure(revmap.getlastnode(path) is None)
187 for i in xrange(1, 10): 189 for i in xrange(1, 10):
188 hsh = genhsh(i) 190 hsh = genhsh(i)
189 rm.append(hsh, path=str(i // 2), flush=True) 191 rm.append(hsh, path=(b'%d' % (i // 2)), flush=True)
190 ensure(revmap.getlastnode(path) == hsh) 192 ensure(revmap.getlastnode(path) == hsh)
191 rm2 = revmap.revmap(path) 193 rm2 = revmap.revmap(path)
192 ensure(rm2.rev2hsh(rm2.maxrev) == hsh) 194 ensure(rm2.rev2hsh(rm2.maxrev) == hsh)
193 195
194 testbasicreadwrite() 196 testbasicreadwrite()