~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import sys
22
22
 
 
23
import bzrlib
23
24
from bzrlib import (
24
25
    errors,
25
26
    msgeditor,
31
32
    make_commit_message_template_encoded,
32
33
    edit_commit_message_encoded
33
34
)
34
 
from bzrlib.tests import TestCaseWithTransport, TestSkipped
 
35
from bzrlib.tests import (
 
36
    probe_bad_non_ascii,
 
37
    TestCaseWithTransport,
 
38
    TestSkipped,
 
39
    )
35
40
from bzrlib.trace import mutter
36
41
 
 
42
 
37
43
class MsgEditorTest(TestCaseWithTransport):
38
44
 
39
45
    def make_uncommitted_tree(self):
90
96
  hell\u00d8
91
97
""".encode('utf8') in template)
92
98
 
93
 
    def setUp(self):
94
 
        super(MsgEditorTest, self).setUp()
95
 
        self._bzr_editor = os.environ.get('BZR_EDITOR', None)
96
 
 
97
 
    def tearDown(self):
98
 
        if self._bzr_editor is not None:
99
 
            os.environ['BZR_EDITOR'] = self._bzr_editor
100
 
        else:
101
 
            if os.environ.get('BZR_EDITOR', None) is not None:
102
 
                del os.environ['BZR_EDITOR']
103
 
        super(MsgEditorTest, self).tearDown()
104
 
 
105
99
    def test_run_editor(self):
106
100
        if sys.platform == "win32":
107
101
            f = file('fed.bat', 'w')
162
156
        self.assertEqual('test message from fed\n',
163
157
                         msgeditor.edit_commit_message(''))
164
158
 
 
159
        mutter('edit_commit_message with ascii string infotext')
 
160
        self.assertEqual('test message from fed\n',
 
161
                         msgeditor.edit_commit_message('spam'))
 
162
 
165
163
        mutter('edit_commit_message with unicode infotext')
166
164
        self.assertEqual('test message from fed\n',
167
165
                         msgeditor.edit_commit_message(u'\u1234'))
256
254
    def test_unsupported_encoding_commit_message(self):
257
255
        old_env = osutils.set_or_unset_env('LANG', 'C')
258
256
        try:
259
 
            self.make_fake_editor(message='\xff')
 
257
            # LANG env variable has no effect on Windows
 
258
            # but some characters anyway cannot be represented
 
259
            # in default user encoding
 
260
            char = probe_bad_non_ascii(bzrlib.user_encoding)
 
261
            if char is None:
 
262
                raise TestSkipped('Cannot find suitable non-ascii character '
 
263
                    'for user_encoding (%s)' % bzrlib.user_encoding)
 
264
 
 
265
            self.make_fake_editor(message=char)
260
266
 
261
267
            working_tree = self.make_uncommitted_tree()
262
268
            self.assertRaises(errors.BadCommitMessageEncoding,