49
49
def load_tests(loader, standard_tests, pattern):
50
50
"""Parameterize the test for tempfile creation with different encodings."""
51
to_adapt, result = split_suite_by_re(standard_tests,
51
to_adapt, result = split_suite_by_re(
52
53
"test__create_temp_file_with_commit_template_in_unicode_dir")
53
54
return multiply_tests(to_adapt, encoding_scenarios, result)
58
59
def make_uncommitted_tree(self):
59
60
"""Build a branch with uncommitted unicode named changes in the cwd."""
60
61
working_tree = self.make_branch_and_tree('.')
61
b = working_tree.branch
62
62
filename = u'hell\u00d8'
64
64
self.build_tree_contents([(filename, b'contents of hello')])
65
65
except UnicodeEncodeError:
66
66
self.skipTest("can't build unicode working tree in "
67
"filesystem encoding %s" % sys.getfilesystemencoding())
67
"filesystem encoding %s" % sys.getfilesystemencoding())
68
68
working_tree.add(filename)
69
69
return working_tree
102
102
working_tree = self.make_multiple_pending_tree()
103
103
template = msgeditor.make_commit_message_template(working_tree, None)
104
104
self.assertEqualDiff(template,
107
107
Bilbo Baggins 2009-01-29 Feature X finished.
108
108
Bilbo Baggins 2009-01-28 Feature X work.
163
162
See <https://bugs.launchpad.net/bzr/+bug/220331>
165
164
self.overrideEnv('BRZ_EDITOR',
166
'"%s"' % self.make_do_nothing_editor('name with spaces'))
167
self.assertEqual(True, msgeditor._run_editor('a_filename'))
165
'"%s"' % self.make_do_nothing_editor('name with spaces'))
166
self.assertEqual(True, msgeditor._run_editor('a_filename'))
169
168
def make_fake_editor(self, message='test message from fed\n'):
170
169
"""Set up environment so that an editor will be a known script.
201
200
self.overrideEnv('BRZ_EDITOR', './fed.py')
203
202
def test_edit_commit_message_without_infotext(self):
204
working_tree = self.make_uncommitted_tree()
203
self.make_uncommitted_tree()
205
204
self.make_fake_editor()
207
206
mutter('edit_commit_message without infotext')
209
208
msgeditor.edit_commit_message(''))
211
210
def test_edit_commit_message_with_ascii_infotext(self):
212
working_tree = self.make_uncommitted_tree()
211
self.make_uncommitted_tree()
213
212
self.make_fake_editor()
215
214
mutter('edit_commit_message with ascii string infotext')
217
216
msgeditor.edit_commit_message('spam'))
219
218
def test_edit_commit_message_with_unicode_infotext(self):
220
working_tree = self.make_uncommitted_tree()
219
self.make_uncommitted_tree()
221
220
self.make_fake_editor()
223
222
mutter('edit_commit_message with unicode infotext')
237
236
self.make_uncommitted_tree()
238
237
self.make_fake_editor()
239
238
self.assertEqual('test message from fed\nstart message\n',
240
msgeditor.edit_commit_message('',
241
start_message='start message\n'))
239
msgeditor.edit_commit_message(
240
'', start_message='start message\n'))
242
241
self.assertEqual('test message from fed\n',
243
msgeditor.edit_commit_message('',
242
msgeditor.edit_commit_message(
243
'', start_message=''))
246
245
def test_deleted_commit_message(self):
247
working_tree = self.make_uncommitted_tree()
246
self.make_uncommitted_tree()
249
248
if sys.platform == 'win32':
250
249
editor = 'cmd.exe /c del'
253
252
self.overrideEnv('BRZ_EDITOR', editor)
255
254
self.assertRaises((EnvironmentError, errors.NoSuchFile),
256
msgeditor.edit_commit_message, '')
255
msgeditor.edit_commit_message, '')
258
257
def test__get_editor(self):
259
258
self.overrideEnv('BRZ_EDITOR', 'bzr_editor')
275
274
self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'],
279
277
def test__run_editor_EACCES(self):
280
278
"""If running a configured editor raises EACESS, the user is warned."""
281
279
self.overrideEnv('BRZ_EDITOR', 'eacces.py')
299
298
msgeditor._run_editor('')
301
300
trace.warning = _warning
302
self.assertStartsWith(warnings[0], 'Could not start editor "eacces.py"')
301
self.assertStartsWith(
302
warnings[0], 'Could not start editor "eacces.py"')
304
304
def test__create_temp_file_with_commit_template(self):
305
305
# check that commit template written properly
306
306
# and has platform native line-endings (CRLF on win32)
307
307
create_file = msgeditor._create_temp_file_with_commit_template
308
msgfilename, hasinfo = create_file(b'infotext', '----', b'start message')
308
msgfilename, hasinfo = create_file(
309
b'infotext', '----', b'start message')
309
310
self.assertNotEqual(None, msgfilename)
310
311
self.assertTrue(hasinfo)
311
312
expected = os.linesep.join(['start message',
343
344
# in default user encoding
344
345
char = probe_bad_non_ascii(osutils.get_user_encoding())
346
self.skipTest('Cannot find suitable non-ascii character '
348
'Cannot find suitable non-ascii character '
347
349
'for user_encoding (%s)' % osutils.get_user_encoding())
349
351
self.make_fake_editor(message=char)
351
working_tree = self.make_uncommitted_tree()
353
self.make_uncommitted_tree()
352
354
self.assertRaises(msgeditor.BadCommitMessageEncoding,
353
355
msgeditor.edit_commit_message, '')
355
357
def test_set_commit_message_no_hooks(self):
356
358
commit_obj = commit.Commit()
357
359
self.assertIs(None,
358
msgeditor.set_commit_message(commit_obj))
360
msgeditor.set_commit_message(commit_obj))
360
362
def test_set_commit_message_hook(self):
361
363
msgeditor.hooks.install_named_hook("set_commit_message",
362
lambda commit_obj, existing_message: "save me some typing\n", None)
364
lambda commit_obj, existing_message: "save me some typing\n", None)
363
365
commit_obj = commit.Commit()
364
366
self.assertEqual("save me some typing\n",
365
msgeditor.set_commit_message(commit_obj))
367
msgeditor.set_commit_message(commit_obj))
367
369
def test_generate_commit_message_template_no_hooks(self):
368
370
commit_obj = commit.Commit()
369
371
self.assertIs(None,
370
msgeditor.generate_commit_message_template(commit_obj))
372
msgeditor.generate_commit_message_template(commit_obj))
372
374
def test_generate_commit_message_template_hook(self):
373
375
msgeditor.hooks.install_named_hook("commit_message_template",
374
lambda commit_obj, msg: "save me some typing\n", None)
376
lambda commit_obj, msg: "save me some typing\n", None)
375
377
commit_obj = commit.Commit()
376
378
self.assertEqual("save me some typing\n",
377
msgeditor.generate_commit_message_template(commit_obj))
379
msgeditor.generate_commit_message_template(commit_obj))
380
382
# GZ 2009-11-17: This wants moving to osutils when the errno checking code is
384
386
def test_subprocess_call_bad_file(self):
385
387
if sys.platform != "win32":
386
388
raise TestNotApplicable("Workarounds for windows only")
387
import subprocess, errno
388
391
ERROR_BAD_EXE_FORMAT = 193
389
392
open("textfile.txt", "w").close()
390
393
e = self.assertRaises(WindowsError, subprocess.call, "textfile.txt")