/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-01-05 22:59:14 UTC
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060105225914-174b175b9feca89b
Adding a test case which uses non-ascii characters for email, filename, and commit message

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
"""\
 
19
Black-box tests for bzr handling non-ascii characters.
 
20
"""
 
21
 
 
22
import sys
 
23
import os
 
24
import bzrlib
 
25
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
26
 
 
27
_mu = u'\xb5'
 
28
# Swedish?
 
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'
 
38
 
 
39
 
 
40
class TestNonAscii(TestCaseInTempDir):
 
41
 
 
42
    def setUp(self):
 
43
        super(TestNonAscii, self).setUp()
 
44
        self._orig_email = os.environ.get('BZREMAIL', None)
 
45
        email = _erik + u' <joe@foo.com>'
 
46
        try:
 
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)
 
51
 
 
52
        bzr = self.run_bzr
 
53
        bzr('init')
 
54
        open('a', 'wb').write('foo\n')
 
55
        bzr('add', 'a')
 
56
        bzr('commit', '-m', 'adding a')
 
57
        open('b', 'wb').write(_shrimp_sandwich.encode('utf-8') + '\n')
 
58
        bzr('add', 'b')
 
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')
 
66
        bzr('add', fname)
 
67
        bzr('commit', '-m', u'And an arabic file\n')
 
68
    
 
69
    def tearDown(self):
 
70
        if self._orig_email is not None:
 
71
            os.environ['BZREMAIL'] = self._orig_email
 
72
        else:
 
73
            if os.environ.get('BZREMAIL', None) is not None:
 
74
                del os.environ['BZREMAIL']
 
75
        super(TestEmail, self).tearDown()
 
76
 
 
77
    def test_log(self):
 
78
        bzr = self.run_bzr
 
79
        txt = bzr('log')[0]
 
80