~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_log.py

  • Committer: Martin Pool
  • Date: 2005-06-02 02:37:54 UTC
  • Revision ID: mbp@sourcefrog.net-20050602023754-fc3d4c02877ba29d
doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 
18
 
 
19
 
"""Black-box tests for bzr log."""
20
 
 
21
 
import os
22
 
 
23
 
import bzrlib
24
 
from bzrlib.tests.blackbox import ExternalBase
25
 
from bzrlib.tests import TestCaseInTempDir
26
 
 
27
 
 
28
 
class TestLog(ExternalBase):
29
 
 
30
 
    def _prepare(self):
31
 
        self.runbzr("init")
32
 
        self.build_tree(['hello.txt', 'goodbye.txt', 'meep.txt'])
33
 
        self.runbzr("add hello.txt")
34
 
        self.runbzr("commit -m message1 hello.txt")
35
 
        self.runbzr("add goodbye.txt")
36
 
        self.runbzr("commit -m message2 goodbye.txt")
37
 
        self.runbzr("add meep.txt")
38
 
        self.runbzr("commit -m message3 meep.txt")
39
 
        self.full_log = self.runbzr("log")[0]
40
 
 
41
 
    def test_log_null_end_revspec(self):
42
 
        self._prepare()
43
 
        self.assertTrue('revno: 1\n' in self.full_log)
44
 
        self.assertTrue('revno: 2\n' in self.full_log)
45
 
        self.assertTrue('revno: 3\n' in self.full_log)
46
 
        self.assertTrue('message:\n  message1\n' in self.full_log)
47
 
        self.assertTrue('message:\n  message2\n' in self.full_log)
48
 
        self.assertTrue('message:\n  message3\n' in self.full_log)
49
 
 
50
 
        log = self.runbzr("log -r 1..")[0]
51
 
        self.assertEquals(log, self.full_log)
52
 
 
53
 
    def test_log_null_begin_revspec(self):
54
 
        self._prepare()
55
 
        log = self.runbzr("log -r ..3")[0]
56
 
        self.assertEquals(self.full_log, log)
57
 
 
58
 
    def test_log_null_both_revspecs(self):
59
 
        self._prepare()
60
 
        log = self.runbzr("log -r ..")[0]
61
 
        self.assertEquals(self.full_log, log)
62
 
 
63
 
    def test_log_negative_begin_revspec_full_log(self):
64
 
        self._prepare()
65
 
        log = self.runbzr("log -r -3..")[0]
66
 
        self.assertEquals(self.full_log, log)
67
 
 
68
 
    def test_log_negative_both_revspec_full_log(self):
69
 
        self._prepare()
70
 
        log = self.runbzr("log -r -3..-1")[0]
71
 
        self.assertEquals(self.full_log, log)
72
 
 
73
 
    def test_log_negative_both_revspec_partial(self):
74
 
        self._prepare()
75
 
        log = self.runbzr("log -r -3..-2")[0]
76
 
        self.assertTrue('revno: 1\n' in log)
77
 
        self.assertTrue('revno: 2\n' in log)
78
 
        self.assertTrue('revno: 3\n' not in log)
79
 
 
80
 
    def test_log_negative_begin_revspec(self):
81
 
        self._prepare()
82
 
        log = self.runbzr("log -r -2..")[0]
83
 
        self.assertTrue('revno: 1\n' not in log)
84
 
        self.assertTrue('revno: 2\n' in log)
85
 
        self.assertTrue('revno: 3\n' in log)
86
 
 
87
 
    def test_log_postive_revspecs(self):
88
 
        self._prepare()
89
 
        log = self.runbzr("log -r 1..3")[0]
90
 
        self.assertEquals(self.full_log, log)
91
 
 
92
 
 
93
 
class TestLogMerges(ExternalBase):
94
 
 
95
 
    def test_merges_are_indented_by_level(self):
96
 
        self.build_tree(['parent/'])
97
 
        self.run_bzr('init', 'parent')
98
 
        self.run_bzr('commit', '-m', 'first post', '--unchanged', 'parent')
99
 
        self.run_bzr('branch', 'parent', 'child')
100
 
        self.run_bzr('commit', '-m', 'branch 1', '--unchanged', 'child')
101
 
        self.run_bzr('branch', 'child', 'smallerchild')
102
 
        self.run_bzr('commit', '-m', 'branch 2', '--unchanged', 'smallerchild')
103
 
        os.chdir('child')
104
 
        self.run_bzr('merge', '../smallerchild')
105
 
        self.run_bzr('commit', '-m', 'merge branch 2')
106
 
        os.chdir('../parent')
107
 
        self.run_bzr('merge', '../child')
108
 
        self.run_bzr('commit', '-m', 'merge branch 1')
109
 
        out,err = self.run_bzr('log')
110
 
        # the log will look something like:
111
 
#        self.assertEqual("""\
112
 
#------------------------------------------------------------
113
 
#revno: 2
114
 
#committer: Robert Collins <foo@example.com>
115
 
#branch nick: parent
116
 
#timestamp: Tue 2006-03-28 22:31:40 +1100
117
 
#message:
118
 
#  merge branch 1
119
 
#    ------------------------------------------------------------
120
 
#    merged: foo@example.com-20060328113140-91f43cfb46dc2863
121
 
#    committer: Robert Collins <foo@example.com>
122
 
#    branch nick: child
123
 
#    timestamp: Tue 2006-03-28 22:31:40 +1100
124
 
#    message:
125
 
#      merge branch 2
126
 
#        ------------------------------------------------------------
127
 
