~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
2
# -*- coding: utf-8 -*-
1685.1.76 by Wouter van Heyst
codecleanup
3
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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.
1685.1.76 by Wouter van Heyst
codecleanup
8
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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.
1685.1.76 by Wouter van Heyst
codecleanup
13
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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
1685.1.76 by Wouter van Heyst
codecleanup
18
"""Black-box tests for bzr handling non-ascii characters."""
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
19
20
import sys
21
import os
1685.1.76 by Wouter van Heyst
codecleanup
22
1987.1.2 by John Arbash Meinel
Remove the unneeded _set_user_ignores(['./.bazaar']) now that home has moved
23
from bzrlib import osutils, urlutils
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
24
import bzrlib
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
25
from bzrlib.tests import TestCaseWithTransport, TestSkipped
1185.85.41 by John Arbash Meinel
Changing test_non_ascii.py so that it will keep trying even if it can't encode one piece.
26
from bzrlib.trace import mutter, note
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
27
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
28
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
29
class TestNonAscii(TestCaseWithTransport):
1185.85.67 by John Arbash Meinel
Starting work on a test adapter for multiple encodings.
30
    """Test that bzr handles files/committers/etc which are non-ascii."""
31
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
32
    def setUp(self):
33
        super(TestNonAscii, self).setUp()
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
34
        self._orig_email = os.environ.get('BZR_EMAIL', None)
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
35
        self._orig_encoding = bzrlib.user_encoding
36
37
        bzrlib.user_encoding = self.encoding
38
        email = self.info['committer'] + ' <joe@foo.com>'
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
39
        os.environ['BZR_EMAIL'] = email.encode(bzrlib.user_encoding)
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
40
        self.create_base()
41
42
    def tearDown(self):
43
        if self._orig_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
44
            os.environ['BZR_EMAIL'] = self._orig_email
1185.85.41 by John Arbash Meinel
Changing test_non_ascii.py so that it will keep trying even if it can't encode one piece.
45
        else:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
46
            if os.environ.get('BZR_EMAIL', None) is not None:
47
                del os.environ['BZR_EMAIL']
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
48
        bzrlib.user_encoding = self._orig_encoding
49
        super(TestNonAscii, self).tearDown()
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
50
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
51
    def create_base(self):
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
52
        bzr = self.run_bzr
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
53
1685.1.57 by Martin Pool
[broken] Skip unicode blackbox tests if not supported by filesystem
54
        fs_enc = sys.getfilesystemencoding()
1711.4.11 by John Arbash Meinel
Skip non_ascii tests that won't write properly to the screen
55
        terminal_enc = osutils.get_terminal_encoding()
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
56
        fname = self.info['filename']
1685.1.57 by Martin Pool
[broken] Skip unicode blackbox tests if not supported by filesystem
57
        dir_name = self.info['directory']
58
        for thing in [fname, dir_name]:
59
            try:
60
                thing.encode(fs_enc)
61
            except UnicodeEncodeError:
62
                raise TestSkipped(('Unable to represent path %r'
1711.4.11 by John Arbash Meinel
Skip non_ascii tests that won't write properly to the screen
63
                                   ' in filesystem encoding "%s"')
1685.1.57 by Martin Pool
[broken] Skip unicode blackbox tests if not supported by filesystem
64
                                    % (thing, fs_enc))
1711.4.11 by John Arbash Meinel
Skip non_ascii tests that won't write properly to the screen
65
            try:
66
                thing.encode(terminal_enc)
67
            except UnicodeEncodeError:
68
                raise TestSkipped(('Unable to represent path %r'
69
                                   ' in terminal encoding "%s"'
70
                                   ' (even though it is valid in'
71
                                   ' filesystem encoding "%s")')
72
                                   % (thing, terminal_enc, fs_enc))
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
73
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
74
        wt = self.make_branch_and_tree('.')
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
75
        open('a', 'wb').write('foo\n')
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
76
        wt.add('a')
