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