/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_command_encoding.py

merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2005, 2007 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
13
12
#
14
13
# You should have received a copy of the GNU General Public License
15
14
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
16
 
18
17
"""Tests for the Command.encoding_type interface."""
19
18
 
35
34
 
36
35
 
37
36
class cmd_echo_strict(cmd_echo_exact):
38
 
    """Replace bogus unicode characters."""
 
37
    """Raise a UnicodeError for unrepresentable characters."""
39
38
 
40
39
    encoding_type = 'strict'
41
40
 
47
46
 
48
47
 
49
48
class TestCommandEncoding(TestCase):
50
 
    
 
49
 
51
50
    def test_exact(self):
52
51
        def bzr(*args, **kwargs):
53
52
            return self.run_bzr(*args, **kwargs)[0]
59
58
            # get past main()
60
59
            self.assertEqual('foo\xb5', bzr('echo-exact foo\xb5'))
61
60
            # Exact should fail to decode the string
62
 
            bzr(['echo-exact', u'foo\xb5'], retcode=3)
 
61
            self.assertRaises(UnicodeEncodeError,
 
62
                bzr,
 
63
                ['echo-exact', u'foo\xb5'])
63
64
        finally:
64
 
            plugin_cmds.pop('echo-exact')
 
65
            plugin_cmds.remove('echo-exact')
65
66
 
66
67
    def test_strict_utf8(self):
67
68
        def bzr(*args, **kwargs):
74
75
            self.assertEqual(u'foo\xb5'.encode('utf-8'),
75
76
                             bzr(['echo-strict', u'foo\xb5']))
76
77
        finally:
77
 
            plugin_cmds.pop('echo-strict')
 
78
            plugin_cmds.remove('echo-strict')
78
79
 
79
80
    def test_strict_ascii(self):
80
81
        def bzr(*args, **kwargs):
85
86
        try:
86
87
            self.assertEqual('foo', bzr('echo-strict foo'))
87
88
            # ascii can't encode \xb5
88
 
            bzr(['echo-strict', u'foo\xb5'], retcode=3)
 
89
            self.assertRaises(UnicodeEncodeError,
 
90
                bzr,
 
91
                ['echo-strict', u'foo\xb5'])
89
92
        finally:
90
 
            plugin_cmds.pop('echo-strict')
 
93
            plugin_cmds.remove('echo-strict')
91
94
 
92
95
    def test_replace_utf8(self):
93
96
        def bzr(*args, **kwargs):
100
103
            self.assertEqual(u'foo\xb5'.encode('utf-8'),
101
104
                             bzr(['echo-replace', u'foo\xb5']))
102
105
        finally:
103
 
            plugin_cmds.pop('echo-replace')
 
106
            plugin_cmds.remove('echo-replace')
104
107
 
105
108
    def test_replace_ascii(self):
106
109
        def bzr(*args, **kwargs):
113
116
            # ascii can't encode \xb5
114
117
            self.assertEqual('foo?', bzr(['echo-replace', u'foo\xb5']))
115
118
        finally:
116
 
            plugin_cmds.pop('echo-replace')
 
119
            plugin_cmds.remove('echo-replace')
117
120
 
118
121