77
        wt.commit('adding a')
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
78
79
        open('b', 'wb').write('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
80
        wt.add('b')
81
        wt.commit(self.info['message'])
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
82
1685.1.57 by Martin Pool
[broken] Skip unicode blackbox tests if not supported by filesystem
83
        open(fname, 'wb').write('unicode filename\n')
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
84
        wt.add(fname)
85
        wt.commit(u'And a unicode file\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
86
        self.wt = wt
1185.85.66 by John Arbash Meinel
Adding test for swedish
87
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
88
    def test_status(self):
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
89
        bzr = self.run_bzr_decode
90
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
91
        open(self.info['filename'], 'ab').write('added something\n')
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
92
        txt = bzr('status')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
93
        self.assertEqual(u'modified:\n  %s\n' % (self.info['filename'],), txt)
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
94
1685.1.76 by Wouter van Heyst
codecleanup
95
        txt = bzr('status', encoding='ascii')
96
        expected = u'modified:\n  %s\n' % (
97
                    self.info['filename'].encode('ascii', 'replace'),)
98
        self.assertEqual(expected, txt)
99
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
100
    def test_cat(self):
101
        # bzr cat shouldn't change the contents
102
        # using run_bzr since that doesn't decode
103
        txt = self.run_bzr('cat', 'b')[0]
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
104
        self.assertEqual('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n', txt)
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
105
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
106
        txt = self.run_bzr('cat', self.info['filename'])[0]
1185.85.41 by John Arbash Meinel
Changing test_non_ascii.py so that it will keep trying even if it can't encode one piece.
107
        self.assertEqual('unicode filename\n', txt)
1185.85.17 by John Arbash Meinel
switching to using the default encoding instead of utf-8
108
109
    def test_cat_revision(self):
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
110
        bzr = self.run_bzr_decode
111
1185.85.72 by John Arbash Meinel
Fix some of the tests.
112
        committer = self.info['committer']
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
113
        txt = bzr('cat-revision', '-r', '1')
1185.85.72 by John Arbash Meinel
Fix some of the tests.
114
        self.failUnless(committer in txt,
115
                        'failed to find %r in %r' % (committer, txt))
1185.85.17 by John Arbash Meinel
switching to using the default encoding instead of utf-8
116
1185.85.72 by John Arbash Meinel
Fix some of the tests.
117
        msg = self.info['message']
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
118
        txt = bzr('cat-revision', '-r', '2')
1185.85.72 by John Arbash Meinel
Fix some of the tests.
119
        self.failUnless(msg in txt, 'failed to find %r in %r' % (msg, txt))
1185.85.18 by John Arbash Meinel
Updated mkdir, added to test_log
120
121
    def test_mkdir(self):
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
122
        bzr = self.run_bzr_decode
123
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
124
        txt = bzr('mkdir', self.info['directory'])
125
        self.assertEqual(u'added %s\n' % self.info['directory'], txt)
126
127
        # The text should be garbled, but the command should succeed
128
        txt = bzr('mkdir', self.info['directory'] + '2', encoding='ascii')
129
        expected = u'added %s2\n' % (self.info['directory'],)
130
        expected = expected.encode('ascii', 'replace')
131
        self.assertEqual(expected, txt)
1185.85.19 by John Arbash Meinel
Updated bzr relpath
132
133
    def test_relpath(self):
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
134
        bzr = self.run_bzr_decode
135
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
136
        txt = bzr('relpath', self.info['filename'])
137
        self.assertEqual(self.info['filename'] + '\n', txt)
1185.85.19 by John Arbash Meinel
Updated bzr relpath
138
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
139
        bzr('relpath', self.info['filename'], encoding='ascii', retcode=3)
1185.85.22 by John Arbash Meinel
Updated cmd_inventory. Changing from having each Command request an encoded stdout to providing one before calling run()
140
141
    def test_inventory(self):
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
142
        bzr = self.run_bzr_decode
143
144
        txt = bzr('inventory')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
145
        self.assertEqual(['a', 'b', self.info['filename']],
1185.85.22 by John Arbash Meinel
Updated cmd_inventory. Changing from having each Command request an encoded stdout to providing one before calling run()
146
                         txt.splitlines())
147
1185.85.23 by John Arbash Meinel
Adding more inventory tests.
148
        # inventory should fail if unable to encode
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
149
        bzr('inventory', encoding='ascii', retcode=3)
1185.85.23 by John Arbash Meinel
Adding more inventory tests.
150
151
        # We don't really care about the ids themselves,
152
        # but the command shouldn't fail
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
153
        txt = bzr('inventory', '--show-ids')
154
155
    def test_revno(self):
156
        # There isn't a lot to test here, since revno should always
157
        # be an integer
158
        bzr = self.run_bzr_decode
159
160
        self.assertEqual('3\n', bzr('revno'))
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
161
        self.assertEqual('3\n', bzr('revno', encoding='ascii'))
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
162
163
    def test_revision_info(self):
164
        bzr = self.run_bzr_decode
165
166
        bzr('revision-info', '-r', '1')
167
1685.1.76 by Wouter van Heyst
codecleanup
168
        # TODO: jam 20060105 If we support revisions with non-ascii characters,
169
        # this should be strict and fail.
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
170
        bzr('revision-info', '-r', '1', encoding='ascii')
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
171
172
    def test_mv(self):
173
        bzr = self.run_bzr_decode
174
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
175
        fname1 = self.info['filename']
176
        fname2 = self.info['filename'] + '2'
177
        dirname = self.info['directory']
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
178
1685.1.76 by Wouter van Heyst
codecleanup
179
        # fname1 already exists
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
180
        bzr('mv', 'a', fname1, retcode=3)
181
182
        txt = bzr('mv', 'a', fname2)
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
183
        self.assertEqual(u'a => %s\n' % fname2, txt)
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
184
        self.failIfExists('a')
185
        self.failUnlessExists(fname2)
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
186
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
187
        # After 'mv' we need to re-open the working tree
188
        self.wt = self.wt.bzrdir.open_workingtree()
189
        self.wt.commit('renamed to non-ascii')
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
190
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
191
        os.mkdir(dirname)
192
        self.wt.add(dirname)
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
193
        txt = bzr('mv', fname1, fname2, dirname)
194
        self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
195
                          u'%s => %s/%s' % (fname2, dirname, fname2)]
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
196
                         , txt.splitlines())
