~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Alexander Belchenko
  • Date: 2007-09-06 11:59:59 UTC
  • mto: (2839.6.2 3)
  • mto: This revision was merged to the branch mainline in revision 2884.
  • Revision ID: bialix@ukr.net-20070906115959-512lrh7jb9rll98d
some win32-specific fixes for selftest

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_in_user_encoding,
 
37
    TestCaseWithTransport,
 
38
    TestSkipped,
 
39
    )
35
40
from bzrlib.trace import mutter
36
41
 
37
42
class MsgEditorTest(TestCaseWithTransport):
90
95
  hell\u00d8
91
96
""".encode('utf8') in template)
92
97
 
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
98
    def test_run_editor(self):
106
99
        if sys.platform == "win32":
107
100
            f = file('fed.bat', 'w')
162
155
        self.assertEqual('test message from fed\n',
163
156
                         msgeditor.edit_commit_message(''))
164
157
 
 
158
        mutter('edit_commit_message with ascii string infotext')
 
159
        self.assertEqual('test message from fed\n',
 
160
                         msgeditor.edit_commit_message('spam'))
 
161
 
165
162
        mutter('edit_commit_message with unicode infotext')
166
163
        self.assertEqual('test message from fed\n',
167
164
                         msgeditor.edit_commit_message(u'\u1234'))
256
253
    def test_unsupported_encoding_commit_message(self):
257
254
        old_env = osutils.set_or_unset_env('LANG', 'C')
258
255
        try:
259
 
            self.make_fake_editor(message='\xff')
 
256
            # LANG env variable has no effect on Windows
 
257
            # but some characters anyway cannot be represented
 
258
            # in default user encoding
 
259
            char = '\xff'
 
260
            if sys.platform == 'win32':
 
261
                char = probe_bad_non_ascii_in_user_encoding()
 
262
                if char is None:
 
263
                    raise TestSkipped('cannot find suitable character')
 
264
 
 
265
            self.make_fake_editor(message=char)
260
266
 
261
267
            working_tree = self.make_uncommitted_tree()
262
268
            self.assertRaises(errors.BadCommitMessageEncoding,