1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
8
7
# This program is distributed in the hope that it will be useful,
9
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
45
42
def test_commit_template(self):
46
43
"""Test building a commit message template"""
47
44
working_tree = self.make_uncommitted_tree()
48
template = bzrlib.msgeditor.make_commit_message_template(working_tree, None)
45
template = make_commit_message_template(working_tree, None)
49
46
self.assertEqualDiff(template,
56
super(MsgEditorTest, self).setUp()
57
self._bzr_editor = os.environ.get('BZR_EDITOR', None)
60
if self._bzr_editor is not None:
61
os.environ['BZR_EDITOR'] = self._bzr_editor
63
if os.environ.get('BZR_EDITOR', None) is not None:
64
del os.environ['BZR_EDITOR']
65
super(MsgEditorTest, self).tearDown()
67
def test_run_editor(self):
68
if sys.platform == "win32":
69
f = file('fed.bat', 'w')
70
f.write('@rem dummy fed')
72
os.environ['BZR_EDITOR'] = 'fed.bat'
74
f = file('fed.sh', 'wb')
75
f.write('#!/bin/sh\n')
77
os.chmod('fed.sh', 0755)
78
os.environ['BZR_EDITOR'] = './fed.sh'
80
self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
81
'Unable to run dummy fake editor')
83
def test_edit_commit_message(self):
84
working_tree = self.make_uncommitted_tree()
86
f = file('fed.py', 'wb')
87
f.write('#!%s\n' % sys.executable)
90
if len(sys.argv) == 2:
96
f.write('test message from fed\\n')
101
if sys.platform == "win32":
102
# [win32] make batch file and set BZR_EDITOR
103
f = file('fed.bat', 'w')
107
""" % sys.executable)
109
os.environ['BZR_EDITOR'] = 'fed.bat'
111
# [non-win32] make python script executable and set BZR_EDITOR
112
os.chmod('fed.py', 0755)
113
os.environ['BZR_EDITOR'] = './fed.py'
115
mutter('edit_commit_message without infotext')
116
self.assertEqual('test message from fed\n',
117
bzrlib.msgeditor.edit_commit_message(''))
119
mutter('edit_commit_message with unicode infotext')
120
self.assertEqual('test message from fed\n',
121
bzrlib.msgeditor.edit_commit_message(u'\u1234'))
123
def test_deleted_commit_message(self):
124
working_tree = self.make_uncommitted_tree()
126
if sys.platform == 'win32':
127
os.environ['BZR_EDITOR'] = 'cmd.exe /c del'
129
os.environ['BZR_EDITOR'] = 'rm'
131
self.assertRaises((IOError, OSError), bzrlib.msgeditor.edit_commit_message, '')
133
def test__get_editor(self):
134
# Test that _get_editor can return a decent list of items
135
bzr_editor = os.environ.get('BZR_EDITOR')
136
visual = os.environ.get('VISUAL')
137
editor = os.environ.get('EDITOR')
139
os.environ['BZR_EDITOR'] = 'bzr_editor'
140
os.environ['VISUAL'] = 'visual'
141
os.environ['EDITOR'] = 'editor'
143
ensure_config_dir_exists()
144
f = open(config_filename(), 'wb')
145
f.write('editor = config_editor\n')
148
editors = list(bzrlib.msgeditor._get_editor())
150
self.assertEqual(['bzr_editor', 'config_editor', 'visual',
151
'editor'], editors[:4])
153
if sys.platform == 'win32':
154
self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:])
156
self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano',
160
# Restore the environment
161
if bzr_editor is None:
162
del os.environ['BZR_EDITOR']
164
os.environ['BZR_EDITOR'] = bzr_editor
166
del os.environ['VISUAL']
168
os.environ['VISUAL'] = visual
170
del os.environ['EDITOR']
172
os.environ['EDITOR'] = editor