~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import log
21
 
from bzrlib.tests import TestCaseWithTransport
 
21
from bzrlib.tests import TestCase, TestCaseWithTransport
22
22
from bzrlib.log import (show_log,
23
23
                        get_view_revisions,
24
24
                        LogRevision,
28
28
                        LineLogFormatter)
29
29
from bzrlib.branch import Branch
30
30
from bzrlib.errors import InvalidRevisionNumber
 
31
from bzrlib.revision import Revision
31
32
 
32
33
 
33
34
class LogCatcher(LogFormatter):
103
104
 
104
105
        self.build_tree(['hello'])
105
106
        wt.add('hello')
106
 
        wt.commit('add one file')
 
107
        wt.commit('add one file',
 
108
                  committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
 
109
                            u'<test@example.com>')
107
110
 
108
 
        lf = StringIO()
 
111
        lf = self.make_utf8_encoded_stringio()
109
112
        # log using regular thing
110
113
        show_log(b, LongLogFormatter(lf))
111
114
        lf.seek(0)
198
201
    b.nick='test'
199
202
    open('a', 'wb').write('hello moto\n')
200
203
    wt.add('a')
201
 
    wt.commit('simple log message', rev_id='a1'
202
 
            , timestamp=1132586655.459960938, timezone=-6*3600
203
 
            , committer='Joe Foo <joe@foo.com>')
 
204
    wt.commit('simple log message', rev_id='a1',
 
205
              timestamp=1132586655.459960938, timezone=-6*3600,
 
206
              committer='Joe Foo <joe@foo.com>')
204
207
    open('b', 'wb').write('goodbye\n')
205
208
    wt.add('b')
206
 
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
207
 
            , timestamp=1132586842.411175966, timezone=-6*3600
208
 
            , committer='Joe Foo <joe@foo.com>')
 
209
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
 
210
              timestamp=1132586842.411175966, timezone=-6*3600,
 
211
              committer='Joe Foo <joe@foo.com>',
 
212
              author='Joe Bar <joe@bar.com>')
209
213
 
210
214
    open('c', 'wb').write('just another manic monday\n')
211
215
    wt.add('c')
212
 
    wt.commit('single line with trailing newline\n', rev_id='a3'
213
 
            , timestamp=1132587176.835228920, timezone=-6*3600
214
 
            , committer = 'Joe Foo <joe@foo.com>')
 
216
    wt.commit('single line with trailing newline\n', rev_id='a3',
 
217
              timestamp=1132587176.835228920, timezone=-6*3600,
 
218
              committer = 'Joe Foo <joe@foo.com>')
215
219
    return b
216
220
 
217
221
 
220
224
    def test_trailing_newlines(self):
221
225
        wt = self.make_branch_and_tree('.')
222
226
        b = make_commits_with_trailing_newlines(wt)
223
 
        sio = StringIO()
 
227
        sio = self.make_utf8_encoded_stringio()
224
228
        lf = ShortLogFormatter(to_file=sio)
225
229
        show_log(b, lf)
