~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Andrew Bennetts
  • Date: 2011-02-07 04:14:29 UTC
  • mfrom: (5535.4.26 fetch-all-tags-309682)
  • mto: This revision was merged to the branch mainline in revision 5648.
  • Revision ID: andrew.bennetts@canonical.com-20110207041429-3kc1blj34rvvxod9
Merge fetch-all-tags-309682.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    tests,
30
30
    trace,
31
31
    )
32
 
from bzrlib.branch import Branch
33
 
from bzrlib.config import ensure_config_dir_exists, config_filename
34
32
from bzrlib.msgeditor import (
35
33
    make_commit_message_template_encoded,
36
34
    edit_commit_message_encoded
157
155
            return './fed.sh'
158
156
 
159
157
    def test_run_editor(self):
160
 
        os.environ['BZR_EDITOR'] = self.make_do_nothing_editor()
 
158
        self.overrideEnv('BZR_EDITOR', self.make_do_nothing_editor())
161
159
        self.assertEqual(True, msgeditor._run_editor(''),
162
160
                         'Unable to run dummy fake editor')
163
161
 
191
189
"%s" fed.py %%1
192
190
""" % sys.executable)
193
191
            f.close()
194
 
            os.environ['BZR_EDITOR'] = 'fed.bat'
 
192
            self.overrideEnv('BZR_EDITOR', 'fed.bat')
195
193
        else:
196
194
            # [non-win32] make python script executable and set BZR_EDITOR
197
195
            os.chmod('fed.py', 0755)
198
 
            os.environ['BZR_EDITOR'] = './fed.py'
 
196
            self.overrideEnv('BZR_EDITOR', './fed.py')
199
197
 
200
198
    def test_edit_commit_message(self):
201
199
        working_tree = self.make_uncommitted_tree()
230
228
        working_tree = self.make_uncommitted_tree()
231
229
 
232
230
        if sys.platform == 'win32':
233
 
            os.environ['BZR_EDITOR'] = 'cmd.exe /c del'
 
231
            editor = 'cmd.exe /c del'
234
232
        else:
235
 
            os.environ['BZR_EDITOR'] = 'rm'
 
233
            editor = 'rm'
 
234
        self.overrideEnv('BZR_EDITOR', editor)
236
235
 
237
236
        self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
238
237
 
239
238
    def test__get_editor(self):
240
 
        os.environ['BZR_EDITOR'] = 'bzr_editor'
241
 
        os.environ['VISUAL'] = 'visual'
242
 
        os.environ['EDITOR'] = 'editor'
 
239
        self.overrideEnv('BZR_EDITOR', 'bzr_editor')
 
240
        self.overrideEnv('VISUAL', 'visual')
 
241
        self.overrideEnv('EDITOR', 'editor')
243
242
 
244
243
        conf = config.GlobalConfig.from_string('editor = config_editor\n',
245
244
                                               save=True)
259
258
 
260
259
    def test__run_editor_EACCES(self):
261
260
        """If running a configured editor raises EACESS, the user is warned."""
262
 
        os.environ['BZR_EDITOR'] = 'eacces.py'
 
261
        self.overrideEnv('BZR_EDITOR', 'eacces.py')
263
262
        f = file('eacces.py', 'wb')
264
263
        f.write('# Not a real editor')
265
264
        f.close()
267
266
        os.chmod('eacces.py', 0)
268
267
        # Set $EDITOR so that _run_editor will terminate before trying real
269
268
        # editors.
270
 
        os.environ['EDITOR'] = self.make_do_nothing_editor()
 
269
        self.overrideEnv('EDITOR', self.make_do_nothing_editor())
271
270
        # Call _run_editor, capturing mutter.warning calls.
272
271
        warnings = []
273
272
        def warning(*args):
319
318
        self.assertFileEqual('', msgfilename)
320
319
 
321
320
    def test_unsupported_encoding_commit_message(self):
322
 
        old_env = osutils.set_or_unset_env('LANG', 'C')
323
 
        try:
324
 
            # LANG env variable has no effect on Windows
325
 
            # but some characters anyway cannot be represented
326
 
            # in default user encoding
327
 
            char = probe_bad_non_ascii(osutils.get_user_encoding())
328
 
            if char is None:
329
 
                raise TestSkipped('Cannot find suitable non-ascii character '
330
 
                    'for user_encoding (%s)' % osutils.get_user_encoding())
331
 
 
332
 
            self.make_fake_editor(message=char)
333
 
 
334
 
            working_tree = self.make_uncommitted_tree()
335
 
            self.assertRaises(errors.BadCommitMessageEncoding,
336
 
                              msgeditor.edit_commit_message, '')
337
 
        finally:
338
 
            osutils.set_or_unset_env('LANG', old_env)
 
321
        self.overrideEnv('LANG', 'C')
 
322
        # LANG env variable has no effect on Windows
 
323
        # but some characters anyway cannot be represented
 
324
        # in default user encoding
 
325
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
326
        if char is None:
 
327
            raise TestSkipped('Cannot find suitable non-ascii character '
 
328
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
329
 
 
330
        self.make_fake_editor(message=char)
 
331
 
 
332
        working_tree = self.make_uncommitted_tree()
 
333
        self.assertRaises(errors.BadCommitMessageEncoding,
 
334
                          msgeditor.edit_commit_message, '')
339
335
 
340
336
    def test_generate_commit_message_template_no_hooks(self):
341
337
        commit_obj = commit.Commit()