/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1685.1.80 by Wouter van Heyst
more code cleanup
2
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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.
1685.1.80 by Wouter van Heyst
more code cleanup
7
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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.
1685.1.80 by Wouter van Heyst
more code cleanup
12
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
16
17
import os
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
20
    branchbuilder,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
21
    errors,
22
    log,
23
    registry,
24
    revision,
25
    revisionspec,
26
    tests,
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
27
    gpg,
28
    trace,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
31
    BytesIO,
7045.4.13 by Jelmer Vernooij
Some more test fixes.
32
    StringIO,
7029.4.8 by Jelmer Vernooij
Merge trunk.
33
    unichr,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
34
    )
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
35
36
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
37
class TestLogMixin(object):
38
39
    def wt_commit(self, wt, message, **kwargs):
40
        """Use some mostly fixed values for commits to simplify tests.
41
42
        Tests can use this function to get some commit attributes. The time
43
        stamp is incremented at each commit.
44
        """
45
        if getattr(self, 'timestamp', None) is None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
46
            self.timestamp = 1132617600  # Mon 2005-11-22 00:00:00 +0000
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
47
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
48
            self.timestamp += 1  # 1 second between each commit
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
49
        kwargs.setdefault('timestamp', self.timestamp)
7143.15.2 by Jelmer Vernooij
Run autopep8.
50
        kwargs.setdefault('timezone', 0)  # UTC
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
51
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
52
53
        return wt.commit(message, **kwargs)
54
55
56
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
57
58
    def setUp(self):
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
59
        super(TestCaseForLogFormatter, self).setUp()
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
60
        # keep a reference to the "current" custom prop. handler registry
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
61
        self.properties_handler_registry = log.properties_handler_registry
4325.4.3 by Vincent Ladeuil
More cleanups.
62
        # Use a clean registry for log
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
63
        log.properties_handler_registry = registry.Registry()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
64
4325.4.3 by Vincent Ladeuil
More cleanups.
65
        def restore():
66
            log.properties_handler_registry = self.properties_handler_registry
67
        self.addCleanup(restore)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
68
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
69
    def assertFormatterResult(self, result, branch, formatter_class,
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
70
                              formatter_kwargs=None, show_log_kwargs=None):
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
71
        logfile = self.make_utf8_encoded_stringio()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
72
        if formatter_kwargs is None:
73
            formatter_kwargs = {}
74
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
75
        if show_log_kwargs is None:
76
            show_log_kwargs = {}
77
        log.show_log(branch, formatter, **show_log_kwargs)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
78
        self.assertEqualDiff(result, logfile.getvalue())
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
79
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
80
    def make_standard_commit(self, branch_nick, **kwargs):
81
        wt = self.make_branch_and_tree('.')
82
        wt.lock_write()
83
        self.addCleanup(wt.unlock)
84
        self.build_tree(['a'])
85
        wt.add(['a'])
86
        wt.branch.nick = branch_nick
87
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
88
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
89
        self.wt_commit(wt, 'add a', **kwargs)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
90
        return wt
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
91
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
92
    def make_commits_with_trailing_newlines(self, wt):
93
        """Helper method for LogFormatter tests"""
94
        b = wt.branch
95
        b.nick = 'test'
6855.4.1 by Jelmer Vernooij
Yet more bees.
96
        self.build_tree_contents([('a', b'hello moto\n')])
97
        self.wt_commit(wt, 'simple log message', rev_id=b'a1')
