~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-11 15:04:23 UTC
  • mfrom: (5848.1.1 2.4-cython-first)
  • Revision ID: pqm@pqm.ubuntu.com-20110511150423-tpm1ablukqalkvim
(jameinel) Default to using Cython for compiling code,
 rather than Pyrex. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
    errors,
27
27
    msgeditor,
28
28
    osutils,
 
29
    tests,
29
30
    trace,
30
31
    )
31
32
from bzrlib.msgeditor import (
33
34
    edit_commit_message_encoded
34
35
)
35
36
from bzrlib.tests import (
36
 
    features,
37
37
    TestCaseInTempDir,
38
38
    TestCaseWithTransport,
39
39
    TestNotApplicable,
80
80
""")
81
81
 
82
82
    def make_multiple_pending_tree(self):
83
 
        config.GlobalStack().set('email', 'Bilbo Baggins <bb@hobbit.net>')
 
83
        from bzrlib import config
 
84
        config.GlobalConfig().set_user_option('email',
 
85
                                              'Bilbo Baggins <bb@hobbit.net>')
84
86
        tree = self.make_branch_and_tree('a')
85
87
        tree.commit('Initial checkin.', timestamp=1230912900, timezone=0)
86
88
        tree2 = tree.bzrdir.clone('b').open_workingtree()
249
251
        self.overrideEnv('VISUAL', 'visual')
250
252
        self.overrideEnv('EDITOR', 'editor')
251
253
 
252
 
        conf = config.GlobalStack()
253
 
        conf.store._load_from_string('[DEFAULT]\neditor = config_editor\n')
254
 
        conf.store.save()
 
254
        conf = config.GlobalConfig.from_string('editor = config_editor\n',
 
255
                                               save=True)
 
256
 
255
257
        editors = list(msgeditor._get_editor())
256
258
        editors = [editor for (editor, cfg_src) in editors]
257
259
 
307
309
        self.assertFileEqual(expected, msgfilename)
308
310
 
309
311
    def test__create_temp_file_with_commit_template_in_unicode_dir(self):
310
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
312
        self.requireFeature(tests.UnicodeFilenameFeature)
311
313
        if hasattr(self, 'info'):
312
314
            tmpdir = self.info['directory']
313
315
            os.mkdir(tmpdir)
342
344
        self.assertRaises(errors.BadCommitMessageEncoding,
343
345
                          msgeditor.edit_commit_message, '')
344
346
 
345
 
    def test_set_commit_message_no_hooks(self):
346
 
        commit_obj = commit.Commit()
347
 
        self.assertIs(None,
348
 
            msgeditor.set_commit_message(commit_obj))
349
 
 
350
 
    def test_set_commit_message_hook(self):
351
 
        msgeditor.hooks.install_named_hook("set_commit_message",
352
 
                lambda commit_obj, existing_message: "save me some typing\n", None)
353
 
        commit_obj = commit.Commit()
354
 
        self.assertEqual("save me some typing\n",
355
 
            msgeditor.set_commit_message(commit_obj))
356
 
 
357
347
    def test_generate_commit_message_template_no_hooks(self):
358
348
        commit_obj = commit.Commit()
359
349
        self.assertIs(None,
363
353
        msgeditor.hooks.install_named_hook("commit_message_template",
364
354
                lambda commit_obj, msg: "save me some typing\n", None)
365
355
        commit_obj = commit.Commit()
366
 
        self.assertEqual("save me some typing\n",
 
356
        self.assertEquals("save me some typing\n",
367
357
            msgeditor.generate_commit_message_template(commit_obj))
368
358
 
369
359
 
378
368
        ERROR_BAD_EXE_FORMAT = 193
379
369
        file("textfile.txt", "w").close()
380
370
        e = self.assertRaises(WindowsError, subprocess.call, "textfile.txt")
381
 
        self.assertEqual(e.errno, errno.ENOEXEC)
382
 
        self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)
 
371
        # Python2.4 used the 'winerror' as the errno, which confuses a lot of
 
372
        # our error trapping code. Make sure that we understand the mapping
 
373
        # correctly.
 
374
        if sys.version_info >= (2, 5):
 
375
            self.assertEqual(e.errno, errno.ENOEXEC)
 
376
            self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)
 
377
        else:
 
378
            self.assertEqual(e.errno, ERROR_BAD_EXE_FORMAT)