197
198
        # The rename should still succeed
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
199
        newpath = u'%s/%s' % (dirname, fname2)
200
        txt = bzr('mv', newpath, 'a', encoding='ascii')
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
201
        self.failUnlessExists('a')
1685.1.2 by John Arbash Meinel
Re-enabling the non_ascii tests after fixing trace.py, bzr ignore also does the right thing now
202
        self.assertEqual(newpath.encode('ascii', 'replace') + ' => a\n', txt)
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
203
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
204
    def test_branch(self):
205
        # We should be able to branch into a directory that
206
        # has a unicode name, even if we can't display the name
207
        bzr = self.run_bzr_decode
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
208
        bzr('branch', u'.', self.info['directory'])
209
        bzr('branch', u'.', self.info['directory'] + '2', encoding='ascii')
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
210
211
    def test_pull(self):
212
        # Make sure we can pull from paths that can't be encoded
213
        bzr = self.run_bzr_decode
214
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
215
        dirname1 = self.info['directory']
216
        dirname2 = self.info['directory'] + '2'
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
217
        url1 = urlutils.local_path_to_url(dirname1)
218
        url2 = urlutils.local_path_to_url(dirname2)
219
        out_bzrdir = self.wt.bzrdir.sprout(url1)
220
        out_bzrdir.sprout(url2)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
221
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
222
        os.chdir(dirname1)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
