1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
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
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'
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')
192
190
""" % sys.executable)
194
os.environ['BZR_EDITOR'] = 'fed.bat'
192
self.overrideEnv('BZR_EDITOR', 'fed.bat')
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')
200
198
def test_edit_commit_message(self):
201
199
working_tree = self.make_uncommitted_tree()
230
228
working_tree = self.make_uncommitted_tree()
232
230
if sys.platform == 'win32':
233
os.environ['BZR_EDITOR'] = 'cmd.exe /c del'
231
editor = 'cmd.exe /c del'
235
os.environ['BZR_EDITOR'] = 'rm'
234
self.overrideEnv('BZR_EDITOR', editor)
237
236
self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
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')
244
243
conf = config.GlobalConfig.from_string('editor = config_editor\n',
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')
267
266
os.chmod('eacces.py', 0)
268
267
# Set $EDITOR so that _run_editor will terminate before trying real
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.
273
272
def warning(*args):
319
318
self.assertFileEqual('', msgfilename)
321
320
def test_unsupported_encoding_commit_message(self):
322
old_env = osutils.set_or_unset_env('LANG', 'C')
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())
329
raise TestSkipped('Cannot find suitable non-ascii character '
330
'for user_encoding (%s)' % osutils.get_user_encoding())
332
self.make_fake_editor(message=char)
334
working_tree = self.make_uncommitted_tree()
335
self.assertRaises(errors.BadCommitMessageEncoding,
336
msgeditor.edit_commit_message, '')
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())
327
raise TestSkipped('Cannot find suitable non-ascii character '
328
'for user_encoding (%s)' % osutils.get_user_encoding())
330
self.make_fake_editor(message=char)
332
working_tree = self.make_uncommitted_tree()
333
self.assertRaises(errors.BadCommitMessageEncoding,
334
msgeditor.edit_commit_message, '')
340
336
def test_generate_commit_message_template_no_hooks(self):
341
337
commit_obj = commit.Commit()