226
230
        self.assertEquals(sio.getvalue(), """\
227
231
    3 Joe Foo\t2005-11-21
228
232
      single line with trailing newline
229
233
 
230
 
    2 Joe Foo\t2005-11-21
 
234
    2 Joe Bar\t2005-11-21
231
235
      multiline
232
236
      log
233
237
      message
242
246
 
243
247
    def normalize_log(self,log):
244
248
        """Replaces the variable lines of logs with fixed lines"""
 
249
        author = 'author: Dolor Sit <test@example.com>'
245
250
        committer = 'committer: Lorem Ipsum <test@example.com>'
246
251
        lines = log.splitlines(True)
247
252
        for idx,line in enumerate(lines):
248
253
            stripped_line = line.lstrip()
249
254
            indent = ' ' * (len(line) - len(stripped_line))
250
 
            if stripped_line.startswith('committer:'):
 
255
            if stripped_line.startswith('author:'):
 
256
                lines[idx] = indent + author + '\n'
 
257
            elif stripped_line.startswith('committer:'):
251
258
                lines[idx] = indent + committer + '\n'
252
 
            if stripped_line.startswith('timestamp:'):
 
259
            elif stripped_line.startswith('timestamp:'):
253
260
                lines[idx] = indent + 'timestamp: Just now\n'
254
261
        return ''.join(lines)
255
262
 
301
308
        self.run_bzr('merge ../child')
302
309
        wt.commit('merge branch 1')
303
310
        b = wt.branch
304
 
        sio = StringIO()
 
311
        sio = self.make_utf8_encoded_stringio()
305
312
        lf = LongLogFormatter(to_file=sio)
306
313
        show_log(b, lf, verbose=True)
307
314
        log = self.normalize_log(sio.getvalue())
357
364
        self.run_bzr('merge ../child')
358
365
        wt.commit('merge branch 1')
359
366
        b = wt.branch
360
 
        sio = StringIO()
 
367
        sio = self.make_utf8_encoded_stringio()
361
368
        lf = LongLogFormatter(to_file=sio)
362
369
        show_log(b, lf, verbose=True)
363
370
        log = self.normalize_log(sio.getvalue())
399
406
    def test_trailing_newlines(self):
400
407
        wt = self.make_branch_and_tree('.')
401
408
        b = make_commits_with_trailing_newlines(wt)
402
 
        sio = StringIO()
 
409
        sio = self.make_utf8_encoded_stringio()
403
410
        lf = LongLogFormatter(to_file=sio)
404
411
        show_log(b, lf)
405
412
        self.assertEqualDiff(sio.getvalue(), """\
412
419
  single line with trailing newline
413
420
------------------------------------------------------------
414
421
revno: 2
 
422
author: Joe Bar <joe@bar.com>
415
423
committer: Joe Foo <joe@foo.com>
416
424
branch nick: test
417
425
timestamp: Mon 2005-11-21 09:27:22 -0600
448
456
        self.assertEqualDiff(sio.getvalue(), '''\
449
457
------------------------------------------------------------
450
458
revno: 1
451
 
committer: Lorem Ipsum <test@example.com>
452
459
author: John Doe <jdoe@example.com>
 
460
committer: Lorem Ipsum <test@example.com>
453
461
branch nick: test_author_log
454
462
timestamp: Wed 2005-11-23 12:08:27 +1000
455
463
message:
498
506
            wt.commit('rev-2', rev_id='rev-2b',
499
507
                      timestamp=1132586800, timezone=36000,
500
508
                      committer='Joe Foo <joe@foo.com>')
501
 
            logfile = StringIO()
 
509
            logfile = self.make_utf8_encoded_stringio()
502
510
            formatter = ShortLogFormatter(to_file=logfile)
503
511
            show_log(wt.branch, formatter)
504
512
            logfile.flush()
516
524
    def test_trailing_newlines(self):
517
525
        wt = self.make_branch_and_tree('.')
518
526
        b = make_commits_with_trailing_newlines(wt)
519
 
        sio = StringIO()
 
527
        sio = self.make_utf8_encoded_stringio()
520
528
        lf = LineLogFormatter(to_file=sio)
521
529
        show_log(b, lf)
522
530
        self.assertEqualDiff(sio.getvalue(), """\
523
531
3: Joe Foo 2005-11-21 single line with trailing newline
524
 
2: Joe Foo 2005-11-21 multiline
 
532
2: Joe Bar 2005-11-21 multiline
525
533
1: Joe Foo 2005-11-21 simple log message
526
534
""")
527
535
 
785
793
        self.build_tree(['tree_a/foo'])
786
794
        tree.add('foo')
787
795
        tree.commit('bar', rev_id='bar-id')
788
 
        s = StringIO()
 
796
        s = self.make_utf8_encoded_stringio()
789
797
        log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
790
798
        self.assertContainsRe(s.getvalue(), 'bar')
791
799
        self.assertNotContainsRe(s.getvalue(), 'foo')
 
800
 
 
801
 
 
802
class TestLogFormatter(TestCase):
 
803
 
 
804
    def test_short_committer(self):
 
805
        rev = Revision('a-id')
 
806
        rev.committer = 'John Doe <jdoe@example.com>'
 
807
        lf = LogFormatter(None)
 
808
        self.assertEqual('John Doe', lf.short_committer(rev))
 
809
 
 
810
    def test_short_author(self):
 
811
        rev = Revision('a-id')
 
812
        rev.committer = 'John Doe <jdoe@example.com>'
 
813
        lf = LogFormatter(None)
 
814
        self.assertEqual('John Doe', lf.short_author(rev))
 
815
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
 
816
        self.assertEqual('John Smith', lf.short_author(rev))