~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-05 05:29:27 UTC
  • mfrom: (1393.1.51)
  • Revision ID: robertc@robertcollins.net-20051005052926-03d3a49e1dbcb670
mergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
791
791
                     ['aaa', 'ddd', 'ccc'],
792
792
                     ['aaa', 'ccc'],
793
793
                     ['<<<<', 'aaa', '====', '>>>>', 'ccc'])
794
 
    
 
794
 
 
795
 
 
796
class JoinWeavesTests(TestBase):
 
797
    def setUp(self):
 
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)
 
805
        
 
806
    def test_join_empty(self):
 
807
        """Join two empty weaves."""
 
808
        eq = self.assertEqual
 
809
        w1 = Weave()
 
810
        w2 = Weave()
 
811
        w1.join(w2)
 
812
        eq(w1.numversions(), 0)
 
813
        
 
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)
 
818
 
 
819
    def test_join_unrelated(self):
 
820
        """Join two weaves with no history in common."""
 
821
        wb = Weave()
 
822
        wb.add('b1', [], ['line from b\n'])
 
823
        w1 = self.weave1
 
824
        w1.join(wb)
 
825
        eq = self.assertEqual
 
826
        eq(len(w1), 4)
 
827
        eq(sorted(list(w1.iter_names())),
 
828
           ['b1', 'v1', 'v2', 'v3'])
 
829
 
 
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
 
836
        eq(len(wa), 4)
 
837
        eq(len(wb), 4)
 
838
        wa.join(wb)
 
839
        eq(len(wa), 5)
 
840
        eq(wa.get_lines('b1'),
 
841
           ['hello\n', 'pale blue\n', 'world\n'])
795
842
 
796
843
 
797
844
if __name__ == '__main__':