/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
1
# Copyright (C) 2005 by Canonical Ltd
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
2
# -*- coding: utf-8 -*-
3
# vim: encoding=utf-8
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
4
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
import os
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
20
from cStringIO import StringIO
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
21
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
22
from bzrlib.tests import BzrTestBase, TestCaseInTempDir
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
23
from bzrlib.log import LogFormatter, show_log, LongLogFormatter, ShortLogFormatter
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
24
from bzrlib.branch import Branch
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
25
from bzrlib.errors import InvalidRevisionNumber
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
26
27
class _LogEntry(object):
28
    # should probably move into bzrlib.log?
29
    pass
30
31
32
class LogCatcher(LogFormatter):
33
    """Pull log messages into list rather than displaying them.
34
35
    For ease of testing we save log messages here rather than actually
36
    formatting them, so that we can precisely check the result without
37
    being too dependent on the exact formatting.
38
39
    We should also test the LogFormatter.
40
    """
41
    def __init__(self):
42
        super(LogCatcher, self).__init__(to_file=None)
43
        self.logs = []
44
        
45
        
46
    def show(self, revno, rev, delta):
47
        le = _LogEntry()
48
        le.revno = revno
49
        le.rev = rev
50
        le.delta = delta
51
        self.logs.append(le)
52
53
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
54
class SimpleLogTest(TestCaseInTempDir):
1102 by Martin Pool
- merge test refactoring from robertc
55
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
56
    def checkDelta(self, delta, **kw):
57
        """Check the filenames touched by a delta are as expected."""
58
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
59
            expected = kw.get(n, [])
60
61
            # tests are written with unix paths; fix them up for windows
1185.31.34 by John Arbash Meinel
Removing instances of os.sep
62
            #if os.sep != '/':
63
            #    expected = [x.replace('/', os.sep) for x in expected]
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
64
65
            # strip out only the path components
66
            got = [x[0] for x in getattr(delta, n)]
67
            self.assertEquals(expected, got)
68
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
69
    def test_cur_revno(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
70
        b = Branch(u'.', init=True)
1092.3.4 by Robert Collins
update symlink branch to integration
71
72
        lf = LogCatcher()
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
73
        b.working_tree().commit('empty commit')
1092.3.4 by Robert Collins
update symlink branch to integration
74
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
75
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
76
                          start_revision=2, end_revision=1) 
77
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
78
                          start_revision=1, end_revision=2) 
79
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
80
                          start_revision=0, end_revision=2) 
81
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
82
                          start_revision=1, end_revision=0) 
83
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
84
                          start_revision=-1, end_revision=1) 
85
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
86
                          start_revision=1, end_revision=-1) 
87
88
    def test_cur_revno(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
89
        b = Branch.initialize(u'.')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
90
91
        lf = LogCatcher()
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
92
        b.working_tree().commit('empty commit')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
93
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
94
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
95
                          start_revision=2, end_revision=1) 
96
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
97
                          start_revision=1, end_revision=2) 
98
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
99
                          start_revision=0, end_revision=2) 
100
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
101
                          start_revision=1, end_revision=0) 
102
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
103
                          start_revision=-1, end_revision=1) 
104
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
105
                          start_revision=1, end_revision=-1) 
106
1102 by Martin Pool
- merge test refactoring from robertc
107
    def test_simple_log(self):
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
108
        eq = self.assertEquals
