~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
 
150
150
def get_diamond_vf(f, trailing_eol=True, left_only=False):
151
151
    """Get a diamond graph to exercise deltas and merges.
152
 
    
 
152
 
153
153
    :param trailing_eol: If True end the last line with \n.
154
154
    """
155
155
    parents = {
181
181
 
182
182
    This creates a 5-node graph in files. If files supports 2-length keys two
183
183
    graphs are made to exercise the support for multiple ids.
184
 
    
 
184
 
185
185
    :param trailing_eol: If True end the last line with \n.
186
186
    :param key_length: The length of keys in files. Currently supports length 1
187
187
        and 2 keys.
257
257
            self.assertEquals(f.get_lines('r1'), ['b\n', 'c\n'])
258
258
            self.assertEqual(2, len(f))
259
259
            self.assertEqual(2, f.num_versions())
260
 
    
 
260
 
261
261
            self.assertRaises(RevisionNotPresent,
262
262
                f.add_lines, 'r2', ['foo'], [])
263
263
            self.assertRaises(RevisionAlreadyPresent,
302
302
        verify_file(f)
303
303
 
304
304
    def test_add_unicode_content(self):
305
 
        # unicode content is not permitted in versioned files. 
 
305
        # unicode content is not permitted in versioned files.
306
306
        # versioned files version sequences of bytes only.
307
307
        vf = self.get_file()
308
308
        self.assertRaises(errors.BzrBadParameterUnicode,
331
331
    def test_inline_newline_throws(self):
332
332
        # \r characters are not permitted in lines being added
333
333
        vf = self.get_file()
334
 
        self.assertRaises(errors.BzrBadParameterContainsNewline, 
 
334
        self.assertRaises(errors.BzrBadParameterContainsNewline,
335
335
            vf.add_lines, 'a', [], ['a\n\n'])
336
336
        self.assertRaises(
337
337
            (errors.BzrBadParameterContainsNewline, NotImplementedError),
536
536
        f.add_lines('noeolbase', [], ['line'])
537
537
        # noeol preceeding its leftmost parent in the output:
538
538
        # this is done by making it a merge of two parents with no common
539
 
        # anestry: noeolbase and noeol with the 
 
539
        # anestry: noeolbase and noeol with the
540
540
        # later-inserted parent the leftmost.
541
541
        f.add_lines('eolbeforefirstparent', ['noeolbase', 'noeol'], ['line'])
542
542
        # two identical eol texts
623
623
        self._transaction = 'after'
624
624
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
625
625
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
626
 
        
 
626
 
627
627
    def test_copy_to(self):
628
628
        f = self.get_file()
629
629
        f.add_lines('0', [], ['a\n'])
702
702
 
703
703
    def test_iter_lines_added_or_present_in_versions(self):
704
704
        # test that we get at least an equalset of the lines added by
705
 
        # versions in the weave 
 
705
        # versions in the weave
706
706
        # the ordering here is to make a tree so that dumb searches have
707
707
        # more changes to muck up.
708
708
 
749
749
        self.assertTrue(lines[('child\n', 'child')] > 0)
750
750
        self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
751
751
        # we dont care if we got more than that.
752
 
        
 
752
 
753
753
        # test all lines
754
754
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
755
755
                                          ('Walking content.', 1, 5),
832
832
                          'base',
833
833
                          [],
834
834
                          [])
835
 
    
 
835
 
836
836
    def test_get_sha1s(self):
837
837
        # check the sha1 data is available
838
838
        vf = self.get_file()
848
848
            'b': '3f786850e387550fdab836ed7e6dc881de23001b',
849
849
            },
850
850
            vf.get_sha1s(['a', 'c', 'b']))
851
 
        
 
851
 
852
852
 
853
853
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
854
854
 
861
861
            get_scope=self.get_transaction)
862
862
        w.add_lines('v1', [], ['hello\n'])
863
863
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
864
 
        
 
864
 
865
865
        # We are going to invasively corrupt the text
866
866
        # Make sure the internals of weave are the same
867
867
        self.assertEqual([('{', 0)
871
871
                        , 'there\n'
872
872
                        , ('}', None)
873
873
                        ], w._weave)
874
 
        
 
874
 
875
875
        self.assertEqual(['f572d396fae9206628714fb2ce00f72e94f2258f'
876
876
                        , '90f265c6e75f1c8f9ab76dcf85528352c5f215ef'
877
877
                        ], w._sha1s)
878
878
        w.check()
879
 
        
 
879
 
880
880
        # Corrupted
881
881
        w._weave[4] = 'There\n'
882
882
        return w
886
886
        # Corrected
887
887
        w._weave[4] = 'there\n'
888
888
        self.assertEqual('hello\nthere\n', w.get_text('v2'))
889
 
        
 
889
 
890
890
        #Invalid checksum, first digit changed
891
891
        w._sha1s[1] =  'f0f265c6e75f1c8f9ab76dcf85528352c5f215ef'
892
892
        return w
1001
1001
 
1002
1002
        def addcrlf(x):
1003
1003
            return x + '\n'
1004
 
        
 
1004
 
1005
1005
        w = self.get_file()
1006
1006
        w.add_lines('text0', [], map(addcrlf, base))
1007
1007
        w.add_lines('text1', ['text0'], map(addcrlf, a))
1023
1023
 
1024
1024
        mp = map(addcrlf, mp)
1025
1025
        self.assertEqual(mt.readlines(), mp)
1026
 
        
1027
 
        
 
1026
 
 
1027
 
1028
1028
    def testOneInsert(self):
1029
1029
        self.doMerge([],
1030
1030
                     ['aa'],
1048
1048
                     ['aaa', 'xxx', 'yyy', 'bbb'],
1049
1049
                     ['aaa', 'xxx', 'bbb'], self.overlappedInsertExpected)
1050
1050
 
1051
 
        # really it ought to reduce this to 
 
1051
        # really it ought to reduce this to
1052
1052
        # ['aaa', 'xxx', 'yyy', 'bbb']
1053
1053
 
1054
1054
 
1056
1056
        self.doMerge(['aaa'],
1057
1057
                     ['xxx'],
1058
1058
                     ['yyy', 'zzz'],
1059
 
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz', 
 
1059
                     ['<<<<<<< ', 'xxx', '=======', 'yyy', 'zzz',
1060
1060
                      '>>>>>>> '])
1061
1061
 
1062
1062
    def testNonClashInsert1(self):
1063
1063
        self.doMerge(['aaa'],
1064
1064
                     ['xxx', 'aaa'],
1065
1065
                     ['yyy', 'zzz'],
1066
 
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz', 
 
1066
                     ['<<<<<<< ', 'xxx', 'aaa', '=======', 'yyy', 'zzz',
1067
1067
                      '>>>>>>> '])
1068
1068
 
1069
1069
    def testNonClashInsert2(self):
1083
1083
        #######################################
1084
1084
        # skippd, not working yet
1085
1085
        return
1086
 
        
 
1086
 
1087
1087
        self.doMerge(['aaa', 'bbb', 'ccc'],
1088
1088
                     ['aaa', 'ddd', 'ccc'],
1089
1089
                     ['aaa', 'ccc'],
1132
1132
    def test_deletion_overlap(self):
1133
1133
        """Delete overlapping regions with no other conflict.
1134
1134
 
1135
 
        Arguably it'd be better to treat these as agreement, rather than 
 
1135
        Arguably it'd be better to treat these as agreement, rather than
1136
1136
        conflict, but for now conflict is safer.
1137
1137
        """
1138
1138
        base = """\
1154
1154
            """
1155
1155
        result = """\
1156
1156
            start context
1157
 
<<<<<<< 
 
1157
<<<<<<<
1158
1158
            int a() {}
1159
1159
=======
1160
1160
            int c() {}
1161
 
>>>>>>> 
 
1161
>>>>>>>
1162
1162
            end context
1163
1163
            """
1164
1164
        self._test_merge_from_strings(base, a, b, result)
1190
1190
 
1191
1191
    def test_sync_on_deletion(self):
1192
1192
        """Specific case of merge where we can synchronize incorrectly.
1193
 
        
 
1193
 
1194
1194
        A previous version of the weave merge concluded that the two versions
1195
1195
        agreed on deleting line 2, and this could be a synchronization point.
1196
 
        Line 1 was then considered in isolation, and thought to be deleted on 
 
1196
        Line 1 was then considered in isolation, and thought to be deleted on
1197
1197
        both sides.
1198
1198
 
1199
1199
        It's better to consider the whole thing as a disagreement region.
1218
1218
            """
1219
1219
        result = """\
1220
1220
            start context
1221
 
<<<<<<< 
 
1221
<<<<<<<
1222
1222
            base line 1
1223
1223
            a's replacement line 2
1224
1224
=======
1225
1225
            b replaces
1226
1226
            both lines
1227
 
>>>>>>> 
 
1227
>>>>>>>
1228
1228
            end context
1229
1229
            """
1230
1230
        self._test_merge_from_strings(base, a, b, result)
1241
1241
        write_weave(w, tmpf)
1242
1242
        self.log(tmpf.getvalue())
1243
1243
 
1244
 
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======', 
 
1244
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======',
1245
1245
                                'xxx', '>>>>>>> ', 'bbb']
1246
1246
 
1247
1247
 
1357
1357
 
1358
1358
    def test_unannotated_to_fulltext(self):
1359
1359
        """Test adapting unannotated knits to full texts.
1360
 
        
 
1360
 
1361
1361
        This is used for -> weaves, and for -> annotated knits.
1362
1362
        """
1363
1363
        # we need a full text, and a delta
1376
1376
 
1377
1377
    def test_unannotated_to_fulltext_no_eol(self):
1378
1378
        """Test adapting unannotated knits to full texts.
1379
 
        
 
1379
 
1380
1380
        This is used for -> weaves, and for -> annotated knits.
1381
1381
        """
1382
1382
        # we need a full text, and a delta
1817
1817
            keys[4]: '9ef09dfa9d86780bdec9219a22560c6ece8e0ef1',
1818
1818
            },
