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