1
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
7
5
# the Free Software Foundation; either version 2 of the License, or
8
6
# (at your option) any later version.
10
8
# This program is distributed in the hope that it will be useful,
11
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
11
# GNU General Public License for more details.
15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60
57
expected = kw.get(n, [])
62
59
# tests are written with unix paths; fix them up for windows
64
# expected = [x.replace('/', os.sep) for x in expected]
61
expected = [x.replace('/', os.sep) for x in expected]
66
63
# strip out only the path components
67
64
got = [x[0] for x in getattr(delta, n)]
68
65
self.assertEquals(expected, got)
70
67
def test_cur_revno(self):
71
wt = self.make_branch_and_tree('.')
68
b = Branch('.', init=True)
75
wt.commit('empty commit')
71
b.commit('empty commit')
76
72
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
77
73
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
78
74
start_revision=2, end_revision=1)
158
154
# commit a log message with control characters
159
155
msg = "All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
160
self.log("original commit message: %r", msg)
162
157
lf = LogCatcher()
163
158
show_log(b, lf, verbose=True)
164
159
committed_msg = lf.logs[0].rev.message
165
160
self.log("escaped commit message: %r", committed_msg)
166
161
self.assert_(msg != committed_msg)
167
162
self.assert_(len(committed_msg) > len(msg))
169
# Check that log message with only XML-valid characters isn't
170
# escaped. As ElementTree apparently does some kind of
171
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
172
# included in the test commit message, even though they are
173
# valid XML 1.0 characters.
174
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
175
self.log("original commit message: %r", msg)
178
show_log(b, lf, verbose=True)
179
committed_msg = lf.logs[0].rev.message
180
self.log("escaped commit message: %r", committed_msg)
181
self.assert_(msg == committed_msg)
183
def test_trailing_newlines(self):
184
wt = self.make_branch_and_tree('.')
187
open('a', 'wb').write('hello moto\n')
189
wt.commit('simple log message', rev_id='a1'
190
, timestamp=1132586655.459960938, timezone=-6*3600
191
, committer='Joe Foo <joe@foo.com>')
192
open('b', 'wb').write('goodbye\n')
194
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
195
, timestamp=1132586842.411175966, timezone=-6*3600
196
, committer='Joe Foo <joe@foo.com>')
198
open('c', 'wb').write('just another manic monday\n')
200
wt.commit('single line with trailing newline\n', rev_id='a3'
201
, timestamp=1132587176.835228920, timezone=-6*3600
202
, committer = 'Joe Foo <joe@foo.com>')
205
lf = ShortLogFormatter(to_file=sio)
207
self.assertEquals(sio.getvalue(), """\
208
3 Joe Foo\t2005-11-21
209
single line with trailing newline
211
2 Joe Foo\t2005-11-21
216
1 Joe Foo\t2005-11-21
222
lf = LongLogFormatter(to_file=sio)
224
self.assertEquals(sio.getvalue(), """\
225
------------------------------------------------------------
227
committer: Joe Foo <joe@foo.com>
229
timestamp: Mon 2005-11-21 09:32:56 -0600
231
single line with trailing newline
232
------------------------------------------------------------
234
committer: Joe Foo <joe@foo.com>
236
timestamp: Mon 2005-11-21 09:27:22 -0600
241
------------------------------------------------------------
243
committer: Joe Foo <joe@foo.com>
245
timestamp: Mon 2005-11-21 09:24:15 -0600
250
def test_verbose_log(self):
251
"""Verbose log includes changed files
255
wt = self.make_branch_and_tree('.')
257
self.build_tree(['a'])
259
# XXX: why does a longer nick show up?
260
b.nick = 'test_verbose_log'
261
wt.commit(message='add a',
262
timestamp=1132711707,
264
committer='Lorem Ipsum <test@example.com>')
265
logfile = file('out.tmp', 'w+')
266
formatter = LongLogFormatter(to_file=logfile)
267
show_log(b, formatter, verbose=True)
270
log_contents = logfile.read()
271
self.assertEqualDiff(log_contents, '''\
272
------------------------------------------------------------
274
committer: Lorem Ipsum <test@example.com>
275
branch nick: test_verbose_log
276
timestamp: Wed 2005-11-23 12:08:27 +1000
283
def test_line_log(self):
284
"""Line log should show revno
288
wt = self.make_branch_and_tree('.')
290
self.build_tree(['a'])
292
b.nick = 'test-line-log'
293
wt.commit(message='add a',
294
timestamp=1132711707,
296
committer='Line-Log-Formatter Tester <test@line.log>')
297
logfile = file('out.tmp', 'w+')
298
formatter = LineLogFormatter(to_file=logfile)
299
show_log(b, formatter)
302
log_contents = logfile.read()
303
self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')