13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Test commit message editor.
52
50
"""Parameterize the test for tempfile creation with different encodings."""
53
51
to_adapt, result = split_suite_by_re(standard_tests,
54
52
"test__create_temp_file_with_commit_template_in_unicode_dir")
55
return multiply_tests(to_adapt, encoding_scenarios, result)
53
for test in iter_suite_tests(to_adapt):
54
result.addTests(EncodingTestAdapter().adapt(test))
58
58
class MsgEditorTest(TestCaseWithTransport):
95
95
tree3.commit('Feature Y, based on initial X work.',
96
96
timestamp=1233285960, timezone=0)
97
97
tree.merge_from_branch(tree2.branch)
98
tree.merge_from_branch(tree3.branch, force=True)
98
tree.merge_from_branch(tree3.branch)
101
101
def test_commit_template_pending_merges(self):
237
237
self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
239
239
def test__get_editor(self):
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'],
240
# Test that _get_editor can return a decent list of items
241
bzr_editor = os.environ.get('BZR_EDITOR')
242
visual = os.environ.get('VISUAL')
243
editor = os.environ.get('EDITOR')
245
os.environ['BZR_EDITOR'] = 'bzr_editor'
246
os.environ['VISUAL'] = 'visual'
247
os.environ['EDITOR'] = 'editor'
249
ensure_config_dir_exists()
250
f = open(config_filename(), 'wb')
251
f.write('editor = config_editor\n')
254
editors = list(msgeditor._get_editor())
255
editors = [editor for (editor, cfg_src) in editors]
257
self.assertEqual(['bzr_editor', 'config_editor', 'visual',
258
'editor'], editors[:4])
260
if sys.platform == 'win32':
261
self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
263
self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano',
267
# Restore the environment
268
if bzr_editor is None:
269
del os.environ['BZR_EDITOR']
271
os.environ['BZR_EDITOR'] = bzr_editor
273
del os.environ['VISUAL']
275
os.environ['VISUAL'] = visual
277
del os.environ['EDITOR']
279
os.environ['EDITOR'] = editor
260
281
def test__run_editor_EACCES(self):
261
282
"""If running a configured editor raises EACESS, the user is warned."""
340
358
msgeditor.generate_commit_message_template(commit_obj))
342
360
def test_generate_commit_message_template_hook(self):
361
def restoreDefaults():
362
msgeditor.hooks['commit_message_template'] = []
363
self.addCleanup(restoreDefaults)
343
364
msgeditor.hooks.install_named_hook("commit_message_template",
344
365
lambda commit_obj, msg: "save me some typing\n", None)
345
366
commit_obj = commit.Commit()
346
367
self.assertEquals("save me some typing\n",
347
368
msgeditor.generate_commit_message_template(commit_obj))
350
# GZ 2009-11-17: This wants moving to osutils when the errno checking code is
351
class TestPlatformErrnoWorkarounds(TestCaseInTempDir):
352
"""Ensuring workarounds enshrined in code actually serve a purpose"""
354
def test_subprocess_call_bad_file(self):
355
if sys.platform != "win32":
356
raise TestNotApplicable("Workarounds for windows only")
357
import subprocess, errno
358
ERROR_BAD_EXE_FORMAT = 193
359
file("textfile.txt", "w").close()
360
e = self.assertRaises(WindowsError, subprocess.call, "textfile.txt")
361
# Python2.4 used the 'winerror' as the errno, which confuses a lot of
362
# our error trapping code. Make sure that we understand the mapping
364
if sys.version_info >= (2, 5):
365
self.assertEqual(e.errno, errno.ENOEXEC)
366
self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)
368
self.assertEqual(e.errno, ERROR_BAD_EXE_FORMAT)