#        merged: foo@example.com-20060328113140-1ba24f850a0ef573
128
 
#        committer: Robert Collins <foo@example.com>
129
 
#        branch nick: smallerchild
130
 
#        timestamp: Tue 2006-03-28 22:31:40 +1100
131
 
#        message:
132
 
#          branch 2
133
 
#    ------------------------------------------------------------
134
 
#    merged: foo@example.com-20060328113140-5749a4757a8ac792
135
 
#    committer: Robert Collins <foo@example.com>
136
 
#    branch nick: child
137
 
#    timestamp: Tue 2006-03-28 22:31:40 +1100
138
 
#    message:
139
 
#      branch 1
140
 
#------------------------------------------------------------
141
 
#revno: 1
142
 
#committer: Robert Collins <foo@example.com>
143
 
#branch nick: parent
144
 
#timestamp: Tue 2006-03-28 22:31:39 +1100
145
 
#message:
146
 
#  first post
147
 
#""", out)
148
 
        # but we dont have a nice pattern matcher hooked up yet, so:
149
 
        # we check for the indenting of the commit message:
150
 
        self.assertTrue('  merge branch 1' in out)
151
 
        self.assertTrue('      merge branch 2' in out)
152
 
        self.assertTrue('          branch 2' in out)
153
 
        self.assertTrue('      branch 1' in out)
154
 
        self.assertTrue('  first post' in out)
155
 
        self.assertEqual('', err)
156
 
 
157
 
 
158
 
class TestLogEncodings(TestCaseInTempDir):
159
 
 
160
 
    _mu = u'\xb5'
161
 
    _message = u'Message with \xb5'
162
 
 
163
 
    # Encodings which can encode mu
164
 
    good_encodings = [
165
 
        'utf-8',
166
 
        'latin-1',
167
 
        'iso-8859-1',
168
 
        'cp437', # Common windows encoding
169
 
        'cp1251', # Alexander Belchenko's windows encoding
170
 
        'cp1258', # Common windows encoding
171
 
    ]
172
 
    # Encodings which cannot encode mu
173
 
    bad_encodings = [
174
 
        'ascii',
175
 
        'iso-8859-2',
176
 
        'koi8_r',
177
 
    ]
178
 
 
179
 
    def setUp(self):
180
 
        TestCaseInTempDir.setUp(self)
181
 
        self.user_encoding = bzrlib.user_encoding
182
 
 
183
 
    def tearDown(self):
184
 
        bzrlib.user_encoding = self.user_encoding
185
 
        TestCaseInTempDir.tearDown(self)
186
 
 
187
 
    def create_branch(self):
188
 
        bzr = self.run_bzr
189
 
        bzr('init')
190
 
        open('a', 'wb').write('some stuff\n')
191
 
        bzr('add', 'a')
192
 
        bzr('commit', '-m', self._message)
193
 
 
194
 
    def try_encoding(self, encoding, fail=False):
195
 
        bzr = self.run_bzr
196
 
        if fail:
197
 
            self.assertRaises(UnicodeEncodeError,
198
 
                self._mu.encode, encoding)
199
 
            encoded_msg = self._message.encode(encoding, 'replace')
200
 
        else:
201
 
            encoded_msg = self._message.encode(encoding)
202
 
 
203
 
        old_encoding = bzrlib.user_encoding
204
 
        # This test requires that 'run_bzr' uses the current
205
 
        # bzrlib, because we override user_encoding, and expect
206
 
        # it to be used
207
 
        try:
208
 
            bzrlib.user_encoding = 'ascii'
209
 
            # We should be able to handle any encoding
210
 
            out, err = bzr('log', encoding=encoding)
211
 
            if not fail:
212
 
                # Make sure we wrote mu as we expected it to exist
213
 
                self.assertNotEqual(-1, out.find(encoded_msg))
214
 
                out_unicode = out.decode(encoding)
215
 
                self.assertNotEqual(-1, out_unicode.find(self._message))
216
 
            else:
217
 
                self.assertNotEqual(-1, out.find('Message with ?'))
218
 
        finally:
219
 
            bzrlib.user_encoding = old_encoding
220
 
 
221
 
    def test_log_handles_encoding(self):
222
 
        self.create_branch()
223
 
 
224
 
        for encoding in self.good_encodings:
225
 
            self.try_encoding(encoding)
226
 
 
227
 
    def test_log_handles_bad_encoding(self):
228
 
        self.create_branch()
229
 
 
230
 
        for encoding in self.bad_encodings:
231
 
            self.try_encoding(encoding, fail=True)
232
 
 
233
 
    def test_stdout_encoding(self):
234
 
        bzr = self.run_bzr
235
 
        bzrlib.user_encoding = "cp1251"
236
 
 
237
 
        bzr('init')
238
 
        self.build_tree(['a'])
239
 
        bzr('add', 'a')
240
 
        bzr('commit', '-m', u'\u0422\u0435\u0441\u0442')
241
 
        stdout, stderr = self.run_bzr('log', encoding='cp866')
242
 
 
243
 
        message = stdout.splitlines()[-1]
244
 
 
245
 
        # explanation of the check:
246
 
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
247
 
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
248
 
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
249
 
        # This test should check that output of log command
250
 
        # encoded to sys.stdout.encoding
251
 
        test_in_cp866 = '\x92\xa5\xe1\xe2'
252
 
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
253
 
        # Make sure the log string is encoded in cp866
254
 
        self.assertEquals(test_in_cp866, message[2:])
255
 
        # Make sure the cp1251 string is not found anywhere
256
 
        self.assertEquals(-1, stdout.find(test_in_cp1251))
257