1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
33
('python', {'_gc_module': _groupcompress_py}),
35
if compiled_groupcompress_feature.available():
36
gc_module = compiled_groupcompress_feature.module
35
if CompiledGroupCompressFeature.available():
36
from bzrlib import _groupcompress_pyx
37
37
scenarios.append(('C',
38
{'_gc_module': gc_module}))
38
{'_gc_module': _groupcompress_pyx}))
39
39
two_way_scenarios.extend([
40
('CC', {'make_delta': gc_module.make_delta,
41
'apply_delta': gc_module.apply_delta}),
40
('CC', {'make_delta': _groupcompress_pyx.make_delta,
41
'apply_delta': _groupcompress_pyx.apply_delta}),
42
42
('PC', {'make_delta': _groupcompress_py.make_delta,
43
'apply_delta': gc_module.apply_delta}),
44
('CP', {'make_delta': gc_module.make_delta,
43
'apply_delta': _groupcompress_pyx.apply_delta}),
44
('CP', {'make_delta': _groupcompress_pyx.make_delta,
45
45
'apply_delta': _groupcompress_py.apply_delta}),
47
47
to_adapt, result = tests.split_suite_by_condition(
57
compiled_groupcompress_feature = tests.ModuleAvailableFeature(
58
'bzrlib._groupcompress_pyx')
57
class _CompiledGroupCompressFeature(tests.Feature):
61
import bzrlib._groupcompress_pyx
67
def feature_name(self):
68
return 'bzrlib._groupcompress_pyx'
71
CompiledGroupCompressFeature = _CompiledGroupCompressFeature()
251
264
# This test isn't multiplied, because we only have DeltaIndex for the
253
266
# We call this here, because _test_needs_features happens after setUp
254
self.requireFeature(compiled_groupcompress_feature)
255
self._gc_module = compiled_groupcompress_feature.module
267
self.requireFeature(CompiledGroupCompressFeature)
268
from bzrlib import _groupcompress_pyx
269
self._gc_module = _groupcompress_pyx
257
271
def test_repr(self):
258
272
di = self._gc_module.DeltaIndex('test text\n')
259
273
self.assertEqual('DeltaIndex(1, 10)', repr(di))
261
def test_first_add_source_doesnt_index_until_make_delta(self):
262
di = self._gc_module.DeltaIndex()
263
self.assertFalse(di._has_index())
264
di.add_source(_text1, 0)
265
self.assertFalse(di._has_index())
266
# However, asking to make a delta will trigger the index to be
267
# generated, and will generate a proper delta
268
delta = di.make_delta(_text2)
269
self.assertTrue(di._has_index())
270
self.assertEqual('N\x90/\x1fdiffer from\nagainst other text\n', delta)
272
def test_second_add_source_triggers_make_index(self):
273
di = self._gc_module.DeltaIndex()
274
self.assertFalse(di._has_index())
275
di.add_source(_text1, 0)
276
self.assertFalse(di._has_index())
277
di.add_source(_text2, 0)
278
self.assertTrue(di._has_index())
280
275
def test_make_delta(self):
281
276
di = self._gc_module.DeltaIndex(_text1)
282
277
delta = di.make_delta(_text2)