223
        open('a', 'ab').write('more text\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
224
        self.wt.commit('mod a')
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
225
1711.4.9 by John Arbash Meinel
In general, python on win32 needs to use the unicode os api, because bytestream stuff just doesn't work.
226
        pwd = osutils.getcwd()
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
227
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
228
        os.chdir(u'../' + dirname2)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
229
        txt = bzr('pull')
230
1685.1.37 by John Arbash Meinel
builtins now use urlfordisplay to display nicer paths to the user.
231
        self.assertEqual(u'Using saved location: %s/\n' % (pwd,), txt)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
232
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
233
        os.chdir('../' + dirname1)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
234
        open('a', 'ab').write('and yet more\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
235
        self.wt.commit(u'modifying a by ' + self.info['committer'])
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
236
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
237
        os.chdir('../' + dirname2)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
238
        # We should be able to pull, even if our encoding is bad
239
        bzr('pull', '--verbose', encoding='ascii')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
240
241
    def test_push(self):
242
        # TODO: Test push to an SFTP location
243
        # Make sure we can pull from paths that can't be encoded
244
        bzr = self.run_bzr_decode
245
1685.1.24 by John Arbash Meinel
cmd_push should use URLs throughout.
246
        # TODO: jam 20060427 For drastically improving performance, we probably
247
        #       could create a local repository, so it wouldn't have to copy
248
        #       the files around as much.
249
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
250
        dirname = self.info['directory']
251
        bzr('push', dirname)
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
252
253
        open('a', 'ab').write('adding more text\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
254
        self.wt.commit('added some stuff')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
255
1685.1.76 by Wouter van Heyst
codecleanup
256
        # TODO: check the output text is properly encoded
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
257
        bzr('push')
258
259
        f = open('a', 'ab')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
260
        try:
261
            f.write('and a bit more: ')
262
            f.write(dirname.encode('utf-8'))
263
            f.write('\n')
264
        finally:
265
            f.close()
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
266
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
267
        self.wt.commit('Added some ' + dirname)
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
268
        bzr('push', '--verbose', encoding='ascii')
269
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
270
        bzr('push', '--verbose', dirname + '2')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
271
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
272
        bzr('push', '--verbose', dirname + '3', encoding='ascii')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
273
1685.1.24 by John Arbash Meinel
cmd_push should use URLs throughout.
274
        bzr('push', '--verbose', '--create-prefix', dirname + '4/' + dirname + '5')
275
        bzr('push', '--verbose', '--create-prefix', dirname + '6/' + dirname + '7', encoding='ascii')
276
1185.85.32 by John Arbash Meinel
Updated bzr renames
277
    def test_renames(self):
278
        bzr = self.run_bzr_decode
279
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
280
        fname = self.info['filename'] + '2'
1185.85.32 by John Arbash Meinel
Updated bzr renames
281
        bzr('mv', 'a', fname)
282
        txt = bzr('renames')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
283
        self.assertEqual(u'a => %s\n' % fname, txt)
1185.85.32 by John Arbash Meinel
Updated bzr renames
284
285
        bzr('renames', retcode=3, encoding='ascii')
286
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
287
    def test_remove(self):
288
        bzr = self.run_bzr_decode
289
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
290
        fname = self.info['filename']
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
291
        txt = bzr('remove', fname, encoding='ascii')
292
293
    def test_remove_verbose(self):
294
        bzr = self.run_bzr_decode
295
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
296
        fname = self.info['filename']
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
297
        txt = bzr('remove', '--verbose', fname, encoding='ascii')
298
1185.85.34 by John Arbash Meinel
Updating 'bzr file-id' exposed that we weren't allowing unicode file ids. Enabling them reveals a lot more bugs.
299
    def test_file_id(self):
300
        bzr = self.run_bzr_decode
301
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
302
        fname = self.info['filename']
1185.85.34 by John Arbash Meinel
Updating 'bzr file-id' exposed that we weren't allowing unicode file ids. Enabling them reveals a lot more bugs.
303
        txt = bzr('file-id', fname)
304
1185.85.35 by John Arbash Meinel
Updated file-path
305
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
306
        #       so there is nothing which would fail in ascii encoding
307
        #       This *should* be retcode=3
1185.85.34 by John Arbash Meinel
Updating 'bzr file-id' exposed that we weren't allowing unicode file ids. Enabling them reveals a lot more bugs.
308
        txt = bzr('file-id', fname, encoding='ascii')
309
1185.85.35 by John Arbash Meinel
Updated file-path
310
    def test_file_path(self):
311
        bzr = self.run_bzr_decode
312
313
        # Create a directory structure
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
314
        fname = self.info['filename']
1185.85.72 by John Arbash Meinel
Fix some of the tests.
315
        dirname = self.info['directory']
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
316
        os.mkdir('base')
317
        os.mkdir('base/' + dirname)
318
        self.wt.add('base')
319
        self.wt.add('base/'+dirname)
1185.85.72 by John Arbash Meinel
Fix some of the tests.
320
        path = '/'.join(['base', dirname, fname])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
321
        self.wt.rename_one(fname, path)
322
        self.wt.commit('moving things around')
1185.85.35 by John Arbash Meinel
Updated file-path
323
324
        txt = bzr('file-path', path)
325
326
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
327
        #       so there is nothing which would fail in ascii encoding
328
        #       This *should* be retcode=3
329
        txt = bzr('file-path', path, encoding='ascii')
1185.85.34 by John Arbash Meinel
Updating 'bzr file-id' exposed that we weren't allowing unicode file ids. Enabling them reveals a lot more bugs.
330
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
331
    def test_revision_history(self):
332
        bzr = self.run_bzr_decode
333
334
        # TODO: jam 20060106 We don't support non-ascii revision ids yet, 
335
        #       so there is nothing which would fail in ascii encoding
336
        txt = bzr('revision-history')
337
338
    def test_ancestry(self):
339
        bzr = self.run_bzr_decode
340
341
        # TODO: jam 20060106 We don't support non-ascii revision ids yet, 
342
        #       so there is nothing which would fail in ascii encoding
343
        txt = bzr('ancestry')
344
345
    def test_diff(self):
346
        # TODO: jam 20060106 diff is a difficult one to test, because it 
347
        #       shouldn't encode the file contents, but it needs some sort
348
        #       of encoding for the paths, etc which are displayed.
1685.1.78 by Wouter van Heyst
more code cleanup
349
        open(self.info['filename'], 'ab').write('newline\n')
350
        txt = self.run_bzr('diff', retcode=1)[0]
1185.85.41 by John Arbash Meinel
Changing test_non_ascii.py so that it will keep trying even if it can't encode one piece.
351
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
352
    def test_deleted(self):
353
        bzr = self.run_bzr_decode
354
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
355
        fname = self.info['filename']
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
356
        os.remove(fname)
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
357
        self.wt.remove(fname)
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
358
359
        txt = bzr('deleted')
360
        self.assertEqual(fname+'\n', txt)
361
362
        txt = bzr('deleted', '--show-ids')
363
        self.failUnless(txt.startswith(fname))
364
1185.85.51 by John Arbash Meinel
Adding tests to make sure deleted and modified fail if cannot encode names.
365
        # Deleted should fail if cannot decode
366
        # Because it is giving the exact paths
367
        # which might be used by a front end
368
        bzr('deleted', encoding='ascii', retcode=3)
369
1185.85.50 by John Arbash Meinel
Updated cmd_modified
370
    def test_modified(self):
371
        bzr = self.run_bzr_decode
372
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
373
        fname = self.info['filename']
1185.85.50 by John Arbash Meinel
Updated cmd_modified
374
        open(fname, 'ab').write('modified\n')
375
376
        txt = bzr('modified')
377
        self.assertEqual(fname+'\n', txt)
378
1185.85.51 by John Arbash Meinel
Adding tests to make sure deleted and modified fail if cannot encode names.
379
        bzr('modified', encoding='ascii', retcode=3)
380
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
381
    def test_added(self):
382
        bzr = self.run_bzr_decode
383
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
384
        fname = self.info['filename'] + '2'
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
385
        open(fname, 'wb').write('added\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
386
        self.wt.add(fname)
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
387
388
        txt = bzr('added')
389
        self.assertEqual(fname+'\n', txt)
390
391
        bzr('added', encoding='ascii', retcode=3)
392
1185.85.53 by John Arbash Meinel
Updated cmd_root
393
    def test_root(self):
394
        bzr = self.run_bzr_decode
395
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
396
        dirname = self.info['directory']
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
397
        url = urlutils.local_path_to_url(dirname)
1185.85.53 by John Arbash Meinel
Updated cmd_root
398
        bzr('root')
399
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
400
        self.wt.bzrdir.sprout(url)
1185.85.53 by John Arbash Meinel
Updated cmd_root
401
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
402
        os.chdir(dirname)
1185.85.53 by John Arbash Meinel
Updated cmd_root
403
404
        txt = bzr('root')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
405
        self.failUnless(txt.endswith(dirname+'\n'))
1185.85.53 by John Arbash Meinel
Updated cmd_root
406
407
        txt = bzr('root', encoding='ascii', retcode=3)
408
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
409
    def test_log(self):
410
        bzr = self.run_bzr_decode
411
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
412
        fname = self.info['filename']
413
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
414
        txt = bzr('log')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
415
        self.assertNotEqual(-1, txt.find(self.info['committer']))
416
        self.assertNotEqual(-1, txt.find(self.info['message']))
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
417
418
        txt = bzr('log', '--verbose')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
419
        self.assertNotEqual(-1, txt.find(fname))
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
420
421
        # Make sure log doesn't fail even if we can't write out
422
        txt = bzr('log', '--verbose', encoding='ascii')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
423
        self.assertEqual(-1, txt.find(fname))
424
        self.assertNotEqual(-1, txt.find(fname.encode('ascii', 'replace')))
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
425
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
426
    def test_touching_revisions(self):
427
        bzr = self.run_bzr_decode
428
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
429
        fname = self.info['filename']
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
430
        txt = bzr('touching-revisions', fname)
431
        self.assertEqual(u'     3 added %s\n' % (fname,), txt)
432
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
433
        fname2 = self.info['filename'] + '2'
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
434
        self.wt.rename_one(fname, fname2)
435
        self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
436
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
437
        txt = bzr('touching-revisions', fname2)
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
438
        expected_txt = (u'     3 added %s\n' 
439
                        u'     4 renamed %s => %s\n'
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
440
                        % (fname, fname, fname2))
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
441
        self.assertEqual(expected_txt, txt)
442
1685.1.78 by Wouter van Heyst
more code cleanup
443
        bzr('touching-revisions', fname2, encoding='ascii', retcode=3)
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
444
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
445
    def test_ls(self):
446
        bzr = self.run_bzr_decode
447
448
        txt = bzr('ls')
1830.3.10 by John Arbash Meinel
Don't compare direct output of ls, sort first
449
        self.assertEqual(sorted(['a', 'b', self.info['filename']]),
450
                         sorted(txt.splitlines()))
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
451
        txt = bzr('ls', '--null')
1830.3.10 by John Arbash Meinel
Don't compare direct output of ls, sort first
452
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
453
                         sorted(txt.split('\0')))
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
454
455
        txt = bzr('ls', encoding='ascii', retcode=3)
456
        txt = bzr('ls', '--null', encoding='ascii', retcode=3)
457
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
458
    def test_unknowns(self):
459
        bzr = self.run_bzr_decode
460
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
461
        fname = self.info['filename'] + '2'
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
462
        open(fname, 'wb').write('unknown\n')
463
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
464
        # TODO: jam 20060112 bzr unknowns is the only one which 
465
        #       quotes paths do we really want it to?
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
466
        txt = bzr('unknowns')
467
        self.assertEqual(u'"%s"\n' % (fname,), txt)
468
469
        bzr('unknowns', encoding='ascii', retcode=3)
470
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
471
    def test_ignore(self):
472
        bzr = self.run_bzr_decode
473
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
474
        fname2 = self.info['filename'] + '2.txt'
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
475
        open(fname2, 'wb').write('ignored\n')
476
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
477
        def check_unknowns(expected):
478
            self.assertEqual(expected, list(self.wt.unknowns()))
479
480
        check_unknowns([fname2])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
481
482
        bzr('ignore', './' + fname2)
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
483
        # After 'ignore' you must re-open the working tree
484
        self.wt = self.wt.bzrdir.open_workingtree()
485
        check_unknowns([])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
486
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
487
        fname3 = self.info['filename'] + '3.txt'
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
488
        open(fname3, 'wb').write('unknown 3\n')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
489
        check_unknowns([fname3])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
490
491
        # Ignore should not care what the encoding is
492
        # (right now it doesn't print anything)
493
        bzr('ignore', fname3, encoding='ascii')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
494
        self.wt = self.wt.bzrdir.open_workingtree()
495
        check_unknowns([])
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
496
497
        # Now try a wildcard match
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
498
        fname4 = self.info['filename'] + '4.txt'
499
        open(fname4, 'wb').write('unknown 4\n')
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
500
        bzr('ignore', '*.txt')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
501
        self.wt = self.wt.bzrdir.open_workingtree()
502
        check_unknowns([])
1185.85.53 by John Arbash Meinel
Updated cmd_root
503
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
504
        # and a different wildcard that matches everything
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
505
        os.remove('.bzrignore')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
506
        bzr('ignore', self.info['filename'] + '*')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
507
        self.wt = self.wt.bzrdir.open_workingtree()
508
        check_unknowns([])
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
509
1816.1.1 by Alexander Belchenko
blackbox test for non-ascii behaviour of missing command
510
    def test_missing(self):
511
        bzr = self.run_bzr_decode
512
513
        # create empty tree as reference for missing
514
        self.run_bzr('init', 'empty-tree')
515
516
        msg = self.info['message']
517
518
        txt = bzr('missing', 'empty-tree', retcode=1)
519
        self.assertNotEqual(-1, txt.find(self.info['committer']))
520
        self.assertNotEqual(-1, txt.find(msg))
521
522
        # Make sure missing doesn't fail even if we can't write out
523
        txt = bzr('missing', 'empty-tree', encoding='ascii', retcode=1)
524
        self.assertEqual(-1, txt.find(msg))
525
        self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))