~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1685.1.76 by Wouter van Heyst
codecleanup
2
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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.76 by Wouter van Heyst
codecleanup
7
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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.76 by Wouter van Heyst
codecleanup
12
#
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
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
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
16
1685.1.76 by Wouter van Heyst
codecleanup
17
"""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
18
19
import os
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
20
import sys
1685.1.76 by Wouter van Heyst
codecleanup
21
4498.4.1 by Vincent Ladeuil
Various cleanups.
22
from bzrlib import (
23
    osutils,
24
    tests,
25
    urlutils,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
26
    )
5168.1.5 by Vincent Ladeuil
EncondigAdapter is a module despite the camelcase name.
27
from bzrlib.tests import EncodingAdapter
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
28
from bzrlib.tests.scenarios import load_tests_apply_scenarios
29
30
31
load_tests = load_tests_apply_scenarios
4498.4.1 by Vincent Ladeuil
Various cleanups.
32
33
34
class TestNonAscii(tests.TestCaseWithTransport):
1185.85.67 by John Arbash Meinel
Starting work on a test adapter for multiple encodings.
35
    """Test that bzr handles files/committers/etc which are non-ascii."""
36
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
37
    scenarios = EncodingAdapter.encoding_scenarios
38
1185.85.10 by John Arbash Meinel
Adding a test case which uses non-ascii characters for email, filename, and commit message
39
    def setUp(self):
40
        super(TestNonAscii, self).setUp()
4920.1.1 by Martin
Change bb.test_non_ascii tests to skip earlier and use addCleanup, as tearDown semantics have changed with testtools
41
        self._check_can_encode_paths()
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
42
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
43
        self.overrideAttr(osutils, '_cached_user_encoding', self.encoding)
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
44
        email = self.info['committer'] + ' <joe@foo.com>'
5570.3.9 by Vincent Ladeuil
More use cases for overrideEnv, _cleanEnvironment *may* contain too much variables now.
45
        self.overrideEnv('BZR_EMAIL', email.encode(osutils.get_user_encoding()))
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
46
        self.create_base()
47
2823.2.4 by Daniel Watkins
Added 'working_dir' to 'run_bzr_decode'.
48
    def run_bzr_decode(self, args, encoding=None, fail=False, retcode=None,
4498.4.1 by Vincent Ladeuil
Various cleanups.
49
                       working_dir=None):
2830.3.1 by Martin Pool
Make run_bzr_decode undeprecated again, but put it in the particular test class
50
        """Run bzr and decode the output into a particular encoding.
51
52
        Returns a string containing the stdout output from bzr.
53
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
54
        :param fail: If true, the operation is expected to fail with
2830.3.1 by Martin Pool
Make run_bzr_decode undeprecated again, but put it in the particular test class
55
            a UnicodeError.
56
        """
57
        if encoding is None:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
58
            encoding = osutils.get_user_encoding()
2830.3.1 by Martin Pool
Make run_bzr_decode undeprecated again, but put it in the particular test class
59
        try:
4498.4.1 by Vincent Ladeuil
Various cleanups.
60
            out = self.run_bzr(args,
61
                               output_encoding=encoding, encoding=encoding,
62
                               retcode=retcode, working_dir=working_dir)[0]
2830.3.1 by Martin Pool
Make run_bzr_decode undeprecated again, but put it in the particular test class
63
            return out.decode(encoding)
64
        except UnicodeError, e:
65
            if not fail:
66
                raise
67
        else:
68
            # This command, run from the regular command line, will give a
69
            # traceback to the user.  That's not really good for a situation
70
            # that can be provoked just by the interaction of their input data
71
            # and locale, as some of these are.  What would be better?
72
            if fail:
73
                self.fail("Expected UnicodeError not raised")
74
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
75
    def _check_OSX_can_roundtrip(self, path, fs_enc=None):
76
        """Stop the test if it's about to fail or errors out.
77
78
        Until we get proper support on OSX for accented paths (in fact, any
79
        path whose NFD decomposition is different than the NFC one), this is
80
        the best way to keep test active (as opposed to disabling them
81
        completely). This is a stop gap. The tests should at least be rewritten
