/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 breezy/tests/test__annotator.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
    module = None # Set by load_tests
41
41
 
42
 
    fa_key = ('f-id', 'a-id')
43
 
    fb_key = ('f-id', 'b-id')
44
 
    fc_key = ('f-id', 'c-id')
45
 
    fd_key = ('f-id', 'd-id')
46
 
    fe_key = ('f-id', 'e-id')
47
 
    ff_key = ('f-id', 'f-id')
 
42
    fa_key = (b'f-id', b'a-id')
 
43
    fb_key = (b'f-id', b'b-id')
 
44
    fc_key = (b'f-id', b'c-id')
 
45
    fd_key = (b'f-id', b'd-id')
 
46
    fe_key = (b'f-id', b'e-id')
 
47
    ff_key = (b'f-id', b'f-id')
48
48
 
49
49
    def make_no_graph_texts(self):
50
50
        factory = knit.make_pack_factory(False, False, 2)
51
51
        self.vf = factory(self.get_transport())
52
52
        self.ann = self.module.Annotator(self.vf)
53
 
        self.vf.add_lines(self.fa_key, (), ['simple\n', 'content\n'])
54
 
        self.vf.add_lines(self.fb_key, (), ['simple\n', 'new content\n'])
 
53
        self.vf.add_lines(self.fa_key, (), [b'simple\n', b'content\n'])
 
54
        self.vf.add_lines(self.fb_key, (), [b'simple\n', b'new content\n'])
55
55
 
56
56
    def make_simple_text(self):
57
57
        # TODO: all we really need is a VersionedFile instance, we'd like to
64
64
        #  A    'simple|content|'
65
65
        #  |
66
66
        #  B    'simple|new content|'
67
 
        self.vf.add_lines(self.fa_key, [], ['simple\n', 'content\n'])
 
67
        self.vf.add_lines(self.fa_key, [], [b'simple\n', b'content\n'])
68
68
        self.vf.add_lines(self.fb_key, [self.fa_key],
69
 
                          ['simple\n', 'new content\n'])
 
69
                          [b'simple\n', b'new content\n'])
70
70
 
71
71
    def make_merge_text(self):
72
72
        self.make_simple_text()
78
78
        #  |/
79
79
        #  D    'simple|from c|new content|introduced in merge|'
80
80
        self.vf.add_lines(self.fc_key, [self.fa_key],
81
 
                          ['simple\n', 'from c\n', 'content\n'])
 
81
                          [b'simple\n', b'from c\n', b'content\n'])
82
82
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
83
 
                          ['simple\n', 'from c\n', 'new content\n',
84
 
                           'introduced in merge\n'])
 
83
                          [b'simple\n', b'from c\n', b'new content\n',
 
84
                           b'introduced in merge\n'])
85
85
 
86
86
    def make_common_merge_text(self):
87
87
        """Both sides of the merge will have introduced a line."""
94
94
        #  |/
95
95
        #  D    'simple|new content|'
96
96
        self.vf.add_lines(self.fc_key, [self.fa_key],
97
 
                          ['simple\n', 'new content\n'])
 
97
                          [b'simple\n', b'new content\n'])
98
98
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
99
 
                          ['simple\n', 'new content\n'])
 
99
                          [b'simple\n', b'new content\n'])
100
100
 
101
101
    def make_many_way_common_merge_text(self):
102
102
        self.make_simple_text()
112
112
        #  |  /
113
113
        #  F-'    'simple|new content|'
114
114
        self.vf.add_lines(self.fc_key, [self.fa_key],
115
 
                          ['simple\n', 'new content\n'])
 
115
                          [b'simple\n', b'new content\n'])
116
116
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
117
 
                          ['simple\n', 'new content\n'])
 
117
                          [b'simple\n', b'new content\n'])
118
118
        self.vf.add_lines(self.fe_key, [self.fa_key],
119
 
                          ['simple\n', 'new content\n'])
 
119
                          [b'simple\n', b'new content\n'])
120
120
        self.vf.add_lines(self.ff_key, [self.fd_key, self.fe_key],
121
 
                          ['simple\n', 'new content\n'])
 
121
                          [b'simple\n', b'new content\n'])
122
122
 
123
123
    def make_merge_and_restored_text(self):
124
124
        self.make_simple_text()
131
131
        #    D  'simple|content|'
132
132
        # c reverts back to 'a' for the new content line
