~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-08-30 07:36:41 UTC
  • mfrom: (5394.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100830073641-a8gnwgcuonlkdqqg
(vila) Config files in bazaar home now use a lock (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    commit,
 
25
    config,
25
26
    errors,
26
27
    msgeditor,
27
28
    osutils,
236
237
        self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
237
238
 
238
239
    def test__get_editor(self):
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
 
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
 
279
259
 
280
260
    def test__run_editor_EACCES(self):
281
261
        """If running a configured editor raises EACESS, the user is warned."""