22
22
from bzrlib.branch import Branch
23
from bzrlib.msgeditor import make_commit_message_template
23
import bzrlib.msgeditor
24
24
from bzrlib.tests import TestCaseInTempDir, TestSkipped
25
from bzrlib.trace import mutter
27
28
class MsgEditorTest(TestCaseInTempDir):
29
30
def make_uncommitted_tree(self):
30
31
"""Build a branch with uncommitted unicode named changes in the cwd."""
31
b = Branch.initialize('.')
32
b = Branch.initialize(u'.')
32
33
working_tree = b.working_tree()
33
34
filename = u'hell\u00d8'
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,
46
48
self.assertEqualDiff(template,
55
super(MsgEditorTest, self).setUp()
56
self._bzr_editor = os.environ.get('BZR_EDITOR', None)
59
if self._bzr_editor != None:
60
os.environ['BZR_EDITOR'] = self._bzr_editor
62
if os.environ.get('BZR_EDITOR', None) != None:
63
del os.environ['BZR_EDITOR']
64
super(MsgEditorTest, self).tearDown()
66
def test_get_editor(self):
67
os.environ['BZR_EDITOR'] = 'fed'
68
editors = [i for i in bzrlib.msgeditor._get_editor()]
69
self.assertNotEqual([], editors, 'No editor found')
70
self.assertEqual('fed', editors[0])
72
def test_run_editor(self):
73
if sys.platform == "win32":
74
f = file('fed.bat', 'w')
75
f.write('@rem dummy fed')
77
os.environ['BZR_EDITOR'] = 'fed.bat'
79
f = file('fed.sh', 'wb')
80
f.write('#!/bin/sh\n')
82
os.chmod('fed.sh', 0755)
83
os.environ['BZR_EDITOR'] = './fed.sh'
85
self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
86
'Unable to run dummy fake editor')
88
def test_edit_commit_message(self):
89
working_tree = self.make_uncommitted_tree()
91
f = file('fed.py', 'wb')
92
f.write('#!%s\n' % sys.executable)
95
if len(sys.argv) == 2:
101
f.write('test message from fed\\n')
106
if sys.platform == "win32":
107
# [win32] make batch file and set BZR_EDITOR
108
f = file('fed.bat', 'w')
112
""" % sys.executable)
114
os.environ['BZR_EDITOR'] = 'fed.bat'
116
# [non-win32] make python script executable and set BZR_EDITOR
117
os.chmod('fed.py', 0755)
118
os.environ['BZR_EDITOR'] = './fed.py'
120
mutter('edit_commit_message without infotext')
121
self.assertEqual('test message from fed\n',
122
bzrlib.msgeditor.edit_commit_message(''))
124
mutter('edit_commit_message with unicode infotext')
125
self.assertEqual('test message from fed\n',
126
bzrlib.msgeditor.edit_commit_message(u'\u1234'))