~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Andrew Bennetts
  • Date: 2007-08-30 08:11:54 UTC
  • mfrom: (2766 +trunk)
  • mto: (2535.3.55 repo-refactor)
  • mto: This revision was merged to the branch mainline in revision 2772.
  • Revision ID: andrew.bennetts@canonical.com-20070830081154-16hebp2xwr15x2hc
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib.tests import TestCaseWithTransport, TestSkipped
27
27
from bzrlib.trace import mutter
28
28
 
 
29
from bzrlib import (
 
30
    osutils,
 
31
    errors
 
32
    )
 
33
 
29
34
 
30
35
class MsgEditorTest(TestCaseWithTransport):
31
36
 
80
85
        self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
81
86
                         'Unable to run dummy fake editor')
82
87
 
83
 
    def make_fake_editor(self):
 
88
    def make_fake_editor(self, message='test message from fed\\n'):
84
89
        """Set up environment so that an editor will be a known script.
85
90
 
86
91
        Sets up BZR_EDITOR so that if an editor is spawned it will run a
89
94
        f = file('fed.py', 'wb')
90
95
        f.write('#!%s\n' % sys.executable)
91
96
        f.write("""\
 
97
# coding=utf-8
92
98
import sys
93
99
if len(sys.argv) == 2:
94
100
    fn = sys.argv[1]
96
102
    s = f.read()
97
103
    f.close()
98
104
    f = file(fn, 'wb')
99
 
    f.write('test message from fed\\n')
 
105
    f.write('%s')
100
106
    f.write(s)
101
107
    f.close()
102
 
""")
 
108
""" % (message, ))
103
109
        f.close()
104
110
        if sys.platform == "win32":
105
111
            # [win32] make batch file and set BZR_EDITOR
210
216
        self.assertNotEqual(None, msgfilename)
211
217
        self.assertFalse(hasinfo)
212
218
        self.assertFileEqual('', msgfilename)
 
219
 
 
220
    def test_unsupported_encoding_commit_message(self):
 
221
        old_env = osutils.set_or_unset_env('LANG', 'C')
 
222
        try:
 
223
            self.make_fake_editor(message='\xff')
 
224
 
 
225
            working_tree = self.make_uncommitted_tree()
 
226
            self.assertRaises(errors.BadCommitMessageEncoding,
 
227
                                    bzrlib.msgeditor.edit_commit_message, '')
 
228
        finally:
 
229
            osutils.set_or_unset_env('LANG', old_env)