/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for Annotators."""
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
4454.3.77 by John Arbash Meinel
Add support for compatibility with old '_break_annotation_tie' function.
20
    annotate,
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
21
    errors,
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
22
    revision,
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
23
    tests,
24
    )
25
6670.4.1 by Jelmer Vernooij
Update imports.
26
from ..bzr import (
27
    knit,
28
    )
29
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
30
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
31
def load_tests(loader, standard_tests, pattern):
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
32
    """Parameterize tests for all versions of groupcompress."""
4913.3.1 by John Arbash Meinel
Implement a permute_for_extension helper.
33
    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
34
        'breezy._annotator_py', 'breezy._annotator_pyx')
4913.3.3 by John Arbash Meinel
Typo in test__annotator. Now 'selftest --list' matches as expected
35
    return suite
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
36
37
38
class TestAnnotator(tests.TestCaseWithMemoryTransport):
39
40
    module = None # Set by load_tests
41
7018.2.1 by Martin
Fix _annotator module tests for Python 3
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')
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
48
4454.3.66 by John Arbash Meinel
Implement no-graph support for the Python version.
49
    def make_no_graph_texts(self):
50
        factory = knit.make_pack_factory(False, False, 2)
51
        self.vf = factory(self.get_transport())
52
        self.ann = self.module.Annotator(self.vf)
7018.2.1 by Martin
Fix _annotator module tests for Python 3
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'])
4454.3.66 by John Arbash Meinel
Implement no-graph support for the Python version.
55
4454.3.2 by John Arbash Meinel
Start moving bits into helper functions. Add tests for multiple revs.
56
    def make_simple_text(self):
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
57
        # TODO: all we really need is a VersionedFile instance, we'd like to
58
        #       avoid creating all the intermediate stuff
59
        factory = knit.make_pack_factory(True, True, 2)
60
        self.vf = factory(self.get_transport())
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
61
        # This assumes nothing special happens during __init__, which may be
62
        # valid
63
        self.ann = self.module.Annotator(self.vf)
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
64
        #  A    'simple|content|'
65
        #  |
66
        #  B    'simple|new content|'
7018.2.1 by Martin
Fix _annotator module tests for Python 3
67
        self.vf.add_lines(self.fa_key, [], [b'simple\n', b'content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
68
        self.vf.add_lines(self.fb_key, [self.fa_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
69
                          [b'simple\n', b'new content\n'])
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
70
71
    def make_merge_text(self):
72
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
73
        #  A    'simple|content|'
74
        #  |\
75
        #  B |  'simple|new content|'
76
        #  | |
77
        #  | C  'simple|from c|content|'
78
        #  |/
79
        #  D    'simple|from c|new content|introduced in merge|'
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
80
        self.vf.add_lines(self.fc_key, [self.fa_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
81
                          [b'simple\n', b'from c\n', b'content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
82
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
83
                          [b'simple\n', b'from c\n', b'new content\n',
84
                           b'introduced in merge\n'])
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
85
86
    def make_common_merge_text(self):
87
        """Both sides of the merge will have introduced a line."""
88
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
89
        #  A    'simple|content|'
90
        #  |\
91
        #  B |  'simple|new content|'
92
        #  | |
93
        #  | C  'simple|new content|'
94
        #  |/
95
        #  D    'simple|new content|'
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
96
        self.vf.add_lines(self.fc_key, [self.fa_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
97
                          [b'simple\n', b'new content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
98
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
99
                          [b'simple\n', b'new content\n'])
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
100
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
101
    def make_many_way_common_merge_text(self):
102
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
103
        #  A-.    'simple|content|'
104
        #  |\ \
105
        #  B | |  'simple|new content|'
106
        #  | | |
107
        #  | C |  'simple|new content|'
108
        #  |/  |
109
        #  D   |  'simple|new content|'
110
        #  |   |
111
        #  |   E  'simple|new content|'
112
        #  |  /
113
        #  F-'    'simple|new content|'
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
114
        self.vf.add_lines(self.fc_key, [self.fa_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
115
                          [b'simple\n', b'new content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
116
        self.vf.add_lines(self.fd_key, [self.fb_key, self.fc_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
117
                          [b'simple\n', b'new content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
118
        self.vf.add_lines(self.fe_key, [self.fa_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
119
                          [b'simple\n', b'new content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
120
        self.vf.add_lines(self.ff_key, [self.fd_key, self.fe_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
121
                          [b'simple\n', b'new content\n'])
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
122
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
123
    def make_merge_and_restored_text(self):
124
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
125
        #  A    'simple|content|'
126
        #  |\
127
        #  B |  'simple|new content|'
128
        #  | |
129
        #  C |  'simple|content|' # reverted to A
130
        #   \|
131
        #    D  'simple|content|'
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
132
        # c reverts back to 'a' for the new content line
133
        self.vf.add_lines(self.fc_key, [self.fb_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
134
                          [b'simple\n', b'content\n'])
4454.3.27 by John Arbash Meinel
Simplify the test__annotator tests by avoiding having a real repository.
135
        # d merges 'a' and 'c', to find both claim last modified
136
        self.vf.add_lines(self.fd_key, [self.fa_key, self.fc_key],
7018.2.1 by Martin
Fix _annotator module tests for Python 3
137
                          [b'simple\n', b'content\n'])
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
138
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
139
    def assertAnnotateEqual(self, expected_annotation, key, exp_text=None):
140
        annotation, lines = self.ann.annotate(key)
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
141
        self.assertEqual(expected_annotation, annotation)
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
142
        if exp_text is None:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
143
            record = next(self.vf.get_record_stream([key], 'unordered', True))
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
144
            exp_text = record.get_bytes_as('fulltext')
7018.2.1 by Martin
Fix _annotator module tests for Python 3
145
        self.assertEqualDiff(exp_text, b''.join(lines))
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
146
147
    def test_annotate_missing(self):
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
148
        self.make_simple_text()
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
149
        self.assertRaises(errors.RevisionNotPresent,
7018.2.1 by Martin
Fix _annotator module tests for Python 3
150
                          self.ann.annotate, (b'not', b'present'))
4454.3.1 by John Arbash Meinel
Initial api for Annotator.
151
152
    def test_annotate_simple(self):
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
153
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
154
        self.assertAnnotateEqual([(self.fa_key,)]*2, self.fa_key)
155
        self.assertAnnotateEqual([(self.fa_key,), (self.fb_key,)], self.fb_key)
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
156
157
    def test_annotate_merge_text(self):
158
        self.make_merge_text()
159
        self.assertAnnotateEqual([(self.fa_key,), (self.fc_key,),
160
                                  (self.fb_key,), (self.fd_key,)],
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
161
                                 self.fd_key)
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
162
163
    def test_annotate_common_merge_text(self):
164
        self.make_common_merge_text()
165
        self.assertAnnotateEqual([(self.fa_key,), (self.fb_key, self.fc_key)],
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
166
                                 self.fd_key)
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
167
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
168
    def test_annotate_many_way_common_merge_text(self):
169
        self.make_many_way_common_merge_text()
170
        self.assertAnnotateEqual([(self.fa_key,),
171
                                  (self.fb_key, self.fc_key, self.fe_key)],
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
172
                                 self.ff_key)
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
173
4454.3.4 by John Arbash Meinel
New work on how to resolve conflict lines.
174
    def test_annotate_merge_and_restored(self):
175
        self.make_merge_and_restored_text()
176
        self.assertAnnotateEqual([(self.fa_key,), (self.fa_key, self.fc_key)],
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
177
                                 self.fd_key)
4454.3.10 by John Arbash Meinel
Start working on 'annotate_flat' which conforms to the original spec.
178
179
    def test_annotate_flat_simple(self):
180
        self.make_simple_text()
7018.2.1 by Martin
Fix _annotator module tests for Python 3
181
        self.assertEqual([(self.fa_key, b'simple\n'),
182
                          (self.fa_key, b'content\n'),
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
183
                         ], self.ann.annotate_flat(self.fa_key))
7018.2.1 by Martin
Fix _annotator module tests for Python 3
184
        self.assertEqual([(self.fa_key, b'simple\n'),
185
                          (self.fb_key, b'new content\n'),
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
186
                         ], self.ann.annotate_flat(self.fb_key))
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
187
188
    def test_annotate_flat_merge_and_restored_text(self):
189
        self.make_merge_and_restored_text()
190
        # fc is a simple dominator of fa
7018.2.1 by Martin
Fix _annotator module tests for Python 3
191
        self.assertEqual([(self.fa_key, b'simple\n'),
192
                          (self.fc_key, b'content\n'),
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
193
                         ], self.ann.annotate_flat(self.fd_key))
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
194
195
    def test_annotate_common_merge_text(self):
196
        self.make_common_merge_text()
197
        # there is no common point, so we just pick the lexicographical lowest
6973.13.2 by Jelmer Vernooij
Fix some more tests.
198
        # and b'b-id' comes before b'c-id'
7018.2.1 by Martin
Fix _annotator module tests for Python 3
199
        self.assertEqual([(self.fa_key, b'simple\n'),
200
                          (self.fb_key, b'new content\n'),
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
201
                         ], self.ann.annotate_flat(self.fd_key))
4454.3.12 by John Arbash Meinel
Finish fleshing out the ability to determine a revision after conflicts.
202
203
    def test_annotate_many_way_common_merge_text(self):
204
        self.make_many_way_common_merge_text()
7018.2.1 by Martin
Fix _annotator module tests for Python 3
205
        self.assertEqual([(self.fa_key, b'simple\n'),
206
                         (self.fb_key, b'new content\n')],
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
207
                         self.ann.annotate_flat(self.ff_key))
208
4454.3.77 by John Arbash Meinel
Add support for compatibility with old '_break_annotation_tie' function.
209
    def test_annotate_flat_respects_break_ann_tie(self):
7018.2.1 by Martin
Fix _annotator module tests for Python 3
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)
4454.3.77 by John Arbash Meinel
Add support for compatibility with old '_break_annotation_tie' function.
233
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
234
    def test_needed_keys_simple(self):
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
235
        self.make_simple_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
236
        keys, ann_keys = self.ann._get_needed_keys(self.fb_key)
4454.3.18 by John Arbash Meinel
Start tracking the number of children that need a given text.
237
        self.assertEqual([self.fa_key, self.fb_key], sorted(keys))
238
        self.assertEqual({self.fa_key: 1, self.fb_key: 1},
239
                         self.ann._num_needed_children)
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
240
        self.assertEqual(set(), ann_keys)
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
241
242
    def test_needed_keys_many(self):
243
        self.make_many_way_common_merge_text()
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
244
        keys, ann_keys = self.ann._get_needed_keys(self.ff_key)
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
245
        self.assertEqual([self.fa_key, self.fb_key, self.fc_key,
246
                          self.fd_key, self.fe_key, self.ff_key,
247
                         ], sorted(keys))
248
        self.assertEqual({self.fa_key: 3,
249
                          self.fb_key: 1,
250
                          self.fc_key: 1,
251
                          self.fd_key: 1,
252
                          self.fe_key: 1,
253
                          self.ff_key: 1,
254
                         }, self.ann._num_needed_children)
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
255
        self.assertEqual(set(), ann_keys)
256
257
    def test_needed_keys_with_special_text(self):
258
        self.make_many_way_common_merge_text()
7018.2.1 by Martin
Fix _annotator module tests for Python 3
259
        spec_key = (b'f-id', revision.CURRENT_REVISION)
260
        spec_text = b'simple\nnew content\nlocally modified\n'
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
261
        self.ann.add_special_text(spec_key, [self.fd_key, self.fe_key],
262
                                  spec_text)
263
        keys, ann_keys = self.ann._get_needed_keys(spec_key)
264
        self.assertEqual([self.fa_key, self.fb_key, self.fc_key,
265
                          self.fd_key, self.fe_key,
266
                         ], sorted(keys))
267
        self.assertEqual([spec_key], sorted(ann_keys))
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
268
4454.3.62 by John Arbash Meinel
Add a test that shows when parent texts, etc, are present, we don't request again.
269
    def test_needed_keys_with_parent_texts(self):
270
        self.make_many_way_common_merge_text()
271
        # If 'D' and 'E' are already annotated, we don't need to extract all
272
        # the texts
273
        #  D   |  'simple|new content|'
274
        #  |   |
275
        #  |   E  'simple|new content|'
276
        #  |  /
277
        #  F-'    'simple|new content|'
278
        self.ann._parent_map[self.fd_key] = (self.fb_key, self.fc_key)
7018.2.1 by Martin
Fix _annotator module tests for Python 3
279
        self.ann._text_cache[self.fd_key] = [b'simple\n', b'new content\n']
4454.3.62 by John Arbash Meinel
Add a test that shows when parent texts, etc, are present, we don't request again.
280
        self.ann._annotations_cache[self.fd_key] = [
281
            (self.fa_key,),
282
            (self.fb_key, self.fc_key),
283
            ]
284
        self.ann._parent_map[self.fe_key] = (self.fa_key,)
7018.2.1 by Martin
Fix _annotator module tests for Python 3
285
        self.ann._text_cache[self.fe_key] = [b'simple\n', b'new content\n']
4454.3.62 by John Arbash Meinel
Add a test that shows when parent texts, etc, are present, we don't request again.
286
        self.ann._annotations_cache[self.fe_key] = [
287
            (self.fa_key,),
288
            (self.fe_key,),
289
            ]
290
        keys, ann_keys = self.ann._get_needed_keys(self.ff_key)
291
        self.assertEqual([self.ff_key], sorted(keys))
292
        self.assertEqual({self.fd_key: 1,
293
                          self.fe_key: 1,
294
                          self.ff_key: 1,
295
                         }, self.ann._num_needed_children)
296
        self.assertEqual([], sorted(ann_keys))
297
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
298
    def test_record_annotation_removes_texts(self):
299
        self.make_many_way_common_merge_text()
300
        # Populate the caches
301
        for x in self.ann._get_needed_texts(self.ff_key):
302
            continue
303
        self.assertEqual({self.fa_key: 3,
304
                          self.fb_key: 1,
305
                          self.fc_key: 1,
306
                          self.fd_key: 1,
307
                          self.fe_key: 1,
308
                          self.ff_key: 1,
309
                         }, self.ann._num_needed_children)
310
        self.assertEqual([self.fa_key, self.fb_key, self.fc_key,
311
                          self.fd_key, self.fe_key, self.ff_key,
312
                         ], sorted(self.ann._text_cache.keys()))
4454.3.22 by John Arbash Meinel
Need to record the other annotations before we can record this,
313
        self.ann._record_annotation(self.fa_key, [], [])
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
314
        self.ann._record_annotation(self.fb_key, [self.fa_key], [])
315
        self.assertEqual({self.fa_key: 2,
316
                          self.fb_key: 1,
317
                          self.fc_key: 1,
318
                          self.fd_key: 1,
319
                          self.fe_key: 1,
320
                          self.ff_key: 1,
321
                         }, self.ann._num_needed_children)
322
        self.assertTrue(self.fa_key in self.ann._text_cache)
4454.3.21 by John Arbash Meinel
Assert that entries in the annotation cache also get cleaned up.
323
        self.assertTrue(self.fa_key in self.ann._annotations_cache)
4454.3.22 by John Arbash Meinel
Need to record the other annotations before we can record this,
324
        self.ann._record_annotation(self.fc_key, [self.fa_key], [])
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
325
        self.ann._record_annotation(self.fd_key, [self.fb_key, self.fc_key], [])
4454.3.22 by John Arbash Meinel
Need to record the other annotations before we can record this,
326
        self.assertEqual({self.fa_key: 1,
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
327
                          self.fb_key: 0,
328
                          self.fc_key: 0,
329
                          self.fd_key: 1,
330
                          self.fe_key: 1,
331
                          self.ff_key: 1,
332
                         }, self.ann._num_needed_children)
333
        self.assertTrue(self.fa_key in self.ann._text_cache)
4454.3.21 by John Arbash Meinel
Assert that entries in the annotation cache also get cleaned up.
334
        self.assertTrue(self.fa_key in self.ann._annotations_cache)
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
335
        self.assertFalse(self.fb_key in self.ann._text_cache)
4454.3.22 by John Arbash Meinel
Need to record the other annotations before we can record this,
336
        self.assertFalse(self.fb_key in self.ann._annotations_cache)
4454.3.19 by John Arbash Meinel
Have _record_annotation start to remove texts when they are no longer needed.
337
        self.assertFalse(self.fc_key in self.ann._text_cache)
4454.3.22 by John Arbash Meinel
Need to record the other annotations before we can record this,
338
        self.assertFalse(self.fc_key in self.ann._annotations_cache)
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
339
340
    def test_annotate_special_text(self):
341
        # Things like WT and PreviewTree want to annotate an arbitrary text
342
        # ('current:') so we need a way to add that to the group of files to be
343
        # annotated.
344
        self.make_many_way_common_merge_text()
345
        #  A-.    'simple|content|'
346
        #  |\ \
347
        #  B | |  'simple|new content|'
348
        #  | | |
349
        #  | C |  'simple|new content|'
350
        #  |/  |
351
        #  D   |  'simple|new content|'
352
        #  |   |
353
        #  |   E  'simple|new content|'
354
        #  |  /
355
        #  SPEC   'simple|new content|locally modified|'
7018.2.1 by Martin
Fix _annotator module tests for Python 3
356
        spec_key = (b'f-id', revision.CURRENT_REVISION)
357
        spec_text = b'simple\nnew content\nlocally modified\n'
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
358
        self.ann.add_special_text(spec_key, [self.fd_key, self.fe_key],
359
                                  spec_text)
360
        self.assertAnnotateEqual([(self.fa_key,),
361
                                  (self.fb_key, self.fc_key, self.fe_key),
4454.3.66 by John Arbash Meinel
Implement no-graph support for the Python version.
362
                                  (spec_key,),
4454.3.61 by John Arbash Meinel
Start implementing an Annotator.add_special_text functionality.
363
                                 ], spec_key,
364
                                 exp_text=spec_text)
4454.3.66 by John Arbash Meinel
Implement no-graph support for the Python version.
365
366
    def test_no_graph(self):
367
        self.make_no_graph_texts()
368
        self.assertAnnotateEqual([(self.fa_key,),
369
                                  (self.fa_key,),
370
                                 ], self.fa_key)
371
        self.assertAnnotateEqual([(self.fb_key,),
372
                                  (self.fb_key,),
373
                                 ], self.fb_key)