~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testlog.py

  • Committer: Martin Pool
  • Date: 2005-07-29 12:29:27 UTC
  • Revision ID: mbp@sourcefrog.net-20050729122927-d51c2cedc14dd5d5
doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib.selftest import BzrTestBase
 
18
from bzrlib.log import LogFormatter, show_log
 
19
from bzrlib.branch import Branch
 
20
 
 
21
class _LogEntry(object):
 
22
    # should probably move into bzrlib.log?
 
23
    pass
 
24
 
 
25
 
 
26
class LogCatcher(LogFormatter):
 
27
    """Pull log messages into list rather than displaying them.
 
28
 
 
29
    For ease of testing we save log messages here rather than actually
 
30
    formatting them, so that we can precisely check the result without
 
31
    being too dependent on the exact formatting.
 
32
 
 
33
    We should also test the LogFormatter.
 
34
    """
 
35
    def __init__(self):
 
36
        super(LogCatcher, self).__init__(to_file=None)
 
37
        self.logs = []
 
38
        
 
39
        
 
40
    def show(self, revno, rev, delta):
 
41
        le = _LogEntry
 
42
        le.revno = revno
 
43
        le.rev = rev
 
44
        le.delta = delta
 
45
        self.logs.append(le)
 
46
 
 
47
 
 
48
class SimpleLogTest(BzrTestBase):
 
49
    def runTest(self):
 
50
        eq = self.assertEquals
 
51
        ass = self.assert_
 
52
        
 
53
        b = Branch('.', init=True)
 
54
 
 
55
        lf = LogCatcher()
 
56
        show_log(b, lf)
 
57
        # no entries yet
 
58
        eq(lf.logs, [])
 
59
 
 
60
 
 
61
        b.commit('empty commit')
 
62
        lf = LogCatcher()
 
63
        show_log(b, lf, verbose=True)
 
64
        eq(len(lf.logs), 1)
 
65
        eq(lf.logs[0].revno, 1)
 
66
        eq(lf.logs[0].rev.message, 'empty commit')
 
67
        d = lf.logs[0].delta
 
68
        self.log('log delta: %r' % d)
 
69
        ass(not d.added)
 
70
        ass(not d.removed)
 
71
        ass(not d.renamed)
 
72
        ass(not d.modified)
 
73
        ass(not d.unchanged)
 
74
 
 
75