1819
1819
            files.get_sha1s(keys))
1820
 
        
 
1820
 
1821
1821
    def test_insert_record_stream_empty(self):
1822
1822
        """Inserting an empty record stream should work."""
1823
1823
        files = self.get_versionedfiles()
2039
2039
        self.assertTrue(
2040
2040
            lines[('otherchild\n', self.get_simple_key('otherchild'))] > 0)
2041
2041
        # we dont care if we got more than that.
2042
 
        
 
2042
 
2043
2043
        # test all lines
2044
2044
        lines = iter_with_keys(files.keys(),
2045
2045
            [('Walking content.', 0, 5),
2086
2086
        files.add_lines(self.get_simple_key('noeolbase'), [], ['line'])
2087
2087
        # noeol preceeding its leftmost parent in the output:
2088
2088
        # this is done by making it a merge of two parents with no common
2089
 
        # anestry: noeolbase and noeol with the 
 
2089
        # anestry: noeolbase and noeol with the
2090
2090
        # later-inserted parent the leftmost.
2091
2091
        files.add_lines(self.get_simple_key('eolbeforefirstparent'),
2092
2092
            self.get_parents([self.get_simple_key('noeolbase'),
2178
2178
        TestCase.setUp(self)
2179
2179
        self._lines = {}
2180
2180
        self._parent_map = {}
2181
 
        self.texts = VirtualVersionedFiles(self._get_parent_map, 
 
2181
        self.texts = VirtualVersionedFiles(self._get_parent_map,
2182
2182
                                           self._lines.get)
2183
2183
 
2184
2184
    def test_add_lines(self):
2185
 
        self.assertRaises(NotImplementedError, 
 
2185
        self.assertRaises(NotImplementedError,
2186
2186
                self.texts.add_lines, "foo", [], [])
2187
2187
 
2188
2188
    def test_add_mpdiffs(self):
2189
 
        self.assertRaises(NotImplementedError, 
 
2189
        self.assertRaises(NotImplementedError,
2190
2190
                self.texts.add_mpdiffs, [])
2191
2191
 
2192
2192
    def test_check(self):
2206
2206
 
2207
2207
    def test_get_parent_map(self):
2208
2208
        self._parent_map = {"G": ("A", "B")}
2209
 
        self.assertEquals({("G",): (("A",),("B",))}, 
 
2209
        self.assertEquals({("G",): (("A",),("B",))},
2210
2210
                          self.texts.get_parent_map([("G",), ("L",)]))
2211
2211
 
2212
2212
    def test_get_record_stream(self):