1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
Black-box tests for bzr handling non-ascii characters.
25
from bzrlib.tests import TestCaseInTempDir, TestSkipped
29
_erik = u'Erik B\xe5gfors'
30
_shrimp_sandwich = u'r\xe4ksm\xf6rg\xe5s'
31
# TODO: jam 20060105 Is there a way we can decode punycode for people
32
# who have non-ascii email addresses? Does it matter to us, we
33
# really would have no problem just using utf-8 internally, since
34
# we don't actually ever send email to these addresses.
35
_punycode_erik = 'Bgfors-iua'
36
# Arabic, probably only Unicode encodings can handle this one
37
_juju = u'\u062c\u0648\u062c\u0648'
40
class TestNonAscii(TestCaseInTempDir):
43
super(TestNonAscii, self).setUp()
44
self._orig_email = os.environ.get('BZREMAIL', None)
45
email = _erik + u' <joe@foo.com>'
47
os.environ['BZREMAIL'] = email.encode(bzrlib.user_encoding)
48
except UnicodeEncodeError:
49
raise TestSkipped('Cannot encode Erik B?gfors in encoding %s'
50
% bzrlib.user_encoding)
54
open('a', 'wb').write('foo\n')
56
bzr('commit', '-m', 'adding a')
57
open('b', 'wb').write(_shrimp_sandwich.encode('utf-8') + '\n')
59
bzr('commit', '-m', u'Creating a ' + _shrimp_sandwich)
60
# TODO: jam 20050105 Handle the case where we can't create a
61
# unicode filename on the current filesytem. I don't know
62
# what exception would be raised, because all of my
63
# filesystems support it. :)
64
fname = _juju + '.txt'
65
open(fname, 'wb').write('arabic filename\n')
67
bzr('commit', '-m', u'And an arabic file\n')
70
if self._orig_email is not None:
71
os.environ['BZREMAIL'] = self._orig_email
73
if os.environ.get('BZREMAIL', None) is not None:
74
del os.environ['BZREMAIL']
75
super(TestEmail, self).tearDown()