~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_weave.py

  • Committer: Robert Collins
  • Date: 2005-10-27 19:45:18 UTC
  • mfrom: (1185.16.130)
  • Revision ID: robertc@robertcollins.net-20051027194518-58afabc9ab280bb0
MergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
            self.log('         %r' % k._parents)
60
60
            self.log('         %r' % k2._parents)
61
61
            self.log('')
62
 
 
63
 
            
64
62
            self.fail('read/write check failed')
65
 
        
66
 
        
 
63
 
 
64
 
 
65
class WeaveContains(TestBase):
 
66
    """Weave __contains__ operator"""
 
67
    def runTest(self):
 
68
        k = Weave()
 
69
        self.assertFalse('foo' in k)
 
70
        k.add('foo', [], TEXT_1)
 
71
        self.assertTrue('foo' in k)
67
72
 
68
73
 
69
74
class Easy(TestBase):
753
758
        self.doMerge(['aaa', 'bbb'],
754
759
                     ['aaa', 'xxx', 'yyy', 'bbb'],
755
760
                     ['aaa', 'xxx', 'bbb'],
756
 
                     ['aaa', '<<<<', 'xxx', 'yyy', '====', 'xxx', '>>>>', 'bbb'])
 
761
                     ['aaa', '<<<<<<<', 'xxx', 'yyy', '=======', 'xxx', 
 
762
                      '>>>>>>>', 'bbb'])
757
763
 
758
764
        # really it ought to reduce this to 
759
765
        # ['aaa', 'xxx', 'yyy', 'bbb']
763
769
        self.doMerge(['aaa'],
764
770
                     ['xxx'],
765
771
                     ['yyy', 'zzz'],
766
 
                     ['<<<<', 'xxx', '====', 'yyy', 'zzz', '>>>>'])
 
772
                     ['<<<<<<<', 'xxx', '=======', 'yyy', 'zzz', 
 
773
                      '>>>>>>>'])
767
774
 
768
775
    def testNonClashInsert(self):
769
776
        self.doMerge(['aaa'],
770
777
                     ['xxx', 'aaa'],
771
778
                     ['yyy', 'zzz'],
772
 
                     ['<<<<', 'xxx', 'aaa', '====', 'yyy', 'zzz', '>>>>'])
 
779
                     ['<<<<<<<', 'xxx', 'aaa', '=======', 'yyy', 'zzz', 
 
780
                      '>>>>>>>'])
773
781
 
774
782
        self.doMerge(['aaa'],
775
783
                     ['aaa'],
791
799
        self.doMerge(['aaa', 'bbb', 'ccc'],
792
800
                     ['aaa', 'ddd', 'ccc'],
793
801
                     ['aaa', 'ccc'],
794
 
                     ['<<<<', 'aaa', '====', '>>>>', 'ccc'])
 
802
                     ['<<<<<<<<', 'aaa', '=======', '>>>>>>>', 'ccc'])
795
803
 
796
804
 
797
805
class JoinWeavesTests(TestBase):
873
881
        eq = self.assertEquals
874
882
        eq(sorted(wa.iter_names()), ['v1', 'v2', 'v3', 'x1',])
875
883
        eq(wa.get_text('x1'), 'line from x1\n')
876
 
 
877
 
    def test_reweave_with_empty(self):
878
 
        wb = Weave()
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)
885
 
 
886
 
    def test_join_with_ghosts_raises_parent_mismatch(self):
887
 
        wa = self.weave1.copy()
888
 
        wb = Weave()
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)
893
 
 
894
 
    def test_reweave_with_ghosts(self):
895
 
        """Join that inserts parents of an existing revision.
896
 
 
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 
901
 
        same text."""
902
 
        wa = self.weave1.copy()
903
 
        wb = Weave()
904
 
        wb.add('x1', [], ['line from x1\n'])
905
 
        wb.add('v1', [], ['hello\n'])
906
 
        wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
907
 
        wc = reweave(wa, wb)
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)
915
 
 
916
 
 
917
 
if __name__ == '__main__':
918
 
    import sys
919
 
    import unittest
920
 
    sys.exit(unittest.main())
921