~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    commit,
25
 
    config,
26
25
    errors,
27
26
    msgeditor,
28
27
    osutils,
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'
243
 
 
244
 
        conf = config.GlobalConfig.from_string('editor = config_editor\n',
245
 
                                               save=True)
246
 
 
247
 
        editors = list(msgeditor._get_editor())
248
 
        editors = [editor for (editor, cfg_src) in editors]
249
 
 
250
 
        self.assertEqual(['bzr_editor', 'config_editor', 'visual', 'editor'],
251
 
                         editors[:4])
252
 
 
253
 
        if sys.platform == 'win32':
254
 
            self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
255
 
        else:
256
 
            self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'],
257
 
                             editors[4:])
258
 
 
 
239
        # Test that _get_editor can return a decent list of items
 
240
        bzr_editor = os.environ.get('BZR_EDITOR')
 
241
        visual = os.environ.get('VISUAL')
 
242
        editor = os.environ.get('EDITOR')
 
243
        try:
 
244
            os.environ['BZR_EDITOR'] = 'bzr_editor'
 
245
            os.environ['VISUAL'] = 'visual'
 
246
            os.environ['EDITOR'] = 'editor'
 
247
 
 
248
            ensure_config_dir_exists()
 
249
            f = open(config_filename(), 'wb')
 
250
            f.write('editor = config_editor\n')
 
251
            f.close()
 
252
 
 
253
            editors = list(msgeditor._get_editor())
 
254
            editors = [editor for (editor, cfg_src) in editors]
 
255
 
 
256
            self.assertEqual(['bzr_editor', 'config_editor', 'visual',
 
257
                              'editor'], editors[:4])
 
258
 
 
259
            if sys.platform == 'win32':
 
260
                self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
 
261
            else:
 
262
                self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano',
 
263
                                  'joe'], editors[4:])
 
264
 
 
265
        finally:
 
266
            # Restore the environment
 
267
            if bzr_editor is None:
 
268
                del os.environ['BZR_EDITOR']
 
269
            else:
 
270
                os.environ['BZR_EDITOR'] = bzr_editor
 
271
            if visual is None:
 
272
                del os.environ['VISUAL']
 
273
            else:
 
274
                os.environ['VISUAL'] = visual
 
275
            if editor is None:
 
276
                del os.environ['EDITOR']
 
277
            else:
 
278
                os.environ['EDITOR'] = editor
259
279
 
260
280
    def test__run_editor_EACCES(self):
261
281
        """If running a configured editor raises EACESS, the user is warned."""