28
28
import bzrlib.errors as errors
29
29
from bzrlib.weave import Weave, WeaveFormatError, WeaveError, reweave
30
30
from bzrlib.weavefile import write_weave, read_weave
31
from bzrlib.tests import TestCase
31
from bzrlib.selftest import TestCase
32
32
from bzrlib.osutils import sha_string
59
59
self.log(' %r' % k._parents)
60
60
self.log(' %r' % k2._parents)
62
64
self.fail('read/write check failed')
65
class WeaveContains(TestBase):
66
"""Weave __contains__ operator"""
69
self.assertFalse('foo' in k)
70
k.add('foo', [], TEXT_1)
71
self.assertTrue('foo' in k)
74
69
class Easy(TestBase):
758
753
self.doMerge(['aaa', 'bbb'],
759
754
['aaa', 'xxx', 'yyy', 'bbb'],
760
755
['aaa', 'xxx', 'bbb'],
761
['aaa', '<<<<<<<', 'xxx', 'yyy', '=======', 'xxx',
756
['aaa', '<<<<', 'xxx', 'yyy', '====', 'xxx', '>>>>', 'bbb'])
764
758
# really it ought to reduce this to
765
759
# ['aaa', 'xxx', 'yyy', 'bbb']
769
763
self.doMerge(['aaa'],
772
['<<<<<<<', 'xxx', '=======', 'yyy', 'zzz',
766
['<<<<', 'xxx', '====', 'yyy', 'zzz', '>>>>'])
775
768
def testNonClashInsert(self):
776
769
self.doMerge(['aaa'],
779
['<<<<<<<', 'xxx', 'aaa', '=======', 'yyy', 'zzz',
772
['<<<<', 'xxx', 'aaa', '====', 'yyy', 'zzz', '>>>>'])
782
774
self.doMerge(['aaa'],
799
791
self.doMerge(['aaa', 'bbb', 'ccc'],
800
792
['aaa', 'ddd', 'ccc'],
802
['<<<<<<<<', 'aaa', '=======', '>>>>>>>', 'ccc'])
794
['<<<<', 'aaa', '====', '>>>>', 'ccc'])
805
797
class JoinWeavesTests(TestBase):
881
873
eq = self.assertEquals
882
874
eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
883
875
eq(wa.get_text('x1'), 'line from x1\n')
877
def test_reweave_with_empty(self):
879
wr = reweave(self.weave1, wb)
880
eq = self.assertEquals
881
eq(sorted(wr.iter_names()), ['v1', 'v2', 'v3'])
882
eq(wr.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
883
self.weave1.reweave(wb)
884
self.assertEquals(wr, self.weave1)
886
def test_join_with_ghosts_raises_parent_mismatch(self):
887
wa = self.weave1.copy()
889
wb.add('x1', [], ['line from x1\n'])
890
wb.add('v1', [], ['hello\n'])
891
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
892
self.assertRaises(errors.WeaveParentMismatch, wa.join, wb)
894
def test_reweave_with_ghosts(self):
895
"""Join that inserts parents of an existing revision.
897
This can happen when merging from another branch who
898
knows about revisions the destination does not. In
899
this test the second weave knows of an additional parent of
900
v2. Any revisions which are in common still have to have the
902
wa = self.weave1.copy()
904
wb.add('x1', [], ['line from x1\n'])
905
wb.add('v1', [], ['hello\n'])
906
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
908
eq = self.assertEquals
909
eq(sorted(wc.iter_names()), ['v1', 'v2', 'v3', 'x1',])
910
eq(wc.get_text('x1'), 'line from x1\n')
911
eq(wc.get_lines('v2'), ['hello\n', 'world\n'])
912
eq(wc.parent_names('v2'), ['v1', 'x1'])
913
self.weave1.reweave(wb)
914
self.assertEquals(wc, self.weave1)
917
if __name__ == '__main__':
920
sys.exit(unittest.main())