133
133
        self.vf.add_lines(self.fc_key, [self.fb_key],
134
 
                          ['simple\n', 'content\n'])
 
134
                          [b'simple\n', b'content\n'])
135
135
        # d merges 'a' and 'c', to find both claim last modified
136
136
        self.vf.add_lines(self.fd_key, [self.fa_key, self.fc_key],
137
 
                          ['simple\n', 'content\n'])
 
137
                          [b'simple\n', b'content\n'])
138
138
 
139
139
    def assertAnnotateEqual(self, expected_annotation, key, exp_text=None):
140
140
        annotation, lines = self.ann.annotate(key)
142
142
        if exp_text is None:
143
143
            record = next(self.vf.get_record_stream([key], 'unordered', True))
144
144
            exp_text = record.get_bytes_as('fulltext')
145
 
        self.assertEqualDiff(exp_text, ''.join(lines))
 
145
        self.assertEqualDiff(exp_text, b''.join(lines))
146
146
 
147
147
    def test_annotate_missing(self):
148
148
        self.make_simple_text()
149
149
        self.assertRaises(errors.RevisionNotPresent,
150
 
                          self.ann.annotate, ('not', 'present'))
 
150
                          self.ann.annotate, (b'not', b'present'))
151
151
 
152
152
    def test_annotate_simple(self):
153
153
        self.make_simple_text()
178
178
 
179
179
    def test_annotate_flat_simple(self):
180
180
        self.make_simple_text()
