Show More
@@ -52,7 +52,7 b' class datapacktestsbase(object):' | |||
|
52 | 52 | |
|
53 | 53 | def createPack(self, revisions=None, packdir=None): |
|
54 | 54 | if revisions is None: |
|
55 | revisions = [("filename", self.getFakeHash(), nullid, "content")] | |
|
55 | revisions = [(b"filename", self.getFakeHash(), nullid, b"content")] | |
|
56 | 56 | |
|
57 | 57 | if packdir is None: |
|
58 | 58 | packdir = self.makeTempDir() |
@@ -73,7 +73,7 b' class datapacktestsbase(object):' | |||
|
73 | 73 | def _testAddSingle(self, content): |
|
74 | 74 | """Test putting a simple blob into a pack and reading it out. |
|
75 | 75 | """ |
|
76 | filename = "foo" | |
|
76 | filename = b"foo" | |
|
77 | 77 | node = self.getHash(content) |
|
78 | 78 | |
|
79 | 79 | revisions = [(filename, node, nullid, content)] |
@@ -86,10 +86,10 b' class datapacktestsbase(object):' | |||
|
86 | 86 | self.assertEqual(content, chain[0][4]) |
|
87 | 87 | |
|
88 | 88 | def testAddSingle(self): |
|
89 | self._testAddSingle('') | |
|
89 | self._testAddSingle(b'') | |
|
90 | 90 | |
|
91 | 91 | def testAddSingleEmpty(self): |
|
92 | self._testAddSingle('abcdef') | |
|
92 | self._testAddSingle(b'abcdef') | |
|
93 | 93 | |
|
94 | 94 | def testAddMultiple(self): |
|
95 | 95 | """Test putting multiple unrelated blobs into a pack and reading them |
@@ -97,8 +97,8 b' class datapacktestsbase(object):' | |||
|
97 | 97 | """ |
|
98 | 98 | revisions = [] |
|
99 | 99 | for i in range(10): |
|
100 |
filename = "foo% |
|
|
101 |
content = "abcdef% |
|
|
100 | filename = b"foo%d" % i | |
|
101 | content = b"abcdef%d" % i | |
|
102 | 102 | node = self.getHash(content) |
|
103 | 103 | revisions.append((filename, node, self.getFakeHash(), content)) |
|
104 | 104 | |
@@ -115,10 +115,10 b' class datapacktestsbase(object):' | |||
|
115 | 115 | """Test putting multiple delta blobs into a pack and read the chain. |
|
116 | 116 | """ |
|
117 | 117 | revisions = [] |
|
118 | filename = "foo" | |
|
118 | filename = b"foo" | |
|
119 | 119 | lastnode = nullid |
|
120 | 120 | for i in range(10): |
|
121 |
content = "abcdef% |
|
|
121 | content = b"abcdef%d" % i | |
|
122 | 122 | node = self.getHash(content) |
|
123 | 123 | revisions.append((filename, node, lastnode, content)) |
|
124 | 124 | lastnode = node |
@@ -132,7 +132,7 b' class datapacktestsbase(object):' | |||
|
132 | 132 | # Test that the chain for the final entry has all the others |
|
133 | 133 | chain = pack.getdeltachain(filename, node) |
|
134 | 134 | for i in range(10): |
|
135 |
content = "abcdef% |
|
|
135 | content = b"abcdef%d" % i | |
|
136 | 136 | self.assertEqual(content, chain[-i - 1][4]) |
|
137 | 137 | |
|
138 | 138 | def testPackMany(self): |
@@ -143,10 +143,10 b' class datapacktestsbase(object):' | |||
|
143 | 143 | blobs = {} |
|
144 | 144 | random.seed(0) |
|
145 | 145 | for i in range(100): |
|
146 |
filename = "filename-% |
|
|
146 | filename = b"filename-%d" % i | |
|
147 | 147 | filerevs = [] |
|
148 | 148 | for j in range(random.randint(1, 100)): |
|
149 |
content = "content-% |
|
|
149 | content = b"content-%d" % j | |
|
150 | 150 | node = self.getHash(content) |
|
151 | 151 | lastnode = nullid |
|
152 | 152 | if len(filerevs) > 0: |
@@ -167,13 +167,13 b' class datapacktestsbase(object):' | |||
|
167 | 167 | def testPackMetadata(self): |
|
168 | 168 | revisions = [] |
|
169 | 169 | for i in range(100): |
|
170 |
filename = '% |
|
|
171 | content = 'put-something-here \n' * i | |
|
170 | filename = b'%d.txt' % i | |
|
171 | content = b'put-something-here \n' * i | |
|
172 | 172 | node = self.getHash(content) |
|
173 | 173 | meta = {constants.METAKEYFLAG: i ** 4, |
|
174 | 174 | constants.METAKEYSIZE: len(content), |
|
175 | 'Z': 'random_string', | |
|
176 | '_': '\0' * i} | |
|
175 | b'Z': b'random_string', | |
|
176 | b'_': b'\0' * i} | |
|
177 | 177 | revisions.append((filename, node, nullid, content, meta)) |
|
178 | 178 | pack = self.createPack(revisions) |
|
179 | 179 | for name, node, x, content, origmeta in revisions: |
@@ -187,39 +187,40 b' class datapacktestsbase(object):' | |||
|
187 | 187 | """Test the getmissing() api. |
|
188 | 188 | """ |
|
189 | 189 | revisions = [] |
|
190 | filename = "foo" | |
|
190 | filename = b"foo" | |
|
191 | 191 | lastnode = nullid |
|
192 | 192 | for i in range(10): |
|
193 |
content = "abcdef% |
|
|
193 | content = b"abcdef%d" % i | |
|
194 | 194 | node = self.getHash(content) |
|
195 | 195 | revisions.append((filename, node, lastnode, content)) |
|
196 | 196 | lastnode = node |
|
197 | 197 | |
|
198 | 198 | pack = self.createPack(revisions) |
|
199 | 199 | |
|
200 | missing = pack.getmissing([("foo", revisions[0][1])]) | |
|
200 | missing = pack.getmissing([(b"foo", revisions[0][1])]) | |
|
201 | 201 | self.assertFalse(missing) |
|
202 | 202 | |
|
203 | missing = pack.getmissing([("foo", revisions[0][1]), | |
|
204 | ("foo", revisions[1][1])]) | |
|
203 | missing = pack.getmissing([(b"foo", revisions[0][1]), | |
|
204 | (b"foo", revisions[1][1])]) | |
|
205 | 205 | self.assertFalse(missing) |
|
206 | 206 | |
|
207 | 207 | fakenode = self.getFakeHash() |
|
208 |
missing = pack.getmissing([("foo", revisions[0][1]), |
|
|
209 | self.assertEqual(missing, [("foo", fakenode)]) | |
|
208 | missing = pack.getmissing([(b"foo", revisions[0][1]), | |
|
209 | (b"foo", fakenode)]) | |
|
210 | self.assertEqual(missing, [(b"foo", fakenode)]) | |
|
210 | 211 | |
|
211 | 212 | def testAddThrows(self): |
|
212 | 213 | pack = self.createPack() |
|
213 | 214 | |
|
214 | 215 | try: |
|
215 | pack.add('filename', nullid, 'contents') | |
|
216 | pack.add(b'filename', nullid, b'contents') | |
|
216 | 217 | self.assertTrue(False, "datapack.add should throw") |
|
217 | 218 | except RuntimeError: |
|
218 | 219 | pass |
|
219 | 220 | |
|
220 | 221 | def testBadVersionThrows(self): |
|
221 | 222 | pack = self.createPack() |
|
222 | path = pack.path + '.datapack' | |
|
223 | path = pack.path + b'.datapack' | |
|
223 | 224 | with open(path) as f: |
|
224 | 225 | raw = f.read() |
|
225 | 226 | raw = struct.pack('!B', 255) + raw[1:] |
@@ -235,9 +236,9 b' class datapacktestsbase(object):' | |||
|
235 | 236 | |
|
236 | 237 | def testMissingDeltabase(self): |
|
237 | 238 | fakenode = self.getFakeHash() |
|
238 | revisions = [("filename", fakenode, self.getFakeHash(), "content")] | |
|
239 | revisions = [(b"filename", fakenode, self.getFakeHash(), b"content")] | |
|
239 | 240 | pack = self.createPack(revisions) |
|
240 | chain = pack.getdeltachain("filename", fakenode) | |
|
241 | chain = pack.getdeltachain(b"filename", fakenode) | |
|
241 | 242 | self.assertEqual(len(chain), 1) |
|
242 | 243 | |
|
243 | 244 | def testLargePack(self): |
@@ -247,7 +248,7 b' class datapacktestsbase(object):' | |||
|
247 | 248 | blobs = {} |
|
248 | 249 | total = basepack.SMALLFANOUTCUTOFF + 1 |
|
249 | 250 | for i in pycompat.xrange(total): |
|
250 |
filename = "filename-% |
|
|
251 | filename = b"filename-%d" % i | |
|
251 | 252 | content = filename |
|
252 | 253 | node = self.getHash(content) |
|
253 | 254 | blobs[(filename, node)] = content |
@@ -274,12 +275,12 b' class datapacktestsbase(object):' | |||
|
274 | 275 | |
|
275 | 276 | for i in range(numpacks): |
|
276 | 277 | chain = [] |
|
277 |
revision = ( |
|
|
278 | revision = (b'%d' % i, self.getFakeHash(), nullid, b"content") | |
|
278 | 279 | |
|
279 | 280 | for _ in range(revisionsperpack): |
|
280 | 281 | chain.append(revision) |
|
281 | 282 | revision = ( |
|
282 |
|
|
|
283 | b'%d' % i, | |
|
283 | 284 | self.getFakeHash(), |
|
284 | 285 | revision[1], |
|
285 | 286 | self.getFakeHash() |
@@ -330,8 +331,8 b' class datapacktestsbase(object):' | |||
|
330 | 331 | for packsize in packsizes: |
|
331 | 332 | revisions = [] |
|
332 | 333 | for i in pycompat.xrange(packsize): |
|
333 |
filename = "filename-% |
|
|
334 |
content = "content-% |
|
|
334 | filename = b"filename-%d" % i | |
|
335 | content = b"content-%d" % i | |
|
335 | 336 | node = self.getHash(content) |
|
336 | 337 | revisions.append((filename, node, nullid, content)) |
|
337 | 338 | |
@@ -350,9 +351,9 b' class datapacktestsbase(object):' | |||
|
350 | 351 | start = time.time() |
|
351 | 352 | pack.getmissing(findnodes[:lookupsize]) |
|
352 | 353 | elapsed = time.time() - start |
|
353 |
print ("%s pack % |
|
|
354 |
(('% |
|
|
355 |
('% |
|
|
354 | print ("%s pack %d lookups = %0.04f" % | |
|
355 | (('%d' % packsize).rjust(7), | |
|
356 | ('%d' % lookupsize).rjust(7), | |
|
356 | 357 | elapsed)) |
|
357 | 358 | |
|
358 | 359 | print("") |
General Comments 0
You need to be logged in to leave comments.
Login now