/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-23 15:29:35 UTC
  • mfrom: (3943.7.7 bzr.code_style_cleanup)
  • mto: This revision was merged to the branch mainline in revision 4033.
  • Revision ID: john@arbash-meinel.com-20090223152935-oel9m92mwcc6nb4h
Merge the removal of all trailing whitespace, and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
 
159
159
def get_diamond_vf(f, trailing_eol=True, left_only=False):
160
160
    """Get a diamond graph to exercise deltas and merges.
161
 
    
 
161
 
162
162
    :param trailing_eol: If True end the last line with \n.
163
163
    """
164
164
    parents = {
190
190
 
191
191
    This creates a 5-node graph in files. If files supports 2-length keys two
192
192
    graphs are made to exercise the support for multiple ids.
193
 
    
 
193
 
194
194
    :param trailing_eol: If True end the last line with \n.
195
195
    :param key_length: The length of keys in files. Currently supports length 1
196
196
        and 2 keys.
266
266
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
267
267
            self.assertEqual(2, len(f))
268
268
            self.assertEqual(2, f.num_versions())
269
 
    
 
269
 
270
270
            self.assertRaises(RevisionNotPresent,
271
271
                f.add_lines, 'r2', ['foo'], [])
272
272
            self.assertRaises(RevisionAlreadyPresent,
311
311
        verify_file(f)
312
312
 
313
313
    def test_add_unicode_content(self):
314
 
        # unicode content is not permitted in versioned files. 
 
314
        # unicode content is not permitted in versioned files.
315
315
        # versioned files version sequences of bytes only.
316
316
        vf = self.get_file()
317
317
        self.assertRaises(errors.BzrBadParameterUnicode,
340
340
    def test_inline_newline_throws(self):
341
341
        # \r characters are not permitted in lines being added
342
342
        vf = self.get_file()
343
 
        self.assertRaises(errors.BzrBadParameterContainsNewline, 
 
343
        self.assertRaises(errors.BzrBadParameterContainsNewline,
344
344
            vf.add_lines, 'a', [], ['a\n\n'])
345
345
        self.assertRaises(
346
346
            (errors.BzrBadParameterContainsNewline, NotImplementedError),
545
545
        f.add_lines('noeolbase', [], ['line'])
546
546
        # noeol preceeding its leftmost parent in the output:
547
547
        # this is done by making it a merge of two parents with no common
548
 
        # anestry: noeolbase and noeol with the 
 
548
        # anestry: noeolbase and noeol with the
549
549
        # later-inserted parent the leftmost.
550
550
        f.add_lines('eolbeforefirstparent', ['noeolbase', 'noeol'], ['line'])
551
551
        # two identical eol texts
632
632
        self._transaction = 'after'
633
633
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
634
634
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
635
 
        
 
635
 
636
636
    def test_copy_to(self):
637
637
        f = self.get_file()
638
638
        f.add_lines('0', [], ['a\n'])
711
711
 
712
712
    def test_iter_lines_added_or_present_in_versions(self):
713
713
        # test that we get at least an equalset of the lines added by
714
 
        # versions in the weave 
 
714
        # versions in the weave
715
715
        # the ordering here is to make a tree so that dumb searches have
716
716
        # more changes to muck up.
717
717
 
758
758
        self.assertTrue(lines[('child\n', 'child')] > 0)
759
759
        self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
760
760
        # we dont care if we got more than that.
761
 
        
 
761
 
762
762
        # test all lines
763
763
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
764
764
                                          ('Walking content.', 1, 5),
841
841
                          'base',
842
842
                          [],
843
843
                          [])
844
 
    
 
844
 
845
845
    def test_get_sha1s(self):
846
846
        # check the sha1 data is available
847
847
        vf = self.get_file()
857
857
            'b': '3f786850e387550fdab836ed7e6dc881de23001b',
858
858
            },
859
859
            vf.get_sha1s(['a', 'c', 'b']))
860
 
        
 
860
 
861
861
 
862
862
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
863
863
 
870
870
            get_scope=self.get_transaction)
871
871
        w.add_lines('v1', [], ['hello\n'])
872
872
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
873
 
        
 
873
 
874
874
        # We are going to invasively corrupt the text
875
875
        # Make sure the internals of weave are the same
876
876
        self.assertEqual([('{', 0)
880
880
                        , 'there\n'
881
881
                        , ('}', None)
882
882
                        ], w._weave)
883
 
        
 
883
 
884
884
        self.assertEqual(['f572d396fae9206628714fb2ce00f72e94f2258f'
885
885
                        , '90f265c6e75f1c8f9ab76dcf85528352c5f215ef'
886
886
                        ], w._sha1s)
887
887
        w.check()
888
 
        
 
888
 
889
889
        # Corrupted
890
890
        w._weave[4] = 'There\n'
891
891
        return w
895
895
        # Corrected
896
896
        w._weave[4] = 'there\n'
897
897
        self.assertEqual('hello\nthere\n', w.get_text('v2'))
898
 
        
 
898
 
899
899
        #Invalid checksum, first digit changed
900
900
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
901
901
        return w
1010
1010
 
1011
1011
        def addcrlf(x):
1012
1012
            return x + '\n'
1013
 
        
 
1013
 
1014
1014
        w = self.get_file()
1015
1015
        w.add_lines('text0', [], map(addcrlf, base))
1016
1016
        w.add_lines('text1', ['text0'], map(addcrlf, a))
1032
1032
 
1033
1033
        mp = map(addcrlf, mp)
1034
1034
        self.assertEqual(mt.readlines(), mp)
1035
 
        
1036
 
        
 
1035
 
 
1036
 
1037
1037
    def testOneInsert(self):
1038
1038
        self.doMerge([],
1039
1039
                     ['aa'],
1057
1057
                     ['aaa', 'xxx', 'yyy', 'bbb'],
1058
1058
                     ['aaa', 'xxx', 'bbb'], self.overlappedInsertExpected)
1059
1059
 
1060
 
        # really it ought to reduce this to 
 
1060
        # really it ought to reduce this to
1061
1061
        # ['aaa', 'xxx', 'yyy', 'bbb']
1062
1062
 
1063
1063
 
1065
1065
        self.doMerge(['aaa'],
1066
1066
                     ['xxx'],
1067
1067
                     ['yyy', 'zzz'],
1068
 
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz', 
 
1068
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz',
1069
1069
                      '>>>>>>> '])
