~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
  hell\u00d8
142
142
""".encode('utf8') in template)
143
143
 
144
 
    def make_do_nothing_editor(self):
 
144
    def make_do_nothing_editor(self, basename='fed'):
145
145
        if sys.platform == "win32":
146
 
            f = file('fed.bat', 'w')
 
146
            name = basename + '.bat'
 
147
            f = file(name, 'w')
147
148
            f.write('@rem dummy fed')
148
149
            f.close()
149
 
            return 'fed.bat'
 
150
            return name
150
151
        else:
151
 
            f = file('fed.sh', 'wb')
 
152
            name = basename + '.sh'
 
153
            f = file(name, 'wb')
152
154
            f.write('#!/bin/sh\n')
153
155
            f.close()
154
 
            os.chmod('fed.sh', 0755)
155
 
            return './fed.sh'
 
156
            os.chmod(name, 0755)
 
157
            return './' + name
156
158
 
157
159
    def test_run_editor(self):
158
160
        self.overrideEnv('BZR_EDITOR', self.make_do_nothing_editor())
159
161
        self.assertEqual(True, msgeditor._run_editor(''),
160
162
                         'Unable to run dummy fake editor')
161
163
 
 
164
    def test_parse_editor_name(self):
 
165
        """Correctly interpret names with spaces.
 
166
 
 
167
        See <https://bugs.launchpad.net/bzr/+bug/220331>
 
168
        """
 
169
        self.overrideEnv('BZR_EDITOR',
 
170
            '"%s"' % self.make_do_nothing_editor('name with spaces'))
 
171
        self.assertEqual(True, msgeditor._run_editor('a_filename'))    
 
172
 
162
173
    def make_fake_editor(self, message='test message from fed\\n'):
163
174
        """Set up environment so that an editor will be a known script.
164
175
 
333
344
        self.assertRaises(errors.BadCommitMessageEncoding,
334
345
                          msgeditor.edit_commit_message, '')
335
346
 
 
347
    def test_set_commit_message_no_hooks(self):
 
348
        commit_obj = commit.Commit()
 
349
        self.assertIs(None,
 
350
            msgeditor.set_commit_message(commit_obj))
 
351
 
 
352
    def test_set_commit_message_hook(self):
 
353
        msgeditor.hooks.install_named_hook("set_commit_message",
 
354
                lambda commit_obj, existing_message: "save me some typing\n", None)
 
355
        commit_obj = commit.Commit()
 
356
        self.assertEquals("save me some typing\n",
 
357
            msgeditor.set_commit_message(commit_obj))
 
358
 
336
359
    def test_generate_commit_message_template_no_hooks(self):
337
360
        commit_obj = commit.Commit()
338
361
        self.assertIs(None,
357
380
        ERROR_BAD_EXE_FORMAT = 193
358
381
        file("textfile.txt", "w").close()
359
382
        e = self.assertRaises(WindowsError, subprocess.call, "textfile.txt")
360
 
        # Python2.4 used the 'winerror' as the errno, which confuses a lot of
361
 
        # our error trapping code. Make sure that we understand the mapping
362
 
        # correctly.
363
 
        if sys.version_info >= (2, 5):
364
 
            self.assertEqual(e.errno, errno.ENOEXEC)
365
 
            self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)
366
 
        else:
367
 
            self.assertEqual(e.errno, ERROR_BAD_EXE_FORMAT)
 
383
        self.assertEqual(e.errno, errno.ENOEXEC)
 
384
        self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)