181
 
        self.assertEqual([(self.fa_key, 'simple\n'),
182
 
                          (self.fa_key, 'content\n'),
 
181
        self.assertEqual([(self.fa_key, b'simple\n'),
 
182
                          (self.fa_key, b'content\n'),
183
183
                         ], self.ann.annotate_flat(self.fa_key))
184
 
        self.assertEqual([(self.fa_key, 'simple\n'),
185
 
                          (self.fb_key, 'new content\n'),
 
184
        self.assertEqual([(self.fa_key, b'simple\n'),
 
185
                          (self.fb_key, b'new content\n'),
186
186
                         ], self.ann.annotate_flat(self.fb_key))
187
187
 
188
188
    def test_annotate_flat_merge_and_restored_text(self):
189
189
        self.make_merge_and_restored_text()
190
190
        # fc is a simple dominator of fa
191
 
        self.assertEqual([(self.fa_key, 'simple\n'),
192
 
                          (self.fc_key, 'content\n'),
 
191
        self.assertEqual([(self.fa_key, b'simple\n'),
 
192
                          (self.fc_key, b'content\n'),
193
193
                         ], self.ann.annotate_flat(self.fd_key))
194
194
 
195
195
    def test_annotate_common_merge_text(self):
196
196
        self.make_common_merge_text()
197
197
        # there is no common point, so we just pick the lexicographical lowest
198
 
        # and 'b-id' comes before 'c-id'
199
 
        self.assertEqual([(self.fa_key, 'simple\n'),
200
 
                          (self.fb_key, 'new content\n'),
 
198
        # and b'b-id' comes before b'c-id'
 
199
        self.assertEqual([(self.fa_key, b'simple\n'),
 
200
                          (self.fb_key, b'new content\n'),
201
201
                         ], self.ann.annotate_flat(self.fd_key))
202
202
 
203
203
    def test_annotate_many_way_common_merge_text(self):
204
204
        self.make_many_way_common_merge_text()
205
 
        self.assertEqual([(self.fa_key, 'simple\n'),
206
 
                         (self.fb_key, 'new content\n')],
 
205
        self.assertEqual([(self.fa_key, b'simple\n'),
 
206
                         (self.fb_key, b'new content\n')],
207
207
                         self.ann.annotate_flat(self.ff_key))
208
208
 
209
209
    def test_annotate_flat_respects_break_ann_tie(self):
210
 
        tiebreaker = annotate._break_annotation_tie
211
 
        try:
212
 
            calls = []
213
 
            def custom_tiebreaker(annotated_lines):
214
 
                self.assertEqual(2, len(annotated_lines))
215
 
                left = annotated_lines[0]
216
 
                self.assertEqual(2, len(left))
217
 
                self.assertEqual('new content\n', left[1])
218
 
                right = annotated_lines[1]
219
 
                self.assertEqual(2, len(right))
220
 
                self.assertEqual('new content\n', right[1])
221
 
                calls.append((left[0], right[0]))
222
 
                # Our custom tiebreaker takes the *largest* value, rather than
223
 
                # the *smallest* value
224
 
                if left[0] < right[0]:
225
 
                    return right
226
 
                else:
227
 
                    return left
228
 
            annotate._break_annotation_tie = custom_tiebreaker
229
 
            self.make_many_way_common_merge_text()
230
 
            self.assertEqual([(self.fa_key, 'simple\n'),
231
 
                             (self.fe_key, 'new content\n')],
232
 
                             self.ann.annotate_flat(self.ff_key))
233
 
            self.assertEqual([(self.fe_key, self.fc_key),
234
 
                              (self.fe_key, self.fb_key)], calls)
235
 
        finally:
236
 
            annotate._break_annotation_tie = tiebreaker
237
 
 
 
210
        seen = set()
 
211
        def custom_tiebreaker(annotated_lines):
 
212
            self.assertEqual(2, len(annotated_lines))
 
213
            left = annotated_lines[0]
 
214
            self.assertEqual(2, len(left))
 
215
            self.assertEqual(b'new content\n', left[1])
 
216
            right = annotated_lines[1]
 
217
            self.assertEqual(2, len(right))
 
218
            self.assertEqual(b'new content\n', right[1])
 
219
            seen.update([left[0], right[0]])
 
220
            # Our custom tiebreaker takes the *largest* value, rather than
 
221
            # the *smallest* value
 
222
            if left[0] < right[0]:
 
223
                return right
 
224
            else:
 
225
                return left
 
226
        self.overrideAttr(annotate, '_break_annotation_tie', custom_tiebreaker)
 
227
        self.make_many_way_common_merge_text()
 
228
        self.assertEqual([(self.fa_key, b'simple\n'),
 
229
                         (self.fe_key, b'new content\n')],
 
230
                         self.ann.annotate_flat(self.ff_key))
 
231
        # Calls happen in set iteration order but should keys should be seen
 
232
        self.assertEqual({self.fb_key, self.fc_key, self.fe_key}, seen)
238
233
 
239
234
    def test_needed_keys_simple(self):
240
235
        self.make_simple_text()
261
256
 
262
257
    def test_needed_keys_with_special_text(self):
263
258
        self.make_many_way_common_merge_text()
264
 
        spec_key = ('f-id', revision.CURRENT_REVISION)
265
 
        spec_text = 'simple\nnew content\nlocally modified\n'
 
259
        spec_key = (b'f-id', revision.CURRENT_REVISION)
 
260
        spec_text = b'simple\nnew content\nlocally modified\n'
266
261
        self.ann.add_special_text(spec_key, [self.fd_key, self.fe_key],
267
262
                                  spec_text)
268
263
        keys, ann_keys = self.ann._get_needed_keys(spec_key)
281
276
        #  |  /
282
277
        #  F-'    'simple|new content|'
283
278
        self.ann._parent_map[self.fd_key] = (self.fb_key, self.fc_key)
284
 
        self.ann._text_cache[self.fd_key] = ['simple\n', 'new content\n']
 
279
        self.ann._text_cache[self.fd_key] = [b'simple\n', b'new content\n']
285
280
        self.ann._annotations_cache[self.fd_key] = [
286
281
            (self.fa_key,),
287
282
            (self.fb_key, self.fc_key),
288
283
            ]
289
284
        self.ann._parent_map[self.fe_key] = (self.fa_key,)
290
 
        self.ann._text_cache[self.fe_key] = ['simple\n', 'new content\n']
 
285
        self.ann._text_cache[self.fe_key] = [b'simple\n', b'new content\n']
291
286
        self.ann._annotations_cache[self.fe_key] = [
292
287
            (self.fa_key,),
293
288
            (self.fe_key,),
358
353
        #  |   E  'simple|new content|'
359
354
        #  |  /
360
355
        #  SPEC   'simple|new content|locally modified|'
361
 
        spec_key = ('f-id', revision.CURRENT_REVISION)
362
 
        spec_text = 'simple\nnew content\nlocally modified\n'
 
356
        spec_key = (b'f-id', revision.CURRENT_REVISION)
 
357
        spec_text = b'simple\nnew content\nlocally modified\n'
363
358
        self.ann.add_special_text(spec_key, [self.fd_key, self.fe_key],
364
359
                                  spec_text)
365
360
        self.assertAnnotateEqual([(self.fa_key,),