~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-11 02:07:30 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071211020730-sdj4kj794dw0628e
make help topics more discoverable

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
 
19
import codecs
19
20
from cStringIO import StringIO
20
21
 
21
22
from bzrlib import (
86
87
e
87
88
""".splitlines(True)
88
89
 
 
90
expected_1 = annotation("""\
 
91
blahblah a
 
92
blahblah b
 
93
blahblah c
 
94
blahblah d
 
95
blahblah e
 
96
""")
 
97
 
89
98
 
90
99
new_2 = """\
91
100
a
140
149
        tree1.commit('merge 2', rev_id='rev-3',
141
150
                     committer='sal@foo.com',
142
151
                     timestamp=1166046003.00, timezone=0)
 
152
        tree1.lock_read()
 
153
        self.addCleanup(tree1.unlock)
143
154
        return tree1, tree2
144
155
 
145
156
    def create_deeply_merged_trees(self):
166
177
        rev-6
167
178
        """
168
179
        tree1, tree2 = self.create_merged_trees()
 
180
        tree1.unlock()
169
181
 
170
182
        tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
171
183
 
193
205
                     timestamp=1166046005.00, timezone=0)
194
206
        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
195
207
        tree1.commit('merge five and six', rev_id='rev-6')
 
208
        tree1.lock_read()
196
209
        return tree1
197
210
 
198
211
    def test_annotate_shows_dotted_revnos(self):
301
314
                             'rev-1_1_1_1_1_1_1 | sixth\n',
302
315
                             sio.getvalue())
303
316
 
 
317
    def test_annotate_unicode_author(self):
 
318
        tree1 = self.make_branch_and_tree('tree1')
 
319
 
 
320
        self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
 
321
        tree1.add(['a'], ['a-id'])
 
322
        tree1.commit('a', rev_id='rev-1',
 
323
                     committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
 
324
                     timestamp=1166046000.00, timezone=0)
 
325
 
 
326
        self.build_tree_contents([('tree1/b', 'bye')])
 
327
        tree1.add(['b'], ['b-id'])
 
328
        tree1.commit('b', rev_id='rev-2',
 
329
                     committer=u'p\xe9rez',
 
330
                     timestamp=1166046000.00, timezone=0)
 
331
 
 
332
        tree1.lock_read()
 
333
        self.addCleanup(tree1.unlock)
 
334
        # this passes if no exception is raised
 
335
        to_file = StringIO()
 
336
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
337
 
 
338
        sio = StringIO()
 
339
        to_file = codecs.getwriter('ascii')(sio)
 
340
        to_file.encoding = 'ascii' # codecs does not set it
 
341
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
342
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
 
343
 
 
344
        # test now with to_file.encoding = None
 
345
        to_file = tests.StringIOWrapper()
 
346
        to_file.encoding = None
 
347
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
348
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
 
349
 
 
350
        # and when it does not exist
 
351
        to_file = StringIO()
 
352
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
353
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
 
354
 
 
355
    def test_annotate_author_or_committer(self):
 
356
        tree1 = self.make_branch_and_tree('tree1')
 
357
 
 
358
        self.build_tree_contents([('tree1/a', 'hello')])
 
359
        tree1.add(['a'], ['a-id'])
 
360
        tree1.commit('a', rev_id='rev-1',
 
361
                     committer='Committer <committer@example.com>',
 
362
                     timestamp=1166046000.00, timezone=0)
 
363
 
 
364
        self.build_tree_contents([('tree1/b', 'bye')])
 
365
        tree1.add(['b'], ['b-id'])
 
366
        tree1.commit('b', rev_id='rev-2',
 
367
                     committer='Committer <committer@example.com>',
 
368
                     author='Author <author@example.com>',
 
369
                     timestamp=1166046000.00, timezone=0)
 
370
 
 
371
        tree1.lock_read()
 
372
        self.addCleanup(tree1.unlock)
 
373
        to_file = StringIO()
 
374
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
375
        self.assertEqual('1   committ | hello\n', to_file.getvalue())
 
376
 
 
377
        to_file = StringIO()
 
378
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
379
        self.assertEqual('2   author@ | bye\n', to_file.getvalue())
 
380
 
304
381
 
305
382
class TestReannotate(tests.TestCase):
306
383
 
307
 
    def annotateEqual(self, expected, parents, newlines, revision_id):
 
384
    def annotateEqual(self, expected, parents, newlines, revision_id,
 
385
                      blocks=None):
308
386
        annotate_list = list(annotate.reannotate(parents, newlines,
309
 
                             revision_id))
 
387
                             revision_id, blocks))
310
388
        self.assertEqual(len(expected), len(annotate_list))
311
389
        for e, a in zip(expected, annotate_list):
312
390
            self.assertEqual(e, a)
316
394
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
317
395
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2, 
318
396
                           'blahblah')
 
397
 
 
398
    def test_reannotate_no_parents(self):
 
399
        self.annotateEqual(expected_1, [], new_1, 'blahblah')
 
400
 
 
401
    def test_reannotate_left_matching_blocks(self):
 
402
        """Ensure that left_matching_blocks has an impact.
 
403
 
 
404
        In this case, the annotation is ambiguous, so the hint isn't actually
 
405
        lying.
 
406
        """
 
407
        parent = [('rev1', 'a\n')]
 
408
        new_text = ['a\n', 'a\n']
 
409
        blocks = [(0, 0, 1), (1, 2, 0)]
 
410
        self.annotateEqual([('rev1', 'a\n'), ('rev2', 'a\n')], [parent],
 
411
                           new_text, 'rev2', blocks)
 
412
        blocks = [(0, 1, 1), (1, 2, 0)]
 
413
        self.annotateEqual([('rev2', 'a\n'), ('rev1', 'a\n')], [parent],
 
414
                           new_text, 'rev2', blocks)