42
43
def test_commit_template(self):
43
44
"""Test building a commit message template"""
44
45
working_tree = self.make_uncommitted_tree()
45
template = make_commit_message_template(working_tree, None)
46
template = bzrlib.msgeditor.make_commit_message_template(working_tree, None)
46
47
self.assertEqualDiff(template,
54
super(MsgEditorTest, self).setUp()
55
self._bzr_editor = os.environ.get('BZR_EDITOR', None)
58
if self._bzr_editor != None:
59
os.environ['BZR_EDITOR'] = self._bzr_editor
61
if os.environ.get('BZR_EDITOR', None) != None:
62
del os.environ['BZR_EDITOR']
63
super(MsgEditorTest, self).tearDown()
65
def test_get_editor(self):
66
os.environ['BZR_EDITOR'] = 'fed'
67
editors = [i for i in bzrlib.msgeditor._get_editor()]
68
self.assertNotEqual([], editors, 'No editor found')
69
self.assertEqual('fed', editors[0])
71
def test_run_editor(self):
72
if sys.platform == "win32":
73
f = file('fed.bat', 'w')
74
f.write('@rem dummy fed')
76
os.environ['BZR_EDITOR'] = 'fed.bat'
78
f = file('fed.sh', 'wb')
79
f.write('#!/bin/sh\n')
81
os.chmod('fed.sh', 0755)
82
os.environ['BZR_EDITOR'] = './fed.sh'
84
self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
85
'Unable to run dummy fake editor')
87
def test_edit_commit_message(self):
88
working_tree = self.make_uncommitted_tree()
90
f = file('fed.py', 'wb')
91
f.write('#!%s\n' % sys.executable)
94
if len(sys.argv) == 2:
100
f.write('test message from fed\\n')
105
if sys.platform == "win32":
106
# [win32] make batch file and set BZR_EDITOR
107
f = file('fed.bat', 'w')
111
""" % sys.executable)
113
os.environ['BZR_EDITOR'] = 'fed.bat'
115
# [non-win32] make python script executable and set BZR_EDITOR
116
os.chmod('fed.py', 0755)
117
os.environ['BZR_EDITOR'] = './fed.py'
119
mutter('edit_commit_message without infotext')
120
self.assertEqual('test message from fed\n',
121
bzrlib.msgeditor.edit_commit_message(''))
123
mutter('edit_commit_message with unicode infotext')
124
self.assertEqual('test message from fed\n',
125
bzrlib.msgeditor.edit_commit_message(u'\u1234'))
127
def test_deleted_commit_message(self):
128
working_tree = self.make_uncommitted_tree()
130
if sys.platform == 'win32':
131
os.environ['BZR_EDITOR'] = 'del'
133
os.environ['BZR_EDITOR'] = 'rm'
135
self.assertRaises(IOError, bzrlib.msgeditor.edit_commit_message, '')