98
        self.build_tree_contents([('b', b'goodbye\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
99
        wt.add('b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
100
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id=b'a2')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
101
6855.4.1 by Jelmer Vernooij
Yet more bees.
102
        self.build_tree_contents([('c', b'just another manic monday\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
103
        wt.add('c')
6855.4.1 by Jelmer Vernooij
Yet more bees.
104
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id=b'a3')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
105
        return b
106
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
107
    def _prepare_tree_with_merges(self, with_tags=False):
108
        wt = self.make_branch_and_memory_tree('.')
109
        wt.lock_write()
110
        self.addCleanup(wt.unlock)
111
        wt.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
112
        self.wt_commit(wt, 'rev-1', rev_id=b'rev-1')
113
        self.wt_commit(wt, 'rev-merged', rev_id=b'rev-2a')
6973.10.6 by Jelmer Vernooij
Fix tests.
114
        wt.set_parent_ids([b'rev-1', b'rev-2a'])
115
        wt.branch.set_last_revision_info(1, b'rev-1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
116
        self.wt_commit(wt, 'rev-2', rev_id=b'rev-2b')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
117
        if with_tags:
118
            branch = wt.branch
6973.10.6 by Jelmer Vernooij
Fix tests.
119
            branch.tags.set_tag('v0.2', b'rev-2b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
120
            self.wt_commit(wt, 'rev-3', rev_id=b'rev-3')
6973.10.6 by Jelmer Vernooij
Fix tests.
121
            branch.tags.set_tag('v1.0rc1', b'rev-3')
122
            branch.tags.set_tag('v1.0', b'rev-3')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
123
        return wt
124
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
125
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
126
class LogCatcher(log.LogFormatter):
4325.4.3 by Vincent Ladeuil
More cleanups.
127
    """Pull log messages into a list rather than displaying them.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
128
4325.4.3 by Vincent Ladeuil
More cleanups.
129
    To simplify testing we save logged revisions here rather than actually
4325.4.1 by Vincent Ladeuil
Some cleanups.
130
    formatting anything, so that we can precisely check the result without
4325.4.3 by Vincent Ladeuil
More cleanups.
131
    being dependent on the formatting.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
132
    """
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
133
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
134
    supports_merge_revisions = True
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
135
    supports_delta = True
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
136
    supports_diff = True
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
137
    preferred_levels = 0
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
138
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
139
    def __init__(self, *args, **kwargs):
140
        kwargs.update(dict(to_file=None))
141
        super(LogCatcher, self).__init__(*args, **kwargs)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
142
        self.revisions = []
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
143
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
144
    def log_revision(self, revision):
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
145
        self.revisions.append(revision)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
146
147
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
148
class TestShowLog(tests.TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
149
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
150
    def checkDelta(self, delta, **kw):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
151
        """Check the filenames touched by a delta are as expected.
152
153
        Caller only have to pass in the list of files for each part, all
154
        unspecified parts are considered empty (and checked as such).
155
        """
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
156
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
157
            # By default we expect an empty list
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
158
            expected = kw.get(n, [])
159
            # strip out only the path components
160
            got = [x[0] for x in getattr(delta, n)]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
161
            self.assertEqual(expected, got)
162
163
    def assertInvalidRevisonNumber(self, br, start, end):
164
        lf = LogCatcher()
165
        self.assertRaises(errors.InvalidRevisionNumber,
166
                          log.show_log, br, lf,
167
                          start_revision=start, end_revision=end)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
168
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
169
    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.
170
        wt = self.make_branch_and_tree('.')
171
        b = wt.branch
1092.3.4 by Robert Collins
update symlink branch to integration
172
173
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
174
        wt.commit('empty commit')
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
175
        log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
176
177
        # Since there is a single revision in the branch all the combinations
178
        # below should fail.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
179
        self.assertInvalidRevisonNumber(b, 2, 1)
180
        self.assertInvalidRevisonNumber(b, 1, 2)
181
        self.assertInvalidRevisonNumber(b, 0, 2)
182
        self.assertInvalidRevisonNumber(b, -1, 1)
183
        self.assertInvalidRevisonNumber(b, 1, -1)
6965.1.3 by Jelmer Vernooij
Fix test.
184
        self.assertInvalidRevisonNumber(b, 1, 0)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
185
186
    def test_empty_branch(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
187
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
188
189
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
190
        log.show_log(wt.branch, lf)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
191
        # no entries yet
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
192
        self.assertEqual([], lf.revisions)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
193
194
    def test_empty_commit(self):
195
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
196
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
197
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
198
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
199
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
200
        revs = lf.revisions
201
        self.assertEqual(1, len(revs))
202
        self.assertEqual('1', revs[0].revno)
203
        self.assertEqual('empty commit', revs[0].rev.message)
204
        self.checkDelta(revs[0].delta)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
205
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
206
    def test_simple_commit(self):
207
        wt = self.make_branch_and_tree('.')
208
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
209
        self.build_tree(['hello'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
210
        wt.add('hello')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
211
        wt.commit('add one file',
212
                  committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
213
                            u'<test@example.com>')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
214
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
215
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
216
        self.assertEqual(2, len(lf.revisions))
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
217
        # first one is most recent
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
218
        log_entry = lf.revisions[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
219
        self.assertEqual('2', log_entry.revno)
220
        self.assertEqual('add one file', log_entry.rev.message)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
221
        self.checkDelta(log_entry.delta, added=['hello'])
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
222
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
223
    def test_commit_message_with_control_chars(self):
224
        wt = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
225
        msg = u"All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
226
        msg = msg.replace(u'\r', u'\n')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
227
        wt.commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
228
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
229
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
230
        committed_msg = lf.revisions[0].rev.message
4627.1.1 by Robert Collins
Review feedback per IanC.
231
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
232
            self.assertNotEqual(msg, committed_msg)
233
            self.assertTrue(len(committed_msg) > len(msg))
234
        else:
235
            self.assertEqual(msg, committed_msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
236
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
237
    def test_commit_message_without_control_chars(self):
238
        wt = self.make_branch_and_tree('.')
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
239
        # escaped.  As ElementTree apparently does some kind of
240
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
241
        # included in the test commit message, even though they are
242
        # valid XML 1.0 characters.
243
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
244
        wt.commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
245
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
246
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
247
        committed_msg = lf.revisions[0].rev.message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
248
        self.assertEqual(msg, committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
249
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
250
    def test_deltas_in_merge_revisions(self):
251
        """Check deltas created for both mainline and merge revisions"""
252
        wt = self.make_branch_and_tree('parent')
253
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
254
        wt.add('file1')
255
        wt.add('file2')
256
        wt.commit(message='add file1 and file2')
2581.1.6 by Martin Pool
fix up more run_bzr callers
257
        self.run_bzr('branch parent child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
258
        os.unlink('child/file1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
259
        with open('child/file2', 'wb') as f:
260
            f.write(b'hello\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
261
        self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
7143.15.2 by Jelmer Vernooij
Run autopep8.
262
                      'child'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
263
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
264
        self.run_bzr('merge ../child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
265
        wt.commit('merge child branch')
266
        os.chdir('..')
267
        b = wt.branch
268
        lf = LogCatcher()
269
        lf.supports_merge_revisions = True
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
270
        log.show_log(b, lf, verbose=True)
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
271
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
272
        revs = lf.revisions
273
        self.assertEqual(3, len(revs))
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
274
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
275
        logentry = revs[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
276
        self.assertEqual('2', logentry.revno)
277
        self.assertEqual('merge child branch', logentry.rev.message)
278
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
279
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
280
        logentry = revs[1]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
281
        self.assertEqual('1.1.1', logentry.revno)
282
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
283
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
284
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
285
        logentry = revs[2]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
286
        self.assertEqual('1', logentry.revno)
287
        self.assertEqual('add file1 and file2', logentry.rev.message)
288
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
289
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
290
    def test_bug_842695_log_restricted_to_dir(self):
291
        # Comments here indicate revision numbers in trunk  # VVVVV
292
        trunk = self.make_branch_and_tree('this')
293
        trunk.commit('initial trunk')                       # 1
6833.5.1 by Jelmer Vernooij
Merge lp:~gagern/bzr/bug842695-log-dir.
294
        adder = trunk.controldir.sprout('adder').open_workingtree()
295
        merger = trunk.controldir.sprout('merger').open_workingtree()
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
296
        self.build_tree_contents([
297
            ('adder/dir/',),
6855.4.1 by Jelmer Vernooij
Yet more bees.
298
            ('adder/dir/file', b'foo'),
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
299
            ])
300
        adder.add(['dir', 'dir/file'])
301
        adder.commit('added dir')                           # 1.1.1
302
        trunk.merge_from_branch(adder.branch)
303
        trunk.commit('merged adder into trunk')             # 2
304
        merger.merge_from_branch(trunk.branch)
305
        merger.commit('merged trunk into merger')           # 1.2.1
306
        # Commits are processed in increments of 200 revisions, so
307
        # make sure the two merges into trunk are in different chunks.
7029.4.8 by Jelmer Vernooij
Merge trunk.
308
        for i in range(200):
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
309
            trunk.commit('intermediate commit %d' % i)      # 3-202
310
        trunk.merge_from_branch(merger.branch)
311
        trunk.commit('merged merger into trunk')            # 203
312
        file_id = trunk.path2id('dir')
313
        lf = LogCatcher()
314
        lf.supports_merge_revisions = True
315
        log.show_log(trunk.branch, lf, file_id)
6833.5.1 by Jelmer Vernooij
Merge lp:~gagern/bzr/bug842695-log-dir.
316
        try:
317
            self.assertEqual(['2', '1.1.1'], [r.revno for r in lf.revisions])
318
        except AssertionError:
319
            raise tests.KnownFailure("bug #842695")
320
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
321
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
322
class TestFormatSignatureValidity(tests.TestCaseWithTransport):
6883.11.3 by Jelmer Vernooij
Fix tests.
323
324
    def verify_revision_signature(self, revid, gpg_strategy):
325
        return (gpg.SIGNATURE_VALID,
7143.15.2 by Jelmer Vernooij
Run autopep8.
326
                u'UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>')
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
327
328
    def test_format_signature_validity_utf(self):
329
        """Check that GPG signatures containing UTF-8 names are formatted
330
        correctly."""
331
        wt = self.make_branch_and_tree('.')
332
        revid = wt.commit('empty commit')
333
        repo = wt.branch.repository
334
        # Monkey patch out checking if this rev is actually signed, since we
335
        # can't sign it without a heavier TestCase and LoopbackGPGStrategy
336
        # doesn't care anyways.
6883.11.3 by Jelmer Vernooij
Fix tests.
337
        self.overrideAttr(repo, 'verify_revision_signature',
7143.15.2 by Jelmer Vernooij
Run autopep8.
338
                          self.verify_revision_signature)
6767.1.2 by Jelmer Vernooij
Fix a test.
339
        out = log.format_signature_validity(revid, wt.branch)
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
340
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
341
            u'valid signature from UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>',
342
            out)
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
343
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
344
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
345
class TestShortLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
346
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
347
    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.
348
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
349
        b = self.make_commits_with_trailing_newlines(wt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
350
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
351
    3 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
352
      single line with trailing newline
353
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
354
    2 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
355
      multiline
356
      log
357
      message
358
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
359
    1 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
360
      simple log message
361
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
362
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
                                   b, log.ShortLogFormatter)
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
364
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
365
    def test_short_log_with_merges(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
366
        wt = self._prepare_tree_with_merges()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
367
        self.assertFormatterResult(b"""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
368
    2 Joe Foo\t2005-11-22 [merge]
369
      rev-2
370
371
    1 Joe Foo\t2005-11-22
372
      rev-1
373
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
374
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
375
                                   wt.branch, log.ShortLogFormatter)
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
376
377
    def test_short_log_with_merges_and_advice(self):
378
        wt = self._prepare_tree_with_merges()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
379
        self.assertFormatterResult(b"""\
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
380
    2 Joe Foo\t2005-11-22 [merge]
381
      rev-2
382
383
    1 Joe Foo\t2005-11-22
384
      rev-1
385
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
386
Use --include-merged or -n0 to see merged revisions.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
387
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
388
                                   wt.branch, log.ShortLogFormatter,
389
                                   formatter_kwargs=dict(show_advice=True))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
390
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
391
    def test_short_log_with_merges_and_range(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
392
        wt = self._prepare_tree_with_merges()
6855.4.1 by Jelmer Vernooij
Yet more bees.
393
        self.wt_commit(wt, 'rev-3a', rev_id=b'rev-3a')
6973.10.6 by Jelmer Vernooij
Fix tests.
394
        wt.branch.set_last_revision_info(2, b'rev-2b')
395
        wt.set_parent_ids([b'rev-2b', b'rev-3a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
396
        self.wt_commit(wt, 'rev-3b', rev_id=b'rev-3b')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
397
        self.assertFormatterResult(b"""\
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
398
    3 Joe Foo\t2005-11-22 [merge]
399
      rev-3b
400
401
    2 Joe Foo\t2005-11-22 [merge]
4955.4.19 by Vincent Ladeuil
Less code duplication.
402
      rev-2
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
403
404
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
405
                                   wt.branch, log.ShortLogFormatter,
406
                                   show_log_kwargs=dict(start_revision=2, end_revision=3))
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
407
3946.3.2 by Ian Clatworthy
add tests & NEWS item
408
    def test_short_log_with_tags(self):
409
        wt = self._prepare_tree_with_merges(with_tags=True)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
410
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
411
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
3946.3.2 by Ian Clatworthy
add tests & NEWS item
412
      rev-3
413
414
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
415
      rev-2
416
417
    1 Joe Foo\t2005-11-22
418
      rev-1
419
420
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
421
                                   wt.branch, log.ShortLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
422
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
423
    def test_short_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
424
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
425
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
426
        rev = revspec.in_history(wt.branch)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
427
        self.assertFormatterResult(b"""\
3947.1.10 by Ian Clatworthy
review feedback from vila
428
      1.1.1 Joe Foo\t2005-11-22
429
            rev-merged
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
430
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
431
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
432
                                   wt.branch, log.ShortLogFormatter,
433
                                   show_log_kwargs=dict(start_revision=rev, end_revision=rev))
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
434
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
435
    def test_show_ids(self):
436
        wt = self.make_branch_and_tree('parent')
437
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
438
        wt.add(['f1', 'f2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
439
        self.wt_commit(wt, 'first post', rev_id=b'a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
440
        child_wt = wt.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
441
        self.wt_commit(child_wt, 'branch 1 changes', rev_id=b'b')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
442
        wt.merge_from_branch(child_wt.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
443
        self.wt_commit(wt, 'merge branch 1', rev_id=b'c')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
444
        self.assertFormatterResult(b"""\
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
445
    2 Joe Foo\t2005-11-22 [merge]
446
      revision-id:c
447
      merge branch 1
448
449
          1.1.1 Joe Foo\t2005-11-22
450
                revision-id:b
451
                branch 1 changes
452
453
    1 Joe Foo\t2005-11-22
454
      revision-id:a
455
      first post
456
457
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
458
                                   wt.branch, log.ShortLogFormatter,
459
                                   formatter_kwargs=dict(levels=0, show_ids=True))
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
460
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
461
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
462
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
463
464
    def test_short_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
465
        wt = self._prepare_tree_with_merges()
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
466
        # Note that the 1.1.1 indenting is in fact correct given that
467
        # the revision numbers are right justified within 5 characters
468
        # for mainline revnos and 9 characters for dotted revnos.
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
469
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
470
    2 Joe Foo\t2005-11-22 [merge]
471
      rev-2
472
3947.1.10 by Ian Clatworthy
review feedback from vila
473
          1.1.1 Joe Foo\t2005-11-22
474
                rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
475
476
    1 Joe Foo\t2005-11-22
477
      rev-1
478
479
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
480
                                   wt.branch, log.ShortLogFormatter,
481
                                   formatter_kwargs=dict(levels=0))
3947.1.2 by Ian Clatworthy
formatter tests
482
483
    def test_short_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
484
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
485
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
486
        rev = revspec.in_history(wt.branch)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
487
        self.assertFormatterResult(b"""\
3947.1.10 by Ian Clatworthy
review feedback from vila
488
      1.1.1 Joe Foo\t2005-11-22
489
            rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
490
491
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
492
                                   wt.branch, log.ShortLogFormatter,
493
                                   formatter_kwargs=dict(levels=0),
494
                                   show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
495
496
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
497
class TestLongLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
498
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
499
    def test_verbose_log(self):
500
        """Verbose log includes changed files
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
501
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
502
        bug #4676
503
        """
4857.4.4 by John Arbash Meinel
One more standard-commit
504
        wt = self.make_standard_commit('test_verbose_log', authors=[])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
505
        self.assertFormatterResult(b'''\
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
506
------------------------------------------------------------
507
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
508
committer: Lorem Ipsum <test@example.com>
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
509
branch nick: test_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
510
timestamp: Tue 2005-11-22 00:00:00 +0000
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
511
message:
512
  add a
513
added:
514
  a
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
515
''',
7143.15.2 by Jelmer Vernooij
Run autopep8.
516
                                   wt.branch, log.LongLogFormatter,
517
                                   show_log_kwargs=dict(verbose=True))
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
518
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
519
    def test_merges_are_indented_by_level(self):
520
        wt = self.make_branch_and_tree('parent')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
521
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
522
        child_wt = wt.controldir.sprout('child').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
523
        self.wt_commit(child_wt, 'branch 1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
524
        smallerchild_wt = wt.controldir.sprout(
525
            'smallerchild').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
526
        self.wt_commit(smallerchild_wt, 'branch 2')
527
        child_wt.merge_from_branch(smallerchild_wt.branch)
528
        self.wt_commit(child_wt, 'merge branch 2')
529
        wt.merge_from_branch(child_wt.branch)
530
        self.wt_commit(wt, 'merge branch 1')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
531
        self.assertFormatterResult(b"""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
532
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
533
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
534
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
535
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
536
timestamp: Tue 2005-11-22 00:00:04 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
537
message:
538
  merge branch 1
539
    ------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
540
    revno: 1.1.2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
541
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
542
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
543
    timestamp: Tue 2005-11-22 00:00:03 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
544
    message:
545
      merge branch 2
546
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
547
        revno: 1.2.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
548
        committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
549
        branch nick: smallerchild
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
550
        timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
551
        message:
552
          branch 2
553
    ------------------------------------------------------------
554
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
555
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
556
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
557
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
558
    message:
559
      branch 1
560
------------------------------------------------------------
561
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
562
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
563
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
564
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
565
message:
566
  first post
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
567
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
568
                                   wt.branch, log.LongLogFormatter,
569
                                   formatter_kwargs=dict(levels=0),
570
                                   show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
571
572
    def test_verbose_merge_revisions_contain_deltas(self):
573
        wt = self.make_branch_and_tree('parent')
574
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
575
        wt.add(['f1', 'f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
576
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
577
        child_wt = wt.controldir.sprout('child').open_workingtree()
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
578
        os.unlink('child/f1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
579
        self.build_tree_contents([('child/f2', b'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
580
        self.wt_commit(child_wt, 'removed f1 and modified f2')
581
        wt.merge_from_branch(child_wt.branch)
582
        self.wt_commit(wt, 'merge branch 1')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
583
        self.assertFormatterResult(b"""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
584
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
585
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
586
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
587
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
588
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
589
message:
590
  merge branch 1
591
removed:
592
  f1
593
modified:
594
  f2
595
    ------------------------------------------------------------
596
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
597
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
598
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
599
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
600
    message:
601
      removed f1 and modified f2
602
    removed:
603
      f1
604
    modified:
605
      f2
606
------------------------------------------------------------
607
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
608
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
609
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
610
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
611
message:
612
  first post
613
added:
614
  f1
615
  f2
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
616
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
617
                                   wt.branch, log.LongLogFormatter,
618
                                   formatter_kwargs=dict(levels=0),
619
                                   show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
620
621
    def test_trailing_newlines(self):
622
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
623
        b = self.make_commits_with_trailing_newlines(wt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
624
        self.assertFormatterResult(b"""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
625
------------------------------------------------------------
626
revno: 3
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
627
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
628
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
629
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
630
message:
631
  single line with trailing newline
632
------------------------------------------------------------
633
revno: 2
634
committer: Joe Foo <joe@foo.com>
635
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
636
timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
637
message:
638
  multiline
639
  log
640
  message
641
------------------------------------------------------------
642
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
643
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
644
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
645
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
646
message:
647
  simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
648
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
649
                                   b, log.LongLogFormatter)
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
650
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
651
    def test_author_in_log(self):
652
        """Log includes the author name if it's set in
653
        the revision properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
654
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
655
        wt = self.make_standard_commit('test_author_log',
7143.15.2 by Jelmer Vernooij
Run autopep8.
656
                                       authors=['John Doe <jdoe@example.com>',
657
                                                'Jane Rey <jrey@example.com>'])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
658
        self.assertFormatterResult(b"""\
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
659
------------------------------------------------------------
660
revno: 1
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
661
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
2671.5.4 by Lukáš Lalinsky
Replace the committer with the author in log, the committer is displayed only in the long format and only if it's different from the author.
662
committer: Lorem Ipsum <test@example.com>
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
663
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
664
timestamp: Tue 2005-11-22 00:00:00 +0000
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
665
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
666
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
667
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
668
                                   wt.branch, log.LongLogFormatter)
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
669
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
670
    def test_properties_in_log(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
671
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
672
        handlers.
673
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
674
        wt = self.make_standard_commit('test_properties_in_log')
7143.15.2 by Jelmer Vernooij
Run autopep8.
675
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
676
        def trivial_custom_prop_handler(revision):
7143.15.2 by Jelmer Vernooij
Run autopep8.
677
            return {'test_prop': 'test_value'}
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
678
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
679
        # Cleaned up in setUp()
680
        log.properties_handler_registry.register(
681
            'trivial_custom_prop_handler',
682
            trivial_custom_prop_handler)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
683
        self.assertFormatterResult(b"""\
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
684
------------------------------------------------------------
685
revno: 1
686
test_prop: test_value
687
author: John Doe <jdoe@example.com>
688
committer: Lorem Ipsum <test@example.com>
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
689
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
690
timestamp: Tue 2005-11-22 00:00:00 +0000
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
691
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
692
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
693
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
694
                                   wt.branch, log.LongLogFormatter)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
695
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
696
    def test_properties_in_short_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
697
        """Log includes the custom properties returned by the registered
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
698
        handlers.
699
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
700
        wt = self.make_standard_commit('test_properties_in_short_log')
7143.15.2 by Jelmer Vernooij
Run autopep8.
701
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
702
        def trivial_custom_prop_handler(revision):
7143.15.2 by Jelmer Vernooij
Run autopep8.
703
            return {'test_prop': 'test_value'}
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
704
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
705
        log.properties_handler_registry.register(
706
            'trivial_custom_prop_handler',
707
            trivial_custom_prop_handler)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
708
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
709
    1 John Doe\t2005-11-22
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
710
      test_prop: test_value
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
711
      add a
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
712
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
713
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
714
                                   wt.branch, log.ShortLogFormatter)
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
715
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
716
    def test_error_in_properties_handler(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
717
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
718
        handlers.
719
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
720
        wt = self.make_standard_commit('error_in_properties_handler',
7143.15.2 by Jelmer Vernooij
Run autopep8.
721
                                       revprops={u'first_prop': 'first_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
722
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
723
        formatter = log.LongLogFormatter(to_file=sio)
7143.15.2 by Jelmer Vernooij
Run autopep8.
724
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
725
        def trivial_custom_prop_handler(revision):
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
726
            raise Exception("a test error")
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
727
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
728
        log.properties_handler_registry.register(
729
            'trivial_custom_prop_handler',
730
            trivial_custom_prop_handler)
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
731
        self.assertRaises(Exception, log.show_log, wt.branch, formatter,)
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
732
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
733
    def test_properties_handler_bad_argument(self):
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
734
        wt = self.make_standard_commit('bad_argument',
7143.15.2 by Jelmer Vernooij
Run autopep8.
735
                                       revprops={u'a_prop': 'test_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
736
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
737
        formatter = log.LongLogFormatter(to_file=sio)
7143.15.2 by Jelmer Vernooij
Run autopep8.
738
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
739
        def bad_argument_prop_handler(revision):
7143.15.2 by Jelmer Vernooij
Run autopep8.
740
            return {'custom_prop_name': revision.properties['a_prop']}
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
741
742
        log.properties_handler_registry.register(
743
            'bad_argument_prop_handler',
744
            bad_argument_prop_handler)
745
746
        self.assertRaises(AttributeError, formatter.show_properties,
747
                          'a revision', '')
748
749
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
750
        formatter.show_properties(revision, '')
7067.13.1 by Jelmer Vernooij
Some more fixes for Python 3.
751
        self.assertEqualDiff(b'''custom_prop_name: test_value\n''',
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
752
                             sio.getvalue())
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
753
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
754
    def test_show_ids(self):
755
        wt = self.make_branch_and_tree('parent')
756
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
757
        wt.add(['f1', 'f2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
758
        self.wt_commit(wt, 'first post', rev_id=b'a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
759
        child_wt = wt.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
760
        self.wt_commit(child_wt, 'branch 1 changes', rev_id=b'b')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
761
        wt.merge_from_branch(child_wt.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
762
        self.wt_commit(wt, 'merge branch 1', rev_id=b'c')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
763
        self.assertFormatterResult(b"""\
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
764
------------------------------------------------------------
765
revno: 2 [merge]
766
revision-id: c
767
parent: a
768
parent: b
769
committer: Joe Foo <joe@foo.com>
770
branch nick: parent
771
timestamp: Tue 2005-11-22 00:00:02 +0000
772
message:
773
  merge branch 1
774
    ------------------------------------------------------------
775
    revno: 1.1.1
776
    revision-id: b
777
    parent: a
778
    committer: Joe Foo <joe@foo.com>
779
    branch nick: child
780
    timestamp: Tue 2005-11-22 00:00:01 +0000
781
    message:
782
      branch 1 changes
783
------------------------------------------------------------
784
revno: 1
785
revision-id: a
786
committer: Joe Foo <joe@foo.com>
787
branch nick: parent
788
timestamp: Tue 2005-11-22 00:00:00 +0000
789
message:
790
  first post
791
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
792
                                   wt.branch, log.LongLogFormatter,
793
                                   formatter_kwargs=dict(levels=0, show_ids=True))
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
794
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
795
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
796
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
797
798
    def test_long_verbose_log(self):
799
        """Verbose log includes changed files
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
800
3947.1.2 by Ian Clatworthy
formatter tests
801
        bug #4676
802
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
803
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
804
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
805
------------------------------------------------------------
806
revno: 1
807
committer: Lorem Ipsum <test@example.com>
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
808
branch nick: test_long_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
809
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
810
message:
811
  add a
812
added:
813
  a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
814
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
815
                                   wt.branch, log.LongLogFormatter,
816
                                   formatter_kwargs=dict(levels=1),
817
                                   show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
818
819
    def test_long_verbose_contain_deltas(self):
820
        wt = self.make_branch_and_tree('parent')
821
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
822
        wt.add(['f1', 'f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
823
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
824
        child_wt = wt.controldir.sprout('child').open_workingtree()
3947.1.2 by Ian Clatworthy
formatter tests
825
        os.unlink('child/f1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
826
        self.build_tree_contents([('child/f2', b'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
827
        self.wt_commit(child_wt, 'removed f1 and modified f2')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
828
        wt.merge_from_branch(child_wt.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
829
        self.wt_commit(wt, 'merge branch 1')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
830
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
831
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
832
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
833
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
834
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
835
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
836
message:
837
  merge branch 1
838
removed:
839
  f1
840
modified:
841
  f2
842
------------------------------------------------------------
843
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
844
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
845
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
846
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
847
message:
848
  first post
849
added:
850
  f1
851
  f2
852
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
853
                                   wt.branch, log.LongLogFormatter,
854
                                   formatter_kwargs=dict(levels=1),
855
                                   show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
856
857
    def test_long_trailing_newlines(self):
858
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
859
        b = self.make_commits_with_trailing_newlines(wt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
860
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
861
------------------------------------------------------------
862
revno: 3
863
committer: Joe Foo <joe@foo.com>
864
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
865
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
866
message:
867
  single line with trailing newline
868
------------------------------------------------------------
869
revno: 2
870
committer: Joe Foo <joe@foo.com>
871
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
872
timestamp: Tue 2005-11-22 00:00:01 +0000
3947.1.2 by Ian Clatworthy
formatter tests
873
message:
874
  multiline
875
  log
876
  message
877
------------------------------------------------------------
878
revno: 1
879
committer: Joe Foo <joe@foo.com>
880
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
881
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
882
message:
883
  simple log message
884
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
885
                                   b, log.LongLogFormatter,
886
                                   formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
887
888
    def test_long_author_in_log(self):
889
        """Log includes the author name if it's set in
890
        the revision properties
891
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
892
        wt = self.make_standard_commit('test_author_log')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
893
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
894
------------------------------------------------------------
895
revno: 1
896
author: John Doe <jdoe@example.com>
897
committer: Lorem Ipsum <test@example.com>
898
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
899
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
900
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
901
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
902
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
903
                                   wt.branch, log.LongLogFormatter,
904
                                   formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
905
906
    def test_long_properties_in_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
907
        """Log includes the custom properties returned by the registered
3947.1.2 by Ian Clatworthy
formatter tests
908
        handlers.
909
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
910
        wt = self.make_standard_commit('test_properties_in_log')
7143.15.2 by Jelmer Vernooij
Run autopep8.
911
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
912
        def trivial_custom_prop_handler(revision):
7143.15.2 by Jelmer Vernooij
Run autopep8.
913
            return {'test_prop': 'test_value'}
3947.1.2 by Ian Clatworthy
formatter tests
914
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
915
        log.properties_handler_registry.register(
916
            'trivial_custom_prop_handler',
917
            trivial_custom_prop_handler)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
918
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
919
------------------------------------------------------------
920
revno: 1
921
test_prop: test_value
922
author: John Doe <jdoe@example.com>
923
committer: Lorem Ipsum <test@example.com>
924
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
925
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
926
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
927
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
928
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
929
                                   wt.branch, log.LongLogFormatter,
930
                                   formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
931
932
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
933
class TestLineLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
934
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
935
    def test_line_log(self):
936
        """Line log should show revno
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
937
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
938
        bug #5162
939
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
940
        wt = self.make_standard_commit('test-line-log',
7143.15.2 by Jelmer Vernooij
Run autopep8.
941
                                       committer='Line-Log-Formatter Tester <test@line.log>',
942
                                       authors=[])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
943
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
944
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
945
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
946
                                   wt.branch, log.LineLogFormatter)
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
947
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
948
    def test_trailing_newlines(self):
949
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
950
        b = self.make_commits_with_trailing_newlines(wt)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
951
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
952
3: Joe Foo 2005-11-22 single line with trailing newline
953
2: Joe Foo 2005-11-22 multiline
954
1: Joe Foo 2005-11-22 simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
955
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
956
                                   b, log.LineLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
957
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
958
    def test_line_log_single_merge_revision(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
959
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
960
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
961
        rev = revspec.in_history(wt.branch)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
962
        self.assertFormatterResult(b"""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
963
1.1.1: Joe Foo 2005-11-22 rev-merged
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
964
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
965
                                   wt.branch, log.LineLogFormatter,
966
                                   show_log_kwargs=dict(start_revision=rev, end_revision=rev))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
967
3946.3.2 by Ian Clatworthy
add tests & NEWS item
968
    def test_line_log_with_tags(self):
969
        wt = self._prepare_tree_with_merges(with_tags=True)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
970
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
971
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
972
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
3946.3.2 by Ian Clatworthy
add tests & NEWS item
973
1: Joe Foo 2005-11-22 rev-1
974
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
975
                                   wt.branch, log.LineLogFormatter)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
976
977
978
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
979
980
    def test_line_merge_revs_log(self):
981
        """Line log should show revno
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
982
3947.1.2 by Ian Clatworthy
formatter tests
983
        bug #5162
984
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
985
        wt = self.make_standard_commit('test-line-log',
7143.15.2 by Jelmer Vernooij
Run autopep8.
986
                                       committer='Line-Log-Formatter Tester <test@line.log>',
987
                                       authors=[])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
988
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
989
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
990
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
991
                                   wt.branch, log.LineLogFormatter)
3947.1.2 by Ian Clatworthy
formatter tests
992
993
    def test_line_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
994
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
995
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
996
        rev = revspec.in_history(wt.branch)
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
997
        self.assertFormatterResult(b"""\
3947.1.2 by Ian Clatworthy
formatter tests
998
1.1.1: Joe Foo 2005-11-22 rev-merged
999
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1000
                                   wt.branch, log.LineLogFormatter,
1001
                                   formatter_kwargs=dict(levels=0),
1002
                                   show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
1003
1004
    def test_line_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
1005
        wt = self._prepare_tree_with_merges()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1006
        self.assertFormatterResult(b"""\
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
1007
2: Joe Foo 2005-11-22 [merge] rev-2
3947.1.2 by Ian Clatworthy
formatter tests
1008
  1.1.1: Joe Foo 2005-11-22 rev-merged
1009
1: Joe Foo 2005-11-22 rev-1
1010
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1011
                                   wt.branch, log.LineLogFormatter,
1012
                                   formatter_kwargs=dict(levels=0))
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
1013
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
1014
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1015
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
1016
1017
    def test_gnu_changelog(self):
1018
        wt = self.make_standard_commit('nicky', authors=[])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1019
        self.assertFormatterResult(b'''\
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1020
2005-11-22  Lorem Ipsum  <test@example.com>
1021
1022
\tadd a
1023
1024
''',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1025
                                   wt.branch, log.GnuChangelogLogFormatter)
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1026
1027
    def test_with_authors(self):
1028
        wt = self.make_standard_commit('nicky',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1029
                                       authors=['Fooa Fooz <foo@example.com>',
1030
                                                'Bari Baro <bar@example.com>'])
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1031
        self.assertFormatterResult(b'''\
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1032
2005-11-22  Fooa Fooz  <foo@example.com>
1033
1034
\tadd a
1035
1036
''',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1037
                                   wt.branch, log.GnuChangelogLogFormatter)
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1038
1039
    def test_verbose(self):
1040
        wt = self.make_standard_commit('nicky')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1041
        self.assertFormatterResult(b'''\
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1042
2005-11-22  John Doe  <jdoe@example.com>
1043
1044
\t* a:
1045
1046
\tadd a
1047
1048
''',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1049
                                   wt.branch, log.GnuChangelogLogFormatter,
1050
                                   show_log_kwargs=dict(verbose=True))
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1051
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1052
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1053
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1054
1055
    def test_show_changed_revisions_verbose(self):
1056
        tree = self.make_branch_and_tree('tree_a')
1057
        self.build_tree(['tree_a/foo'])
1058
        tree.add('foo')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1059
        tree.commit('bar', rev_id=b'bar-id')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
1060
        s = self.make_utf8_encoded_stringio()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1061
        log.show_changed_revisions(tree.branch, [], [b'bar-id'], s)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1062
        self.assertContainsRe(s.getvalue(), b'bar')
1063
        self.assertNotContainsRe(s.getvalue(), b'foo')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1064
1065
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1066
class TestLogFormatter(tests.TestCase):
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1067
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1068
    def setUp(self):
1069
        super(TestLogFormatter, self).setUp()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1070
        self.rev = revision.Revision(b'a-id')
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1071
        self.lf = log.LogFormatter(None)
1072
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1073
    def test_short_committer(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1074
        def assertCommitter(expected, committer):
1075
            self.rev.committer = committer
1076
            self.assertEqual(expected, self.lf.short_committer(self.rev))
1077
1078
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1079
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1080
        assertCommitter('John Smith', 'John Smith')
1081
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
1082
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1083
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1084
1085
    def test_short_author(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1086
        def assertAuthor(expected, author):
1087
            self.rev.properties['author'] = author
1088
            self.assertEqual(expected, self.lf.short_author(self.rev))
1089
1090
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1091
        assertAuthor('John Smith', 'John Smith')
1092
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
1093
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1094
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
1095
1096
    def test_short_author_from_committer(self):
1097
        self.rev.committer = 'John Doe <jdoe@example.com>'
1098
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
1099
1100
    def test_short_author_from_authors(self):
1101
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1102
                                          'Jane Rey <jrey@example.com>')
1103
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1104
1105
1106
class TestReverseByDepth(tests.TestCase):
1107
    """Test reverse_by_depth behavior.
1108
1109
    This is used to present revisions in forward (oldest first) order in a nice
1110
    layout.
1111
1112
    The tests use lighter revision description to ease reading.
1113
    """
1114
1115
    def assertReversed(self, forward, backward):
1116
        # Transform the descriptions to suit the API: tests use (revno, depth),
1117
        # while the API expects (revid, revno, depth)
1118
        def complete_revisions(l):
1119
            """Transform the description to suit the API.
1120
1121
            Tests use (revno, depth) whil the API expects (revid, revno, depth).
1122
            Since the revid is arbitrary, we just duplicate revno
1123
            """
7143.15.2 by Jelmer Vernooij
Run autopep8.
1124
            return [(r, r, d) for r, d in l]
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1125
        forward = complete_revisions(forward)
7143.15.2 by Jelmer Vernooij
Run autopep8.
1126
        backward = complete_revisions(backward)
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1127
        self.assertEqual(forward, log.reverse_by_depth(backward))
1128
1129
    def test_mainline_revisions(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
1130
        self.assertReversed([('1', 0), ('2', 0)],
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1131
                            [('2', 0), ('1', 0)])
1132
1133
    def test_merged_revisions(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
1134
        self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1), ],
1135
                            [('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0), ])
1136
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1137
    def test_shifted_merged_revisions(self):
1138
        """Test irregular layout.
1139
1140
        Requesting revisions touching a file can produce "holes" in the depths.
1141
        """
7143.15.2 by Jelmer Vernooij
Run autopep8.
1142
        self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2), ],
1143
                            [('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0), ])
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1144
1145
    def test_merged_without_child_revisions(self):
1146
        """Test irregular layout.
1147
1148
        Revision ranges can produce "holes" in the depths.
1149
        """
1150
        # When a revision of higher depth doesn't follow one of lower depth, we
1151
        # assume a lower depth one is virtually there
1152
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1153
                            [('4', 4), ('3', 3), ('2', 2), ('1', 2), ])
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1154
        # So we get the same order after reversing below even if the original
1155
        # revisions are not in the same order.
1156
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1157
                            [('3', 3), ('4', 4), ('2', 2), ('1', 2), ])
3848.1.6 by Aaron Bentley
Implement get_history_change
1158
1159
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1160
class TestHistoryChange(tests.TestCaseWithTransport):
3848.1.6 by Aaron Bentley
Implement get_history_change
1161
1162
    def setup_a_tree(self):
1163
        tree = self.make_branch_and_tree('tree')
1164
        tree.lock_write()
1165
        self.addCleanup(tree.unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1166
        tree.commit('1a', rev_id=b'1a')
1167
        tree.commit('2a', rev_id=b'2a')
1168
        tree.commit('3a', rev_id=b'3a')
3848.1.6 by Aaron Bentley
Implement get_history_change
1169
        return tree
1170
1171
    def setup_ab_tree(self):
1172
        tree = self.setup_a_tree()
6973.10.6 by Jelmer Vernooij
Fix tests.
1173
        tree.set_last_revision(b'1a')
1174
        tree.branch.set_last_revision_info(1, b'1a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1175
        tree.commit('2b', rev_id=b'2b')
1176
        tree.commit('3b', rev_id=b'3b')
3848.1.6 by Aaron Bentley
Implement get_history_change
1177
        return tree
1178
1179
    def setup_ac_tree(self):
1180
        tree = self.setup_a_tree()
1181
        tree.set_last_revision(revision.NULL_REVISION)
1182
        tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1183
        tree.commit('1c', rev_id=b'1c')
1184
        tree.commit('2c', rev_id=b'2c')
1185
        tree.commit('3c', rev_id=b'3c')
3848.1.6 by Aaron Bentley
Implement get_history_change
1186
        return tree
1187
1188
    def test_all_new(self):
1189
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1190
        old, new = log.get_history_change(b'1a', b'3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1191
        self.assertEqual([], old)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1192
        self.assertEqual([b'2a', b'3a'], new)
3848.1.6 by Aaron Bentley
Implement get_history_change
1193
1194
    def test_all_old(self):
1195
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1196
        old, new = log.get_history_change(b'3a', b'1a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1197
        self.assertEqual([], new)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1198
        self.assertEqual([b'2a', b'3a'], old)
3848.1.6 by Aaron Bentley
Implement get_history_change
1199
1200
    def test_null_old(self):
1201
        tree = self.setup_ab_tree()
1202
        old, new = log.get_history_change(revision.NULL_REVISION,
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1203
                                          b'3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1204
        self.assertEqual([], old)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1205
        self.assertEqual([b'1a', b'2a', b'3a'], new)
3848.1.6 by Aaron Bentley
Implement get_history_change
1206
1207
    def test_null_new(self):
1208
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1209
        old, new = log.get_history_change(b'3a', revision.NULL_REVISION,
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1210
                                          tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1211
        self.assertEqual([], new)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1212
        self.assertEqual([b'1a', b'2a', b'3a'], old)
3848.1.6 by Aaron Bentley
Implement get_history_change
1213
1214
    def test_diverged(self):
1215
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1216
        old, new = log.get_history_change(b'3a', b'3b', tree.branch.repository)
1217
        self.assertEqual(old, [b'2a', b'3a'])
1218
        self.assertEqual(new, [b'2b', b'3b'])
3848.1.6 by Aaron Bentley
Implement get_history_change
1219
1220
    def test_unrelated(self):
1221
        tree = self.setup_ac_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1222
        old, new = log.get_history_change(b'3a', b'3c', tree.branch.repository)
1223
        self.assertEqual(old, [b'1a', b'2a', b'3a'])
1224
        self.assertEqual(new, [b'1c', b'2c', b'3c'])
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1225
1226
    def test_show_branch_change(self):
1227
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1228
        s = StringIO()
1229
        log.show_branch_change(tree.branch, s, 3, b'3a')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1230
        self.assertContainsRe(s.getvalue(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1231
                              '[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1232
                              '[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1233
1234
    def test_show_branch_change_no_change(self):
1235
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1236
        s = StringIO()
1237
        log.show_branch_change(tree.branch, s, 3, b'3b')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1238
        self.assertEqual(s.getvalue(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1239
                         'Nothing seems to have changed\n')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1240
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1241
    def test_show_branch_change_no_old(self):
1242
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1243
        s = StringIO()
1244
        log.show_branch_change(tree.branch, s, 2, b'2b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1245
        self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1246
        self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1247
1248
    def test_show_branch_change_no_new(self):
1249
        tree = self.setup_ab_tree()
6973.10.6 by Jelmer Vernooij
Fix tests.
1250
        tree.branch.set_last_revision_info(2, b'2b')
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1251
        s = StringIO()
1252
        log.show_branch_change(tree.branch, s, 3, b'3b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1253
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1254
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1255
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1256
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1257
class TestRevisionNotInBranch(TestCaseForLogFormatter):
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1258
1259
    def setup_a_tree(self):
1260
        tree = self.make_branch_and_tree('tree')
1261
        tree.lock_write()
1262
        self.addCleanup(tree.unlock)
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1263
        kwargs = {
1264
            'committer': 'Joe Foo <joe@foo.com>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1265
            'timestamp': 1132617600,  # Mon 2005-11-22 00:00:00 +0000
1266
            'timezone': 0,  # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1267
        }
6855.4.1 by Jelmer Vernooij
Yet more bees.
1268
        tree.commit('commit 1a', rev_id=b'1a', **kwargs)
1269
        tree.commit('commit 2a', rev_id=b'2a', **kwargs)
1270
        tree.commit('commit 3a', rev_id=b'3a', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1271
        return tree
1272
1273
    def setup_ab_tree(self):
1274
        tree = self.setup_a_tree()
6973.10.6 by Jelmer Vernooij
Fix tests.
1275
        tree.set_last_revision(b'1a')
1276
        tree.branch.set_last_revision_info(1, b'1a')
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1277
        kwargs = {
1278
            'committer': 'Joe Foo <joe@foo.com>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1279
            'timestamp': 1132617600,  # Mon 2005-11-22 00:00:00 +0000
1280
            'timezone': 0,  # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1281
        }
6855.4.1 by Jelmer Vernooij
Yet more bees.
1282
        tree.commit('commit 2b', rev_id=b'2b', **kwargs)
1283
        tree.commit('commit 3b', rev_id=b'3b', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1284
        return tree
1285
1286
    def test_one_revision(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1287
        tree = self.setup_ab_tree()
1288
        lf = LogCatcher()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1289
        rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1290
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1291
                     end_revision=rev)
1292
        self.assertEqual(1, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1293
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1294
        self.assertEqual(b'3a', lf.revisions[0].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1295
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1296
    def test_many_revisions(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1297
        tree = self.setup_ab_tree()
1298
        lf = LogCatcher()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1299
        start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1300
        end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1301
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1302
                     end_revision=end_rev)
1303
        self.assertEqual(3, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1304
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1305
        self.assertEqual(b'3a', lf.revisions[0].rev.revision_id)
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1306
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1307
        self.assertEqual(b'2a', lf.revisions[1].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1308
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1309
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1310
    def test_long_format(self):
1311
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1312
        start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1313
        end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1314
        self.assertFormatterResult(b"""\
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1315
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1316
revision-id: 3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1317
committer: Joe Foo <joe@foo.com>
1318
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1319
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1320
message:
1321
  commit 3a
1322
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1323
revision-id: 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1324
committer: Joe Foo <joe@foo.com>
1325
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1326
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1327
message:
1328
  commit 2a
1329
------------------------------------------------------------
1330
revno: 1
1331
committer: Joe Foo <joe@foo.com>
1332
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1333
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1334
message:
1335
  commit 1a
1336
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1337
                                   tree.branch, log.LongLogFormatter, show_log_kwargs={
1338
                                       'start_revision': start_rev, 'end_revision': end_rev
1339
                                       })
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1340
1341
    def test_short_format(self):
1342
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1343
        start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1344
        end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1345
        self.assertFormatterResult(b"""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1346
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1347
      revision-id:3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1348
      commit 3a
1349
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1350
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1351
      revision-id:2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1352
      commit 2a
1353
1354
    1 Joe Foo\t2005-11-22
1355
      commit 1a
1356
1357
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1358
                                   tree.branch, log.ShortLogFormatter, show_log_kwargs={
1359
                                       'start_revision': start_rev, 'end_revision': end_rev
1360
                                       })
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1361
1362
    def test_line_format(self):
1363
        tree = self.setup_ab_tree()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1364
        start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1365
        end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1366
        self.assertFormatterResult(b"""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1367
Joe Foo 2005-11-22 commit 3a
1368
Joe Foo 2005-11-22 commit 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1369
1: Joe Foo 2005-11-22 commit 1a
1370
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1371
                                   tree.branch, log.LineLogFormatter, show_log_kwargs={
1372
                                       'start_revision': start_rev, 'end_revision': end_rev
1373
                                       })
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1374
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1375
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1376
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1377
1378
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1379
        super(TestLogWithBugs, self).setUp()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1380
        log.properties_handler_registry.register(
1381
            'bugs_properties_handler',
1382
            log._bugs_properties_handler)
1383
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1384
    def make_commits_with_bugs(self):
1385
        """Helper method for LogFormatter tests"""
1386
        tree = self.make_branch_and_tree(u'.')
1387
        self.build_tree(['a', 'b'])
1388
        tree.add('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1389
        self.wt_commit(tree, 'simple log message', rev_id=b'a1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1390
                       revprops={u'bugs': 'test://bug/id fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1391
        tree.add('b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1392
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id=b'a2',
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1393
                       authors=['Joe Bar <joe@bar.com>'],
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1394
                       revprops={u'bugs': 'test://bug/id fixed\n'
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1395
                                 'test://bug/2 fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1396
        return tree
1397
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1398
    def test_long_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1399
        tree = self.make_commits_with_bugs()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1400
        self.assertFormatterResult(b"""\
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1401
------------------------------------------------------------
1402
revno: 2
6143.1.8 by Jonathan Riddell
fix log formatting of bug line
1403
fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1404
author: Joe Bar <joe@bar.com>
1405
committer: Joe Foo <joe@foo.com>
1406
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1407
timestamp: Tue 2005-11-22 00:00:01 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1408
message:
1409
  multiline
1410
  log
1411
  message
1412
------------------------------------------------------------
1413
revno: 1
6143.1.4 by Jonathan Riddell
update tests
1414
fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1415
committer: Joe Foo <joe@foo.com>
1416
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1417
timestamp: Tue 2005-11-22 00:00:00 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1418
message:
1419
  simple log message
1420
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1421
                                   tree.branch, log.LongLogFormatter)
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1422
1423
    def test_short_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1424
        tree = self.make_commits_with_bugs()
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1425
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1426
    2 Joe Bar\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1427
      fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1428
      multiline
1429
      log
1430
      message
1431
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1432
    1 Joe Foo\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1433
      fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1434
      simple log message
1435
1436
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1437
                                   tree.branch, log.ShortLogFormatter)
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1438
1439
    def test_wrong_bugs_property(self):
1440
        tree = self.make_branch_and_tree(u'.')
1441
        self.build_tree(['foo'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1442
        self.wt_commit(tree, 'simple log message', rev_id=b'a1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1443
                       revprops={u'bugs': 'test://bug/id invalid_value'})
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1444
        self.assertFormatterResult(b"""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1445
    1 Joe Foo\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1446
      simple log message
1447
1448
""",
7143.15.2 by Jelmer Vernooij
Run autopep8.
1449
                                   tree.branch, log.ShortLogFormatter)
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1450
1451
    def test_bugs_handler_present(self):
1452
        self.properties_handler_registry.get('bugs_properties_handler')
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1453
1454
1455
class TestLogForAuthors(TestCaseForLogFormatter):
1456
1457
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1458
        super(TestLogForAuthors, self).setUp()
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1459
        self.wt = self.make_standard_commit('nicky',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1460
                                            authors=['John Doe <jdoe@example.com>',
1461
                                                     'Jane Rey <jrey@example.com>'])
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1462
1463
    def assertFormatterResult(self, formatter, who, result):
1464
        formatter_kwargs = dict()
1465
        if who is not None:
4081.3.10 by Martin von Gagern
Renamed "authors" to "author_list_handler" in several places.
1466
            author_list_handler = log.author_list_registry.get(who)
1467
            formatter_kwargs['author_list_handler'] = author_list_handler
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1468
        TestCaseForLogFormatter.assertFormatterResult(self, result,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1469
                                                      self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1470
1471
    def test_line_default(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1472
        self.assertFormatterResult(log.LineLogFormatter, None, b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1473
1: John Doe 2005-11-22 add a
1474
""")
1475
1476
    def test_line_committer(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1477
        self.assertFormatterResult(log.LineLogFormatter, 'committer', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1478
1: Lorem Ipsum 2005-11-22 add a
1479
""")
1480
1481
    def test_line_first(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1482
        self.assertFormatterResult(log.LineLogFormatter, 'first', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1483
1: John Doe 2005-11-22 add a
1484
""")
1485
1486
    def test_line_all(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1487
        self.assertFormatterResult(log.LineLogFormatter, 'all', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1488
1: John Doe, Jane Rey 2005-11-22 add a
1489
""")
1490
1491
    def test_short_default(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1492
        self.assertFormatterResult(log.ShortLogFormatter, None, b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1493
    1 John Doe\t2005-11-22
1494
      add a
1495
1496
""")
1497
1498
    def test_short_committer(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1499
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1500
    1 Lorem Ipsum\t2005-11-22
1501
      add a
1502
1503
""")
1504
1505
    def test_short_first(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1506
        self.assertFormatterResult(log.ShortLogFormatter, 'first', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1507
    1 John Doe\t2005-11-22
1508
      add a
1509
1510
""")
1511
1512
    def test_short_all(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1513
        self.assertFormatterResult(log.ShortLogFormatter, 'all', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1514
    1 John Doe, Jane Rey\t2005-11-22
1515
      add a
1516
1517
""")
1518
1519
    def test_long_default(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1520
        self.assertFormatterResult(log.LongLogFormatter, None, b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1521
------------------------------------------------------------
1522
revno: 1
1523
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1524
committer: Lorem Ipsum <test@example.com>
1525
branch nick: nicky
1526
timestamp: Tue 2005-11-22 00:00:00 +0000
1527
message:
1528
  add a
1529
""")
1530
1531
    def test_long_committer(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1532
        self.assertFormatterResult(log.LongLogFormatter, 'committer', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1533
------------------------------------------------------------
1534
revno: 1
1535
committer: Lorem Ipsum <test@example.com>
1536
branch nick: nicky
1537
timestamp: Tue 2005-11-22 00:00:00 +0000
1538
message:
1539
  add a
1540
""")
1541
1542
    def test_long_first(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1543
        self.assertFormatterResult(log.LongLogFormatter, 'first', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1544
------------------------------------------------------------
1545
revno: 1
1546
author: John Doe <jdoe@example.com>
1547
committer: Lorem Ipsum <test@example.com>
1548
branch nick: nicky
1549
timestamp: Tue 2005-11-22 00:00:00 +0000
1550
message:
1551
  add a
1552
""")
1553
1554
    def test_long_all(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1555
        self.assertFormatterResult(log.LongLogFormatter, 'all', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1556
------------------------------------------------------------
1557
revno: 1
1558
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1559
committer: Lorem Ipsum <test@example.com>
1560
branch nick: nicky
1561
timestamp: Tue 2005-11-22 00:00:00 +0000
1562
message:
1563
  add a
1564
""")
1565
1566
    def test_gnu_changelog_default(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1567
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1568
2005-11-22  John Doe  <jdoe@example.com>
1569
1570
\tadd a
1571
1572
""")
1573
1574
    def test_gnu_changelog_committer(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1575
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1576
2005-11-22  Lorem Ipsum  <test@example.com>
1577
1578
\tadd a
1579
1580
""")
1581
1582
    def test_gnu_changelog_first(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1583
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1584
2005-11-22  John Doe  <jdoe@example.com>
1585
1586
\tadd a
1587
1588
""")
1589
1590
    def test_gnu_changelog_all(self):
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
1591
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', b"""\
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1592
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
1593
1594
\tadd a
1595
1596
""")
4081.3.15 by Gary van der Merwe
Merge bzr.dev.
1597
5691.1.3 by Jelmer Vernooij
Fix whitespace.
1598
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1599
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1600
1601
    def make_branch_with_alternate_ancestries(self, relpath='.'):
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1602
        # See test_merge_sorted_exclude_ancestry below for the difference with
1603
        # bt.per_branch.test_iter_merge_sorted_revision.
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1604
        # TestIterMergeSortedRevisionsBushyGraph.
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1605
        # make_branch_with_alternate_ancestries
1606
        # and test_merge_sorted_exclude_ancestry
1607
        # See the FIXME in assertLogRevnos too.
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1608
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1609
        # 1
1610
        # |\
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1611
        # 2 \
1612
        # |  |
1613
        # |  1.1.1
1614
        # |  | \
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1615
        # |  |  1.2.1
1616
        # |  | /
1617
        # |  1.1.2
1618
        # | /
1619
        # 3
1620
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1621
        builder.build_snapshot(None, [
7143.15.2 by Jelmer Vernooij
Run autopep8.
1622
            ('add', ('', b'TREE_ROOT', 'directory', '')), ],
6973.5.2 by Jelmer Vernooij
Add more bees.
1623
            revision_id=b'1')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1624
        builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
1625
        builder.build_snapshot([b'1'], [], revision_id=b'2')
1626
        builder.build_snapshot([b'1.1.1'], [], revision_id=b'1.2.1')
1627
        builder.build_snapshot([b'1.1.1', b'1.2.1'], [], revision_id=b'1.1.2')
1628
        builder.build_snapshot([b'2', b'1.1.2'], [], revision_id=b'3')
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1629
        builder.finish_series()
1630
        br = builder.get_branch()
1631
        br.lock_read()
1632
        self.addCleanup(br.unlock)
1633
        return br
1634
1635
    def assertLogRevnos(self, expected_revnos, b, start, end,
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1636
                        exclude_common_ancestry, generate_merge_revisions=True):
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1637
        # FIXME: the layering in log makes it hard to test intermediate levels,
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
1638
        # I wish adding filters with their parameters was easier...
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1639
        # -- vila 20100413
1640
        iter_revs = log._calc_view_revisions(
1641
            b, start, end, direction='reverse',
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1642
            generate_merge_revisions=generate_merge_revisions,
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1643
            exclude_common_ancestry=exclude_common_ancestry)
1644
        self.assertEqual(expected_revnos,
1645
                         [revid for revid, revno, depth in iter_revs])
1646
1647
    def test_merge_sorted_exclude_ancestry(self):
1648
        b = self.make_branch_with_alternate_ancestries()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1649
        self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'1.1.1', b'2', b'1'],
1650
                             b, b'1', b'3', exclude_common_ancestry=False)
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1651
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1652
        # it should be mentioned even if merge_sort order will make it appear
1653
        # after 1.1.1
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1654
        self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'2'],
1655
                             b, b'1.1.1', b'3', exclude_common_ancestry=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1656
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1657
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1658
        b = self.make_branch_with_alternate_ancestries()
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1659
        self.assertLogRevnos([b'3', b'2'],
1660
                             b, b'1', b'3', exclude_common_ancestry=True,
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1661
                             generate_merge_revisions=False)
7045.4.13 by Jelmer Vernooij
Some more test fixes.
1662
        self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'1.1.1', b'2'],
1663
                             b, b'1', b'3', exclude_common_ancestry=True,
5268.4.3 by Vincent Ladeuil
Respect --exclude-common-ancestry for linear ancestries.
1664
                             generate_merge_revisions=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1665
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1666
1667
class TestLogDefaults(TestCaseForLogFormatter):
1668
    def test_default_log_level(self):
6042.1.2 by Thomi Richards
Minor changes as a result of feedback from merge proposal.
1669
        """
1670
        Test to ensure that specifying 'levels=1' to make_log_request_dict
1671
        doesn't get overwritten when using a LogFormatter that supports more
1672
        detail.
1673
        Fixes bug #747958.
1674
        """
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1675
        wt = self._prepare_tree_with_merges()
1676
        b = wt.branch
1677
1678
        class CustomLogFormatter(log.LogFormatter):
1679
            def __init__(self, *args, **kwargs):
1680
                super(CustomLogFormatter, self).__init__(*args, **kwargs)
1681
                self.revisions = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
1682
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1683
            def get_levels(self):
1684
                # log formatter supports all levels:
1685
                return 0
7143.15.2 by Jelmer Vernooij
Run autopep8.
1686
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1687
            def log_revision(self, revision):
1688
                self.revisions.append(revision)
1689
1690
        log_formatter = LogCatcher()
1691
        # First request we don't specify number of levels, we should get a
1692
        # sensible default (whatever the LogFormatter handles - which in this
1693
        # case is 0/everything):
1694
        request = log.make_log_request_dict(limit=10)
1695
        log.Logger(b, request).show(log_formatter)
1696
        # should have all three revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1697
        self.assertEqual(len(log_formatter.revisions), 3)
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1698
1699
        del log_formatter
1700
        log_formatter = LogCatcher()
1701
        # now explicitly request mainline revisions only:
1702
        request = log.make_log_request_dict(limit=10, levels=1)
1703
        log.Logger(b, request).show(log_formatter)
1704
        # should now only have 2 revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1705
        self.assertEqual(len(log_formatter.revisions), 2)