~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Robert Collins
  • Date: 2007-06-04 00:51:54 UTC
  • mfrom: (2504 +trunk)
  • mto: (2507.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2505.
  • Revision ID: robertc@robertcollins.net-20070604005154-yvx2q8jnwiprw6du
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import log
21
21
from bzrlib.tests import BzrTestBase, TestCaseWithTransport
22
 
from bzrlib.log import (show_log, 
23
 
                        get_view_revisions, 
24
 
                        LogFormatter, 
25
 
                        LongLogFormatter, 
26
 
                        ShortLogFormatter, 
 
22
from bzrlib.log import (show_log,
 
23
                        get_view_revisions,
 
24
                        LogRevision,
 
25
                        LogFormatter,
 
26
                        LongLogFormatter,
 
27
                        ShortLogFormatter,
27
28
                        LineLogFormatter)
28
29
from bzrlib.branch import Branch
29
30
from bzrlib.errors import InvalidRevisionNumber
30
31
 
31
32
 
32
 
class _LogEntry(object):
33
 
    # should probably move into bzrlib.log?
34
 
    pass
35
 
 
36
 
 
37
33
class LogCatcher(LogFormatter):
38
34
    """Pull log messages into list rather than displaying them.
39
35
 
43
39
 
44
40
    We should also test the LogFormatter.
45
41
    """
 
42
 
 
43
    supports_delta = True
 
44
 
46
45
    def __init__(self):
47
46
        super(LogCatcher, self).__init__(to_file=None)
48
47
        self.logs = []
49
48
 
50
 
    def show(self, revno, rev, delta):
51
 
        le = _LogEntry()
52
 
        le.revno = revno
53
 
        le.rev = rev
54
 
        le.delta = delta
55
 
        self.logs.append(le)
 
49
    def log_revision(self, revision):
 
50
        self.logs.append(revision)
56
51
 
57
52
 
58
53
class SimpleLogTest(TestCaseWithTransport):
285
280
        log_contents = logfile.read()
286
281
        self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
287
282
 
 
283
    def test_short_log_with_merges(self):
 
284
        wt = self.make_branch_and_memory_tree('.')
 
285
        wt.lock_write()
 
286
        try:
 
287
            wt.add('')
 
288
            wt.commit('rev-1', rev_id='rev-1',
 
289
                      timestamp=1132586655, timezone=36000,
 
290
                      committer='Joe Foo <joe@foo.com>')
 
291
            wt.commit('rev-merged', rev_id='rev-2a',
 
292
                      timestamp=1132586700, timezone=36000,
 
293
                      committer='Joe Foo <joe@foo.com>')
 
294
            wt.set_parent_ids(['rev-1', 'rev-2a'])
 
295
            wt.branch.set_last_revision_info(1, 'rev-1')
 
296
            wt.commit('rev-2', rev_id='rev-2b',
 
297
                      timestamp=1132586800, timezone=36000,
 
298
                      committer='Joe Foo <joe@foo.com>')
 
299
            logfile = StringIO()
 
300
            formatter = ShortLogFormatter(to_file=logfile)
 
301
            show_log(wt.branch, formatter)
 
302
            logfile.flush()
 
303
            self.assertEqualDiff("""\
 
304
    2 Joe Foo\t2005-11-22 [merge]
 
305
      rev-2
 
306
 
 
307
    1 Joe Foo\t2005-11-22
 
308
      rev-1
 
309
 
 
310
""", logfile.getvalue())
 
311
        finally:
 
312
            wt.unlock()
 
313
 
288
314
    def make_tree_with_commits(self):
289
315
        """Create a tree with well-known revision ids"""
290
316
        wt = self.make_branch_and_tree('tree1')