109
        
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
110
        b = Branch.initialize(u'.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
111
112
        lf = LogCatcher()
113
        show_log(b, lf)
114
        # no entries yet
115
        eq(lf.logs, [])
116
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
117
        b.working_tree().commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
118
        lf = LogCatcher()
119
        show_log(b, lf, verbose=True)
120
        eq(len(lf.logs), 1)
121
        eq(lf.logs[0].revno, 1)
122
        eq(lf.logs[0].rev.message, 'empty commit')
123
        d = lf.logs[0].delta
124
        self.log('log delta: %r' % d)
125
        self.checkDelta(d)
126
127
        self.build_tree(['hello'])
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
128
        b.working_tree().add('hello')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
129
        b.working_tree().commit('add one file')
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
130
131
        lf = StringIO()
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
132
        # log using regular thing
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
133
        show_log(b, LongLogFormatter(lf))
134
        lf.seek(0)
135
        for l in lf.readlines():
136
            self.log(l)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
137
138
        # get log as data structure
139
        lf = LogCatcher()
140
        show_log(b, lf, verbose=True)
141
        eq(len(lf.logs), 2)
142
        self.log('log entries:')
143
        for logentry in lf.logs:
144
            self.log('%4d %s' % (logentry.revno, logentry.rev.message))
145
        
146
        # first one is most recent
147
        logentry = lf.logs[0]
148
        eq(logentry.revno, 2)
149
        eq(logentry.rev.message, 'add one file')
150
        d = logentry.delta
151
        self.log('log 2 delta: %r' % d)
152
        # self.checkDelta(d, added=['hello'])
153
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
154
        # commit a log message with control characters
155
        msg = "All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
156
        self.log("original commit message: %r", msg)
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
157
        b.working_tree().commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
158
        lf = LogCatcher()
159
        show_log(b, lf, verbose=True)
160
        committed_msg = lf.logs[0].rev.message
161
        self.log("escaped commit message: %r", committed_msg)
162
        self.assert_(msg != committed_msg)
163
        self.assert_(len(committed_msg) > len(msg))
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
164
165
        # Check that log message with only XML-valid characters isn't
166
        # escaped.  As ElementTree apparently does some kind of
167
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
168
        # included in the test commit message, even though they are
169
        # valid XML 1.0 characters.
170
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
171
        self.log("original commit message: %r", msg)
1185.33.32 by Martin Pool
[merge] fix \t in commit messages
172
        b.working_tree().commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
173
        lf = LogCatcher()
174
        show_log(b, lf, verbose=True)
175
        committed_msg = lf.logs[0].rev.message
176
        self.log("escaped commit message: %r", committed_msg)
177
        self.assert_(msg == committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
178
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
179
    def test_trailing_newlines(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
180
        b = Branch.initialize(u'.')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
181
        b.nick='test'
182
        wt = b.working_tree()
183
        open('a', 'wb').write('hello moto\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
184
        wt.add('a')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
185
        wt.commit('simple log message', rev_id='a1'
186
                , timestamp=1132586655.459960938, timezone=-6*3600
187
                , committer='Joe Foo <joe@foo.com>')
188
        open('b', 'wb').write('goodbye\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
189
        wt.add('b')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
190
        wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
191
                , timestamp=1132586842.411175966, timezone=-6*3600
192
                , committer='Joe Foo <joe@foo.com>')
193
194
        open('c', 'wb').write('just another manic monday\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
195
        wt.add('c')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
196
        wt.commit('single line with trailing newline\n', rev_id='a3'
197
                , timestamp=1132587176.835228920, timezone=-6*3600
198
                , committer = 'Joe Foo <joe@foo.com>')
199
200
        sio = StringIO()
201
        lf = ShortLogFormatter(to_file=sio)
202
        show_log(b, lf)
203
        self.assertEquals(sio.getvalue(), """\
204
    3 Joe Foo\t2005-11-21
205
      single line with trailing newline
206
207
    2 Joe Foo\t2005-11-21
208
      multiline
209
      log
210
      message
211
212
    1 Joe Foo\t2005-11-21
213
      simple log message
214
215
""")
216
217
        sio = StringIO()
218
        lf = LongLogFormatter(to_file=sio)
219
        show_log(b, lf)
220
        self.assertEquals(sio.getvalue(), """\
221
------------------------------------------------------------
222
revno: 3
223
committer: Joe Foo <joe@foo.com>
224
branch nick: test
225
timestamp: Mon 2005-11-21 09:32:56 -0600
226
message:
227
  single line with trailing newline
228
------------------------------------------------------------
229
revno: 2
230
committer: Joe Foo <joe@foo.com>
231
branch nick: test
232
timestamp: Mon 2005-11-21 09:27:22 -0600
233
message:
234
  multiline
235
  log
236
  message
237
------------------------------------------------------------
238
revno: 1
239
committer: Joe Foo <joe@foo.com>
240
branch nick: test
241
timestamp: Mon 2005-11-21 09:24:15 -0600
242
message:
243
  simple log message
244
""")
245
        
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
246
    def test_verbose_log(self):
247
        """Verbose log includes changed files
248
        
249
        bug #4676
250
        """
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
251
        b = Branch.initialize(u'.')
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
252
        self.build_tree(['a'])
253
        wt = b.working_tree()
1185.33.45 by Martin Pool
[merge] refactoring of branch vs working tree, etc (robertc)
254
        wt.add('a')
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
255
        # XXX: why does a longer nick show up?
256
        b.nick = 'test_verbose_log'
257
        wt.commit(message='add a', 
258
                  timestamp=1132711707, 
259
                  timezone=36000,
260
                  committer='Lorem Ipsum <test@example.com>')
261
        logfile = file('out.tmp', 'w+')
262
        formatter = LongLogFormatter(to_file=logfile)
263
        show_log(b, formatter, verbose=True)
264
        logfile.flush()
265
        logfile.seek(0)
266
        log_contents = logfile.read()
267
        self.assertEqualDiff(log_contents, '''\
268
------------------------------------------------------------
269
revno: 1
270
committer: Lorem Ipsum <test@example.com>
271
branch nick: test_verbose_log
272
timestamp: Wed 2005-11-23 12:08:27 +1000
273
message:
274
  add a
275
added:
276
  a
277
''')
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
278