/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 breezy/tests/blackbox/test_command_encoding.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from .. import TestCaseWithMemoryTransport
20
20
from ...commands import Command, register_command, plugin_cmds
 
21
from ...sixish import PY3
21
22
 
22
23
 
23
24
class cmd_echo_exact(Command):
50
51
    def test_exact(self):
51
52
        def bzr(*args, **kwargs):
52
53
            kwargs['encoding'] = 'ascii'
53
 
            return self.run_bzr(*args, **kwargs)[0]
 
54
            return self.run_bzr_raw(*args, **kwargs)[0]
54
55
 
55
56
        register_command(cmd_echo_exact)
56
57
        try:
57
 
            self.assertEqual('foo', bzr('echo-exact foo'))
 
58
            self.assertEqual(b'foo', bzr('echo-exact foo'))
58
59
            # Exact should fail to decode the string
59
60
            self.assertRaises(UnicodeEncodeError,
60
61
                bzr,
67
68
    def test_strict_utf8(self):
68
69
        def bzr(*args, **kwargs):
69
70
            kwargs['encoding'] = 'utf-8'
70
 
            return self.run_bzr(*args, **kwargs)[0]
 
71
            return self.run_bzr_raw(*args, **kwargs)[0]
71
72
 
72
73
        register_command(cmd_echo_strict)
73
74
        try:
74
 
            self.assertEqual('foo', bzr('echo-strict foo'))
75
 
            self.assertEqual(u'foo\xb5'.encode('utf-8'),
 
75
            self.assertEqual(b'foo', bzr('echo-strict foo'))
 
76
            expected = u'foo\xb5'
 
77
            expected = expected.encode('utf-8')
 
78
            self.assertEqual(expected,
76
79
                             bzr(['echo-strict', u'foo\xb5']))
77
80
        finally:
78
81
            plugin_cmds.remove('echo-strict')
80
83
    def test_strict_ascii(self):
81
84
        def bzr(*args, **kwargs):
82
85
            kwargs['encoding'] = 'ascii'
83
 
            return self.run_bzr(*args, **kwargs)[0]
 
86
            return self.run_bzr_raw(*args, **kwargs)[0]
84
87
 
85
88
        register_command(cmd_echo_strict)
86
89
        try:
87
 
            self.assertEqual('foo', bzr('echo-strict foo'))
 
90
            self.assertEqual(b'foo', bzr('echo-strict foo'))
88
91
            # ascii can't encode \xb5
89
92
            self.assertRaises(UnicodeEncodeError,
90
93
                bzr,
95
98
    def test_replace_utf8(self):
96
99
        def bzr(*args, **kwargs):
97
100
            kwargs['encoding'] = 'utf-8'
98
 
            return self.run_bzr(*args, **kwargs)[0]
 
101
            return self.run_bzr_raw(*args, **kwargs)[0]
99
102
 
100
103
        register_command(cmd_echo_replace)
101
104
        try:
102
 
            self.assertEqual('foo', bzr('echo-replace foo'))
 
105
            self.assertEqual(b'foo', bzr('echo-replace foo'))
103
106
            self.assertEqual(u'foo\xb5'.encode('utf-8'),
104
107
                             bzr(['echo-replace', u'foo\xb5']))
105
108
        finally:
108
111
    def test_replace_ascii(self):
109
112
        def bzr(*args, **kwargs):
110
113
            kwargs['encoding'] = 'ascii'
111
 
            return self.run_bzr(*args, **kwargs)[0]
 
114
            return self.run_bzr_raw(*args, **kwargs)[0]
112
115
 
113
116
        register_command(cmd_echo_replace)
114
117
        try:
115
 
            self.assertEqual('foo', bzr('echo-replace foo'))
 
118
            self.assertEqual(b'foo', bzr('echo-replace foo'))
116
119
            # ascii can't encode \xb5
117
 
            self.assertEqual('foo?', bzr(['echo-replace', u'foo\xb5']))
 
120
            self.assertEqual(b'foo?', bzr(['echo-replace', u'foo\xb5']))
118
121
        finally:
119
122
            plugin_cmds.remove('echo-replace')
120
123