791
791
['aaa', 'ddd', 'ccc'],
793
793
['<<<<', 'aaa', '====', '>>>>', 'ccc'])
796
class JoinWeavesTests(TestBase):
798
super(JoinWeavesTests, self).setUp()
799
self.weave1 = Weave()
800
self.lines1 = ['hello\n']
801
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
802
self.weave1.add('v1', [], self.lines1)
803
self.weave1.add('v2', [0], ['hello\n', 'world\n'])
804
self.weave1.add('v3', [1], self.lines3)
806
def test_join_empty(self):
807
"""Join two empty weaves."""
808
eq = self.assertEqual
812
eq(w1.numversions(), 0)
814
def test_join_empty_to_nonempty(self):
815
"""Join empty weave onto nonempty."""
816
self.weave1.join(Weave())
817
self.assertEqual(len(self.weave1), 3)
819
def test_join_unrelated(self):
820
"""Join two weaves with no history in common."""
822
wb.add('b1', [], ['line from b\n'])
825
eq = self.assertEqual
827
eq(sorted(list(w1.iter_names())),
828
['b1', 'v1', 'v2', 'v3'])
830
def test_join_related(self):
831
wa = self.weave1.copy()
832
wb = self.weave1.copy()
833
wa.add('a1', ['v3'], ['hello\n', 'sweet\n', 'world\n'])
834
wb.add('b1', ['v3'], ['hello\n', 'pale blue\n', 'world\n'])
835
eq = self.assertEquals
840
eq(wa.get_lines('b1'),
841
['hello\n', 'pale blue\n', 'world\n'])
843
def test_join_parent_disagreement(self):
844
"""Cannot join weaves with different parents for a version."""
847
wa.add('v1', [], ['hello\n'])
849
wb.add('v1', ['v0'], ['hello\n'])
850
self.assertRaises(WeaveError,
853
def test_join_text_disagreement(self):
854
"""Cannot join weaves with different texts for a version."""
857
wa.add('v1', [], ['hello\n'])
858
wb.add('v1', [], ['not\n', 'hello\n'])
859
self.assertRaises(WeaveError,
862
def test_join_unordered(self):
863
"""Join weaves where indexes differ.
865
The source weave contains a different version at index 0."""
866
wa = self.weave1.copy()
868
wb.add('x1', [], ['line from x1\n'])
869
wb.add('v1', [], ['hello\n'])
870
wb.add('v2', ['v1'], ['hello\n', 'world\n'])
872
eq = self.assertEquals
873
eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
874
eq(wa.get_text('x1'), 'line from x1\n')
876
def test_join_with_ghosts(self):
877
"""Join that inserts parents of an existing revision.
879
This can happen when merging from another branch who
880
knows about revisions the destination does not. In
881
this test the second weave knows of an additional parent of
882
v2. Any revisions which are in common still have to have the
884
return ###############################
885
wa = self.weave1.copy()
887
wb.add('x1', [], ['line from x1\n'])
888
wb.add('v1', [], ['hello\n'])
889
wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
891
eq = self.assertEquals
892
eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
893
eq(wa.get_text('x1'), 'line from x1\n')
896
797
if __name__ == '__main__':