1070
1070
 
1071
1071
    def testNonClashInsert1(self):
1072
1072
        self.doMerge(['aaa'],
1073
1073
                     ['xxx', 'aaa'],
1074
1074
                     ['yyy', 'zzz'],
1075
 
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz', 
 
1075
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz',
1076
1076
                      '>>>>>>> '])
1077
1077
 
1078
1078
    def testNonClashInsert2(self):
1092
1092
        #######################################
1093
1093
        # skippd, not working yet
1094
1094
        return
1095
 
        
 
1095
 
1096
1096
        self.doMerge(['aaa', 'bbb', 'ccc'],
1097
1097
                     ['aaa', 'ddd', 'ccc'],
1098
1098
                     ['aaa', 'ccc'],
1141
1141
    def test_deletion_overlap(self):
1142
1142
        """Delete overlapping regions with no other conflict.
1143
1143
 
1144
 
        Arguably it'd be better to treat these as agreement, rather than 
 
1144
        Arguably it'd be better to treat these as agreement, rather than
1145
1145
        conflict, but for now conflict is safer.
1146
1146
        """
1147
1147
        base = """\
1163
1163
            """
1164
1164
        result = """\
1165
1165
            start context
1166
 
<<<<<<< 
 
1166
<<<<<<<\x20
1167
1167
            int a() {}
1168
1168
=======
1169
1169
            int c() {}
1170
 
>>>>>>> 
 
1170
>>>>>>>\x20
1171
1171
            end context
1172
1172
            """
1173
1173
        self._test_merge_from_strings(base, a, b, result)
1199
1199
 
1200
1200
    def test_sync_on_deletion(self):
1201
1201
        """Specific case of merge where we can synchronize incorrectly.
1202
 
        
 
1202
 
1203
1203
        A previous version of the weave merge concluded that the two versions
1204
1204
        agreed on deleting line 2, and this could be a synchronization point.
1205
 
        Line 1 was then considered in isolation, and thought to be deleted on 
 
1205
        Line 1 was then considered in isolation, and thought to be deleted on
1206
1206
        both sides.
1207
1207
 
1208
1208
        It's better to consider the whole thing as a disagreement region.
1227
1227
            """
1228
1228
        result = """\
1229
1229
            start context
1230
 
<<<<<<< 
 
1230
<<<<<<<\x20
1231
1231
            base line 1
1232
1232
            a's replacement line 2
1233
1233
=======
1234
1234
            b replaces
1235
1235
            both lines
1236
 
>>>>>>> 
 
1236
>>>>>>>\x20
1237
1237
            end context
1238
1238
            """
1239
1239
        self._test_merge_from_strings(base, a, b, result)
1250
1250
        write_weave(w, tmpf)
1251
1251
        self.log(tmpf.getvalue())
1252
1252
 
1253
 
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======', 
 
1253
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======',
1254
1254
                                'xxx', '>>>>>>> ', 'bbb']
