36
38
gc_module = compiled_groupcompress_feature.module
37
39
scenarios.append(('C',
38
40
{'_gc_module': gc_module}))
39
two_way_scenarios.extend([
44
def two_way_scenarios():
46
('PP', {'make_delta': _groupcompress_py.make_delta,
47
'apply_delta': _groupcompress_py.apply_delta})
49
if compiled_groupcompress_feature.available():
50
gc_module = compiled_groupcompress_feature.module
40
52
('CC', {'make_delta': gc_module.make_delta,
41
53
'apply_delta': gc_module.apply_delta}),
42
54
('PC', {'make_delta': _groupcompress_py.make_delta,
44
56
('CP', {'make_delta': gc_module.make_delta,
45
57
'apply_delta': _groupcompress_py.apply_delta}),
47
to_adapt, result = tests.split_suite_by_condition(
48
standard_tests, tests.condition_isinstance((TestMakeAndApplyDelta,
50
result = tests.multiply_tests(to_adapt, scenarios, result)
51
to_adapt, result = tests.split_suite_by_condition(result,
52
tests.condition_isinstance(TestMakeAndApplyCompatible))
53
result = tests.multiply_tests(to_adapt, two_way_scenarios, result)
57
compiled_groupcompress_feature = tests.ModuleAvailableFeature(
58
'bzrlib._groupcompress_pyx')
62
load_tests = load_tests_apply_scenarios
65
compiled_groupcompress_feature = features.ModuleAvailableFeature(
66
'breezy.bzr._groupcompress_pyx')
258
269
di = self._gc_module.DeltaIndex('test text\n')
259
270
self.assertEqual('DeltaIndex(1, 10)', repr(di))
272
def test__dump_no_index(self):
273
di = self._gc_module.DeltaIndex()
274
self.assertEqual(None, di._dump_index())
276
def test__dump_index_simple(self):
277
di = self._gc_module.DeltaIndex()
278
di.add_source(_text1, 0)
279
self.assertFalse(di._has_index())
280
self.assertEqual(None, di._dump_index())
281
_ = di.make_delta(_text1)
282
self.assertTrue(di._has_index())
283
hash_list, entry_list = di._dump_index()
284
self.assertEqual(16, len(hash_list))
285
self.assertEqual(68, len(entry_list))
286
just_entries = [(idx, text_offset, hash_val)
287
for idx, (text_offset, hash_val)
288
in enumerate(entry_list)
289
if text_offset != 0 or hash_val != 0]
290
rabin_hash = self._gc_module._rabin_hash
291
self.assertEqual([(8, 16, rabin_hash(_text1[1:17])),
292
(25, 48, rabin_hash(_text1[33:49])),
293
(34, 32, rabin_hash(_text1[17:33])),
294
(47, 64, rabin_hash(_text1[49:65])),
296
# This ensures that the hash map points to the location we expect it to
297
for entry_idx, text_offset, hash_val in just_entries:
298
self.assertEqual(entry_idx, hash_list[hash_val & 0xf])
300
def test__dump_index_two_sources(self):
301
di = self._gc_module.DeltaIndex()
302
di.add_source(_text1, 0)
303
di.add_source(_text2, 2)
304
start2 = len(_text1) + 2
305
self.assertTrue(di._has_index())
306
hash_list, entry_list = di._dump_index()
307
self.assertEqual(16, len(hash_list))
308
self.assertEqual(68, len(entry_list))
309
just_entries = [(idx, text_offset, hash_val)
310
for idx, (text_offset, hash_val)
311
in enumerate(entry_list)
312
if text_offset != 0 or hash_val != 0]
313
rabin_hash = self._gc_module._rabin_hash
314
self.assertEqual([(8, 16, rabin_hash(_text1[1:17])),
315
(9, start2+16, rabin_hash(_text2[1:17])),
316
(25, 48, rabin_hash(_text1[33:49])),
317
(30, start2+64, rabin_hash(_text2[49:65])),
318
(34, 32, rabin_hash(_text1[17:33])),
319
(35, start2+32, rabin_hash(_text2[17:33])),
320
(43, start2+48, rabin_hash(_text2[33:49])),
321
(47, 64, rabin_hash(_text1[49:65])),
323
# Each entry should be in the appropriate hash bucket.
324
for entry_idx, text_offset, hash_val in just_entries:
325
hash_idx = hash_val & 0xf
327
hash_list[hash_idx] <= entry_idx < hash_list[hash_idx+1])
261
329
def test_first_add_source_doesnt_index_until_make_delta(self):
262
330
di = self._gc_module.DeltaIndex()
263
331
self.assertFalse(di._has_index())
269
337
self.assertTrue(di._has_index())
270
338
self.assertEqual('N\x90/\x1fdiffer from\nagainst other text\n', delta)
340
def test_add_source_max_bytes_to_index(self):
341
di = self._gc_module.DeltaIndex()
342
di._max_bytes_to_index = 3*16
343
di.add_source(_text1, 0) # (77 bytes -1) // 3 = 25 byte stride
344
di.add_source(_text3, 3) # (135 bytes -1) // 3 = 44 byte stride
345
start2 = len(_text1) + 3
346
hash_list, entry_list = di._dump_index()
347
self.assertEqual(16, len(hash_list))
348
self.assertEqual(67, len(entry_list))
349
just_entries = sorted([(text_offset, hash_val)
350
for text_offset, hash_val in entry_list
351
if text_offset != 0 or hash_val != 0])
352
rabin_hash = self._gc_module._rabin_hash
353
self.assertEqual([(25, rabin_hash(_text1[10:26])),
354
(50, rabin_hash(_text1[35:51])),
355
(75, rabin_hash(_text1[60:76])),
356
(start2+44, rabin_hash(_text3[29:45])),
357
(start2+88, rabin_hash(_text3[73:89])),
358
(start2+132, rabin_hash(_text3[117:133])),
272
361
def test_second_add_source_triggers_make_index(self):
273
362
di = self._gc_module.DeltaIndex()
274
363
self.assertFalse(di._has_index())