4498.4.5 by Vincent Ladeuil
Fix comment.
82
        so that the failing ones are clearly separated from the passing ones.
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
83
        """
84
        if fs_enc is None:
85
            fs_enc = osutils._fs_enc
86
        if sys.platform == 'darwin':
87
            encoded = path.encode(fs_enc)
88
            import unicodedata
89
            normal_thing = unicodedata.normalize('NFD', path)
90
            mac_encoded = normal_thing.encode(fs_enc)
91
            if mac_encoded != encoded:
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
92
                self.knownFailure(
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
93
                    'Unable to roundtrip path %r on OSX filesystem'
94
                    ' using encoding "%s"'
95
                    % (path, fs_enc))
96
4920.1.1 by Martin
Change bb.test_non_ascii tests to skip earlier and use addCleanup, as tearDown semantics have changed with testtools
97
    def _check_can_encode_paths(self):
4498.4.1 by Vincent Ladeuil
Various cleanups.
98
        fs_enc = osutils._fs_enc
1711.4.11 by John Arbash Meinel
Skip non_ascii tests that won't write properly to the screen
99
        terminal_enc = osutils.get_terminal_encoding()
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
100
        fname = self.info['filename']
1685.1.57 by Martin Pool
[broken] Skip unicode blackbox tests if not supported by filesystem
101
        dir_name = self.info['directory']
102
        for thing in [fname, dir_name]:
103
            try:
104
                thing.encode(fs_enc)
105
            except UnicodeEncodeError:
4498.4.1 by Vincent Ladeuil
Various cleanups.
106
                raise tests.TestSkipped(
107
                    'Unable to represent path %r in filesystem encoding "%s"'
108
                    % (thing, fs_enc))
1711.4.11 by John Arbash Meinel
Skip non_ascii tests that won't write properly to the screen
109
            try:
110
                thing.encode(terminal_enc)
111
            except UnicodeEncodeError:
4498.4.1 by Vincent Ladeuil
Various cleanups.
112
                raise tests.TestSkipped(
113
                    'Unable to represent path %r in terminal encoding "%s"'
114
                    ' (even though it is valid in filesystem encoding "%s")'
115
                    % (thing, terminal_enc, fs_enc))
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
116
4920.1.1 by Martin
Change bb.test_non_ascii tests to skip earlier and use addCleanup, as tearDown semantics have changed with testtools
117
    def create_base(self):
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
118
        wt = self.make_branch_and_tree('.')
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
119
        self.build_tree_contents([('a', 'foo\n')])
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
120
        wt.add('a')
121
        wt.commit('adding a')
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
122
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
123
        self.build_tree_contents(
124
            [('b', '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
125
        wt.add('b')
126
        wt.commit(self.info['message'])
1685.1.74 by Wouter van Heyst
fix nonascii tests to run properly under LANG=C
127
4920.1.1 by Martin
Change bb.test_non_ascii tests to skip earlier and use addCleanup, as tearDown semantics have changed with testtools
128
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
129
        self.build_tree_contents([(fname, 'unicode filename\n')])
1836.2.1 by John Arbash Meinel
Switch setup to use internals rather than run_bzr
130
        wt.add(fname)
131
        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.
132
        self.wt = wt
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
133
        # FIXME: We don't check that the add went well, in fact, it doesn't on
134
        # OSX (when LC_ALL is set correctly) because the added path doesn't
135
        # match the one used on OSX. But checking here will require more
136
        # invasive changes than adding the _check_OSX_can_roundtrip(), so I
137
        # punt for now -- vila 20090702
1185.85.66 by John Arbash Meinel
Adding test for swedish
138
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
139
    def test_status(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
140
        self.build_tree_contents(
141
            [(self.info['filename'], 'changed something\n')])
142
        txt = self.run_bzr_decode('status')
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
143
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
144
        self.assertEqual(u'modified:\n  %s\n' % (self.info['filename'],), txt)
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
145
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
146
        txt = self.run_bzr_decode('status', encoding='ascii')
1685.1.76 by Wouter van Heyst
codecleanup
147
        expected = u'modified:\n  %s\n' % (
148
                    self.info['filename'].encode('ascii', 'replace'),)
149
        self.assertEqual(expected, txt)
150
1185.85.15 by John Arbash Meinel
Updated bzr status, adding test_cat
151
    def test_cat(self):
152
        # bzr cat shouldn't change the contents
153
        # using run_bzr since that doesn't decode
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
154
        txt = self.run_bzr('cat b')[0]
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
155
        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
156
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
157
        self._check_OSX_can_roundtrip(self.info['filename'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
158
        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.
159
        self.assertEqual('unicode filename\n', txt)
1185.85.17 by John Arbash Meinel
switching to using the default encoding instead of utf-8
160
161
    def test_cat_revision(self):
1185.85.72 by John Arbash Meinel
Fix some of the tests.
162
        committer = self.info['committer']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
163
        txt = self.run_bzr_decode('cat-revision -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
164
        self.assertTrue(committer in txt,
1185.85.72 by John Arbash Meinel
Fix some of the tests.
165
                        '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
166
1185.85.72 by John Arbash Meinel
Fix some of the tests.
167
        msg = self.info['message']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
168
        txt = self.run_bzr_decode('cat-revision -r 2')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
169
        self.assertTrue(msg in txt, 'failed to find %r in %r' % (msg, txt))
1185.85.18 by John Arbash Meinel
Updated mkdir, added to test_log
170
171
    def test_mkdir(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
172
        txt = self.run_bzr_decode(['mkdir', self.info['directory']])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
173
        self.assertEqual(u'added %s\n' % self.info['directory'], txt)
174
175
        # The text should be garbled, but the command should succeed
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
176
        txt = self.run_bzr_decode(['mkdir', self.info['directory'] + '2'],
177
                                  encoding='ascii')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
178
        expected = u'added %s2\n' % (self.info['directory'],)
179
        expected = expected.encode('ascii', 'replace')
180
        self.assertEqual(expected, txt)
1185.85.19 by John Arbash Meinel
Updated bzr relpath
181
182
    def test_relpath(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
183
        txt = self.run_bzr_decode(['relpath', self.info['filename']])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
184
        self.assertEqual(self.info['filename'] + '\n', txt)
1185.85.19 by John Arbash Meinel
Updated bzr relpath
185
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
186
        self.run_bzr_decode(['relpath', self.info['filename']],
2823.2.2 by Daniel Watkins
Merged bzr.dev.
187
                            encoding='ascii', fail=True)
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()
188
189
    def test_inventory(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
190
        txt = self.run_bzr_decode('inventory')
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
191
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
192
        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()
193
                         txt.splitlines())
194
1185.85.23 by John Arbash Meinel
Adding more inventory tests.
195
        # inventory should fail if unable to encode
2823.2.2 by Daniel Watkins
Merged bzr.dev.
196
        self.run_bzr_decode('inventory', encoding='ascii', fail=True)
1185.85.23 by John Arbash Meinel
Adding more inventory tests.
197
198
        # We don't really care about the ids themselves,
199
        # but the command shouldn't fail
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
200
        txt = self.run_bzr_decode('inventory --show-ids')
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
201
202
    def test_revno(self):
203
        # There isn't a lot to test here, since revno should always
204
        # be an integer
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
205
        self.assertEqual('3\n', self.run_bzr_decode('revno'))
206
        self.assertEqual('3\n', self.run_bzr_decode('revno', encoding='ascii'))
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
207
208
    def test_revision_info(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
209
        self.run_bzr_decode('revision-info -r 1')
1185.85.24 by John Arbash Meinel
Moved run_bzr_decode into TestCase
210
1685.1.76 by Wouter van Heyst
codecleanup
211
        # TODO: jam 20060105 If we support revisions with non-ascii characters,
212
        # this should be strict and fail.
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
213
        self.run_bzr_decode('revision-info -r 1', encoding='ascii')
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
214
215
    def test_mv(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
216
        fname1 = self.info['filename']
217
        fname2 = self.info['filename'] + '2'
218
        dirname = self.info['directory']
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
219
1685.1.76 by Wouter van Heyst
codecleanup
220
        # fname1 already exists
2823.2.2 by Daniel Watkins
Merged bzr.dev.
221
        self.run_bzr_decode(['mv', 'a', fname1], fail=True)
1185.85.26 by John Arbash Meinel
bzr mv should succeed even if it can't display the paths.
222
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
223
        txt = self.run_bzr_decode(['mv', 'a', fname2])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
224
        self.assertEqual(u'a => %s\n' % fname2, txt)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
225
        self.assertPathDoesNotExist('a')
226
        self.assertPathExists(fname2)
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
227
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
228
        # After 'mv' we need to re-open the working tree
229
        self.wt = self.wt.bzrdir.open_workingtree()
230
        self.wt.commit('renamed to non-ascii')
1185.85.25 by John Arbash Meinel
updated 'bzr mv'
231
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
232
        os.mkdir(dirname)
233
        self.wt.add(dirname)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
234
        txt = self.run_bzr_decode(['mv', fname1, fname2, dirname])
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
235
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
236
        self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
237
                          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.
238
                         , txt.splitlines())
239
240
        # The rename should still succeed
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
241
        newpath = u'%s/%s' % (dirname, fname2)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
242
        txt = self.run_bzr_decode(['mv', newpath, 'a'], encoding='ascii')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
243
        self.assertPathExists('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
244
        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.
245
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
246
    def test_branch(self):
247
        # We should be able to branch into a directory that
248
        # has a unicode name, even if we can't display the name
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
249
        self.run_bzr_decode(['branch', u'.', self.info['directory']])
250
        self.run_bzr_decode(['branch', u'.', self.info['directory'] + '2'],
251
                            encoding='ascii')
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
252
253
    def test_pull(self):
254
        # Make sure we can pull from paths that can't be encoded
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
255
        dirname1 = self.info['directory']
256
        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.
257
        url1 = urlutils.local_path_to_url(dirname1)
258
        url2 = urlutils.local_path_to_url(dirname2)
259
        out_bzrdir = self.wt.bzrdir.sprout(url1)
260
        out_bzrdir.sprout(url2)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
261
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
262
        self.build_tree_contents(
263
            [(osutils.pathjoin(dirname1, "a"), 'different text\n')])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
264
        self.wt.commit('mod a')
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
265
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
266
        txt = self.run_bzr_decode('pull', working_dir=dirname2)
267
268
        expected = osutils.pathjoin(osutils.getcwd(), dirname1)
3596.3.1 by James Westby
Give the user a bit more information about which saved location is being used.
269
        self.assertEqual(u'Using saved parent location: %s/\n'
6112.4.7 by Jelmer Vernooij
Fix tests.
270
                'No revisions or tags to pull.\n' % (expected,), txt)
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
271
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
272
        self.build_tree_contents(
273
            [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
274
        self.wt.commit(u'modifying a by ' + self.info['committer'])
1185.85.27 by John Arbash Meinel
Updated bzr branch and bzr pull
275
276
        # We should be able to pull, even if our encoding is bad
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
277
        self.run_bzr_decode('pull --verbose', encoding='ascii',
278
                            working_dir=dirname2)
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
279
280
    def test_push(self):
281
        # TODO: Test push to an SFTP location
282
        # Make sure we can pull from paths that can't be encoded
1685.1.24 by John Arbash Meinel
cmd_push should use URLs throughout.
283
        # TODO: jam 20060427 For drastically improving performance, we probably
284
        #       could create a local repository, so it wouldn't have to copy
285
        #       the files around as much.
4523.4.18 by John Arbash Meinel
tracked down a few more blackbox test cases that were using push.
286
        # Note that the tests don't actually fail, but if we don't set this
287
        # flag, we end up getting "Lock was not Unlocked" warnings
1685.1.24 by John Arbash Meinel
cmd_push should use URLs throughout.
288
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
289
        dirname = self.info['directory']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
290
        self.run_bzr_decode(['push', dirname])
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
291
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
292
        self.build_tree_contents([('a', 'adding more text\n')])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
293
        self.wt.commit('added some stuff')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
294
1685.1.76 by Wouter van Heyst
codecleanup
295
        # TODO: check the output text is properly encoded
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
296
        self.run_bzr_decode('push')
1185.85.31 by John Arbash Meinel
Updated bzr push, including bringing in the unused --verbose flag.
297
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
298
        self.build_tree_contents(
299
            [('a', 'and a bit more: \n%s\n' % (dirname.encode('utf-8'),))])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
300
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
301
        self.wt.commit('Added some ' + dirname)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
302
        self.run_bzr_decode('push --verbose', encoding='ascii')
303
304
        self.run_bzr_decode(['push', '--verbose', dirname + '2'])
305
306
        self.run_bzr_decode(['push', '--verbose', dirname + '3'],
307
                            encoding='ascii')
308
309
        self.run_bzr_decode(['push', '--verbose', '--create-prefix',
310
                            dirname + '4/' + dirname + '5'])
311
        self.run_bzr_decode(['push', '--verbose', '--create-prefix',
312
                            dirname + '6/' + dirname + '7'], encoding='ascii')
1685.1.24 by John Arbash Meinel
cmd_push should use URLs throughout.
313
1185.85.32 by John Arbash Meinel
Updated bzr renames
314
    def test_renames(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
315
        fname = self.info['filename'] + '2'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
316
        self.wt.rename_one('a', fname)
317
        txt = self.run_bzr_decode('renames')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
318
        self.assertEqual(u'a => %s\n' % fname, txt)
1185.85.32 by John Arbash Meinel
Updated bzr renames
319
2823.2.2 by Daniel Watkins
Merged bzr.dev.
320
        self.run_bzr_decode('renames', fail=True, encoding='ascii')
1185.85.32 by John Arbash Meinel
Updated bzr renames
321
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
322
    def test_remove(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
323
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
324
        txt = self.run_bzr_decode(['remove', fname], encoding='ascii')
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
325
326
    def test_remove_verbose(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
327
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
328
        txt = self.run_bzr_decode(['remove', '--verbose', fname],
329
                                  encoding='ascii')
1185.85.33 by John Arbash Meinel
Updated bzr remove, still remove --verbose still broken.
330
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.
331
    def test_file_id(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
332
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
333
        txt = self.run_bzr_decode(['file-id', fname])
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.
334
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
335
        # TODO: jam 20060106 We don't support non-ascii file ids yet,
1185.85.35 by John Arbash Meinel
Updated file-path
336
        #       so there is nothing which would fail in ascii encoding
337
        #       This *should* be retcode=3
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
338
        txt = self.run_bzr_decode(['file-id', fname], 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.
339
1185.85.35 by John Arbash Meinel
Updated file-path
340
    def test_file_path(self):
341
        # Create a directory structure
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
342
        fname = self.info['filename']
1185.85.72 by John Arbash Meinel
Fix some of the tests.
343
        dirname = self.info['directory']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
344
        self.build_tree_contents([
345
            ('base/', ),
346
            (osutils.pathjoin('base', '%s/' % (dirname,)), )])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
347
        self.wt.add('base')
348
        self.wt.add('base/'+dirname)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
349
        path = osutils.pathjoin('base', dirname, fname)
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
350
        self._check_OSX_can_roundtrip(self.info['filename'])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
351
        self.wt.rename_one(fname, path)
352
        self.wt.commit('moving things around')
1185.85.35 by John Arbash Meinel
Updated file-path
353
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
354
        txt = self.run_bzr_decode(['file-path', path])
1185.85.35 by John Arbash Meinel
Updated file-path
355
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
356
        # TODO: jam 20060106 We don't support non-ascii file ids yet,
1185.85.35 by John Arbash Meinel
Updated file-path
357
        #       so there is nothing which would fail in ascii encoding
358
        #       This *should* be retcode=3
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
359
        txt = self.run_bzr_decode(['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.
360
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
361
    def test_revision_history(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
362
        # TODO: jam 20060106 We don't support non-ascii revision ids yet,
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
363
        #       so there is nothing which would fail in ascii encoding
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
364
        txt = self.run_bzr_decode('revision-history')
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
365
366
    def test_ancestry(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
367
        # TODO: jam 20060106 We don't support non-ascii revision ids yet,
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
368
        #       so there is nothing which would fail in ascii encoding
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
369
        txt = self.run_bzr_decode('ancestry')
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
370
371
    def test_diff(self):
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
372
        self._check_OSX_can_roundtrip(self.info['filename'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
373
        # TODO: jam 20060106 diff is a difficult one to test, because it
1185.85.36 by John Arbash Meinel
Working on tests for revision-history, ancestry, and diff
374
        #       shouldn't encode the file contents, but it needs some sort
375
        #       of encoding for the paths, etc which are displayed.
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
376
        self.build_tree_contents([(self.info['filename'], 'newline\n')])
1685.1.78 by Wouter van Heyst
more code cleanup
377
        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.
378
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
379
    def test_deleted(self):
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
380
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
381
        fname = self.info['filename']
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
382
        os.remove(fname)
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
383
        self.wt.remove(fname)
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
384
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
385
        txt = self.run_bzr_decode('deleted')
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
386
        self.assertEqual(fname+'\n', txt)
387
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
388
        txt = self.run_bzr_decode('deleted --show-ids')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
389
        self.assertTrue(txt.startswith(fname))
1185.85.49 by John Arbash Meinel
Updated cmd_deleted, including adding --show-ids option.
390
1185.85.51 by John Arbash Meinel
Adding tests to make sure deleted and modified fail if cannot encode names.
391
        # Deleted should fail if cannot decode
392
        # Because it is giving the exact paths
393
        # which might be used by a front end
2823.2.2 by Daniel Watkins
Merged bzr.dev.
394
        self.run_bzr_decode('deleted', encoding='ascii', fail=True)
1185.85.51 by John Arbash Meinel
Adding tests to make sure deleted and modified fail if cannot encode names.
395
1185.85.50 by John Arbash Meinel
Updated cmd_modified
396
    def test_modified(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
397
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
398
        self.build_tree_contents([(fname, 'modified\n')])
1185.85.50 by John Arbash Meinel
Updated cmd_modified
399
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
400
        txt = self.run_bzr_decode('modified')
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
401
        self._check_OSX_can_roundtrip(self.info['filename'])
3251.6.3 by Adrian Wilkins
Simplified and fixed test code
402
        self.assertEqual('"'+fname+'"'+'\n', txt)
1185.85.50 by John Arbash Meinel
Updated cmd_modified
403
2823.2.2 by Daniel Watkins
Merged bzr.dev.
404
        self.run_bzr_decode('modified', encoding='ascii', fail=True)
1185.85.51 by John Arbash Meinel
Adding tests to make sure deleted and modified fail if cannot encode names.
405
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
406
    def test_added(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
407
        fname = self.info['filename'] + '2'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
408
        self.build_tree_contents([(fname, 'added\n')])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
409
        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.
410
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
411
        txt = self.run_bzr_decode('added')
3251.6.3 by Adrian Wilkins
Simplified and fixed test code
412
        self.assertEqual('"'+fname+'"'+'\n', txt)
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
413
2823.2.2 by Daniel Watkins
Merged bzr.dev.
414
        self.run_bzr_decode('added', encoding='ascii', fail=True)
1185.85.52 by John Arbash Meinel
Updated cmd_added, which obviously had no tests, because it had a bug in it.
415
1185.85.53 by John Arbash Meinel
Updated cmd_root
416
    def test_root(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
417
        dirname = self.info['directory']
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
418
        url = urlutils.local_path_to_url(dirname)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
419
        self.run_bzr_decode('root')
1185.85.53 by John Arbash Meinel
Updated cmd_root
420
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
421
        self.wt.bzrdir.sprout(url)
1185.85.53 by John Arbash Meinel
Updated cmd_root
422
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
423
        txt = self.run_bzr_decode('root', working_dir=dirname)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
424
        self.assertTrue(txt.endswith(dirname+'\n'))
1185.85.53 by John Arbash Meinel
Updated cmd_root
425
2823.2.2 by Daniel Watkins
Merged bzr.dev.
426
        txt = self.run_bzr_decode('root', encoding='ascii', fail=True,
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
427
                                  working_dir=dirname)
1185.85.53 by John Arbash Meinel
Updated cmd_root
428
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
429
    def test_log(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
430
        fname = self.info['filename']
431
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
432
        txt = self.run_bzr_decode('log')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
433
        self.assertNotEqual(-1, txt.find(self.info['committer']))
434
        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
435
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
436
        txt = self.run_bzr_decode('log --verbose')
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
437
        # FIXME: iso-8859-2 test shouldn't be skipped here --vila 20090702
438
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
439
        self.assertNotEqual(-1, txt.find(fname))
1185.85.54 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
440
441
        # Make sure log doesn't fail even if we can't write out
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
442
        txt = self.run_bzr_decode('log --verbose', encoding='ascii')
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
443
        self.assertEqual(-1, txt.find(fname))
444
        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
445
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
446
    def test_touching_revisions(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
447
        fname = self.info['filename']
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
448
        txt = self.run_bzr_decode(['touching-revisions', fname])
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
449
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
450
        self.assertEqual(u'     3 added %s\n' % (fname,), txt)
451
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
452
        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.
453
        self.wt.rename_one(fname, fname2)
454
        self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
455
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
456
        txt = self.run_bzr_decode(['touching-revisions', fname2])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
457
        expected_txt = (u'     3 added %s\n'
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
458
                        u'     4 renamed %s => %s\n'
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
459
                        % (fname, fname, fname2))
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
460
        self.assertEqual(expected_txt, txt)
461
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
462
        self.run_bzr_decode(['touching-revisions', fname2], encoding='ascii',
2823.2.2 by Daniel Watkins
Merged bzr.dev.
463
                            fail=True)
1185.85.55 by John Arbash Meinel
Updated cmd_touching_revisions
464
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
465
    def test_ls(self):
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
466
        txt = self.run_bzr_decode('ls')
1830.3.10 by John Arbash Meinel
Don't compare direct output of ls, sort first
467
        self.assertEqual(sorted(['a', 'b', self.info['filename']]),
468
                         sorted(txt.splitlines()))
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
469
        txt = self.run_bzr_decode('ls --null')
1830.3.10 by John Arbash Meinel
Don't compare direct output of ls, sort first
470
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
471
                         sorted(txt.split('\0')))
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
472
2823.2.2 by Daniel Watkins
Merged bzr.dev.
473
        txt = self.run_bzr_decode('ls', encoding='ascii', fail=True)
474
        txt = self.run_bzr_decode('ls --null', encoding='ascii', fail=True)
1185.85.56 by John Arbash Meinel
Keeping test_non_ascii in the same order as builtins.py
475
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
476
    def test_unknowns(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
477
        fname = self.info['filename'] + '2'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
478
        self.build_tree_contents([(fname, 'unknown\n')])
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
479
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
480
        # TODO: jam 20060112 bzr unknowns is the only one which
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
481
        #       quotes paths do we really want it to?
3251.6.3 by Adrian Wilkins
Simplified and fixed test code
482
        #       awilkins 20080521 added and modified do it now as well
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
483
        txt = self.run_bzr_decode('unknowns')
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
484
        self._check_OSX_can_roundtrip(self.info['filename'])
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
485
        self.assertEqual(u'"%s"\n' % (fname,), txt)
486
2823.2.2 by Daniel Watkins
Merged bzr.dev.
487
        self.run_bzr_decode('unknowns', encoding='ascii', fail=True)
1185.85.57 by John Arbash Meinel
Updated cmd_unknowns
488
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
489
    def test_ignore(self):
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
490
        fname2 = self.info['filename'] + '2.txt'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
491
        self.build_tree_contents([(fname2, 'ignored\n')])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
492
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
493
        def check_unknowns(expected):
494
            self.assertEqual(expected, list(self.wt.unknowns()))
495
4498.4.3 by Vincent Ladeuil
Try to stop failing tests as late as possible on OSX.
496
        self._check_OSX_can_roundtrip(self.info['filename'])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
497
        check_unknowns([fname2])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
498
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
499
        self.run_bzr_decode(['ignore', './' + fname2])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
500
        check_unknowns([])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
501
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
502
        fname3 = self.info['filename'] + '3.txt'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
503
        self.build_tree_contents([(fname3, 'unknown 3\n')])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
504
        check_unknowns([fname3])
1185.85.58 by John Arbash Meinel
Working on bzr ignore, found that WorkingTree.is_ignored doesn't handle unicode names.
505
506
        # Ignore should not care what the encoding is
507
        # (right now it doesn't print anything)
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
508
        self.run_bzr_decode(['ignore', fname3], encoding='ascii')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
509
        check_unknowns([])
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
510
511
        # Now try a wildcard match
1185.85.70 by John Arbash Meinel
Hooked up EncodingAdapter, and updated test_non_ascii.
512
        fname4 = self.info['filename'] + '4.txt'
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
513
        self.build_tree_contents([(fname4, 'unknown 4\n')])
514
        self.run_bzr_decode('ignore *.txt')
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
515
        check_unknowns([])
1185.85.53 by John Arbash Meinel
Updated cmd_root
516
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
517
        # and a different wildcard that matches everything
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
518
        os.remove('.bzrignore')
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
519
        self.run_bzr_decode(['ignore', self.info['filename'] + '*'])
1836.2.2 by John Arbash Meinel
Cleanup the rest of the test_non_ascii suite to use internal apis.
520
        check_unknowns([])
1185.85.59 by John Arbash Meinel
Adding extra tests for future corrections to WorkingTree.is_ignored()
521
1816.1.1 by Alexander Belchenko
blackbox test for non-ascii behaviour of missing command
522
    def test_missing(self):
523
        # create empty tree as reference for missing
2823.2.1 by Daniel Watkins
Cleaned up tests.blackbox.test_non_ascii so it uses internals where appropriate.
524
        self.make_branch_and_tree('empty-tree')
1816.1.1 by Alexander Belchenko
blackbox test for non-ascii behaviour of missing command
525
526
        msg = self.info['message']
527
2823.2.3 by Daniel Watkins
Removed erroneous retcodes.
528
        txt = self.run_bzr_decode('missing empty-tree')
1816.1.1 by Alexander Belchenko
blackbox test for non-ascii behaviour of missing command
529
        self.assertNotEqual(-1, txt.find(self.info['committer']))
530
        self.assertNotEqual(-1, txt.find(msg))
531
532
        # Make sure missing doesn't fail even if we can't write out
2823.2.3 by Daniel Watkins
Removed erroneous retcodes.
533
        txt = self.run_bzr_decode('missing empty-tree', encoding='ascii')
1816.1.1 by Alexander Belchenko
blackbox test for non-ascii behaviour of missing command
534
        self.assertEqual(-1, txt.find(msg))
535
        self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))
2904.3.1 by Lukáš Lalinský
Unicode-safe output from ``bzr info``.
536
537
    def test_info(self):
2904.3.2 by Lukáš Lalinský
More details in NEWS and use full self.run_bzr_decode name in the test.
538
        self.run_bzr_decode(['branch', u'.', self.info['directory']])
539
        self.run_bzr_decode(['info', self.info['directory']])
540
        self.run_bzr_decode(['info', self.info['directory']],
541
                            encoding='ascii')
3123.2.1 by Lukáš Lalinský
Use self.outf instead of sys.stdout in cmd_ignored.
542
543
    def test_ignored(self):
544
        fname = self.info['filename'] + '1.txt'
545
        self.build_tree_contents([(fname, 'ignored\n')])
546
        self.run_bzr(['ignore', fname])
547
        txt = self.run_bzr_decode(['ignored'])
548
        self.assertEqual(txt, '%-50s %s\n' % (fname, fname))
549
        txt = self.run_bzr_decode(['ignored'], encoding='ascii')
550
        fname = fname.encode('ascii', 'replace')
551
        self.assertEqual(txt, '%-50s %s\n' % (fname, fname))