1255
1255
 
1256
1256
 
1365
1365
 
1366
1366
    def test_unannotated_to_fulltext(self):
1367
1367
        """Test adapting unannotated knits to full texts.
1368
 
        
 
1368
 
1369
1369
        This is used for -> weaves, and for -> annotated knits.
1370
1370
        """
1371
1371
        # we need a full text, and a delta
1384
1384
 
1385
1385
    def test_unannotated_to_fulltext_no_eol(self):
1386
1386
        """Test adapting unannotated knits to full texts.
1387
 
        
 
1387
 
1388
1388
        This is used for -> weaves, and for -> annotated knits.
1389
1389
        """
1390
1390
        # we need a full text, and a delta
1991
1991
            keys[4]: '9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',
1992
1992
            },
1993
1993
            files.get_sha1s(keys))
1994
 
        
 
1994
 
1995
1995
    def test_insert_record_stream_empty(self):
1996
1996
        """Inserting an empty record stream should work."""
1997
1997
        files = self.get_versionedfiles()
2265
2265
        self.assertTrue(
2266
2266
            lines[('otherchild\n', self.get_simple_key('otherchild'))] > 0)
2267
2267
        # we dont care if we got more than that.
2268
 
        
 
2268
 
2269
2269
        # test all lines
2270
2270
        lines = iter_with_keys(files.keys(),
2271
2271
            [('Walking content.', 0, 5),
2312
2312
        files.add_lines(self.get_simple_key('noeolbase'), [], ['line'])
2313
2313
        # noeol preceeding its leftmost parent in the output:
2314
2314
        # this is done by making it a merge of two parents with no common
2315
 
        # anestry: noeolbase and noeol with the 
 
2315
        # anestry: noeolbase and noeol with the
2316
2316
        # later-inserted parent the leftmost.
2317
2317
        files.add_lines(self.get_simple_key('eolbeforefirstparent'),
2318
2318
            self.get_parents([self.get_simple_key('noeolbase'),
2404
2404
        TestCase.setUp(self)
2405
2405
        self._lines = {}
2406
2406
        self._parent_map = {}
2407
 
        self.texts = VirtualVersionedFiles(self._get_parent_map, 
 
2407
        self.texts = VirtualVersionedFiles(self._get_parent_map,
2408
2408
                                           self._lines.get)
2409
2409
 
2410
2410
    def test_add_lines(self):
2411
 
        self.assertRaises(NotImplementedError, 
 
2411
        self.assertRaises(NotImplementedError,
2412
2412
                self.texts.add_lines, "foo", [], [])
2413
2413
 
2414
2414
    def test_add_mpdiffs(self):
2415
 
        self.assertRaises(NotImplementedError, 
 
2415
        self.assertRaises(NotImplementedError,
2416
2416
                self.texts.add_mpdiffs, [])
2417
2417
 
2418
2418
    def test_check(self):
2432
2432
 
2433
2433
    def test_get_parent_map(self):
2434
2434
        self._parent_map = {"G": ("A", "B")}
2435
 
        self.assertEquals({("G",): (("A",),("B",))}, 
 
2435
        self.assertEquals({("G",): (("A",),("B",))},
2436
2436
                          self.texts.get_parent_map([("G",), ("L",)]))
2437
2437
 
2438
2438
    def test_get_record_stream(self):