236
237
self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
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')
244
os.environ['BZR_EDITOR'] = 'bzr_editor'
245
os.environ['VISUAL'] = 'visual'
246
os.environ['EDITOR'] = 'editor'
248
ensure_config_dir_exists()
249
f = open(config_filename(), 'wb')
250
f.write('editor = config_editor\n')
253
editors = list(msgeditor._get_editor())
254
editors = [editor for (editor, cfg_src) in editors]
256
self.assertEqual(['bzr_editor', 'config_editor', 'visual',
257
'editor'], editors[:4])
259
if sys.platform == 'win32':
260
self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
262
self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano',
266
# Restore the environment
267
if bzr_editor is None:
268
del os.environ['BZR_EDITOR']
270
os.environ['BZR_EDITOR'] = bzr_editor
272
del os.environ['VISUAL']
274
os.environ['VISUAL'] = visual
276
del os.environ['EDITOR']
278
os.environ['EDITOR'] = editor
240
os.environ['BZR_EDITOR'] = 'bzr_editor'
241
os.environ['VISUAL'] = 'visual'
242
os.environ['EDITOR'] = 'editor'
244
conf = config.GlobalConfig.from_string('editor = config_editor\n',
247
editors = list(msgeditor._get_editor())
248
editors = [editor for (editor, cfg_src) in editors]
250
self.assertEqual(['bzr_editor', 'config_editor', 'visual', 'editor'],
253
if sys.platform == 'win32':
254
self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
256
self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'],
280
260
def test__run_editor_EACCES(self):
281
261
"""If running a configured editor raises EACESS, the user is warned."""