/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.33.72 by Martin Pool
Fix commit message template for non-ascii files, and add test for handling of
1
# Copyright (C) 2005 by Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
"""Test commit message editor.
17
"""
18
19
import os
20
import sys
21
22
from bzrlib.branch import Branch
1185.50.93 by John Arbash Meinel
Added a test for the new list of editors.
23
from bzrlib.config import ensure_config_dir_exists, config_filename
24
from bzrlib.msgeditor import make_commit_message_template, _get_editor
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
25
from bzrlib.tests import TestCaseWithTransport, TestSkipped
26
27
28
class MsgEditorTest(TestCaseWithTransport):
1185.33.72 by Martin Pool
Fix commit message template for non-ascii files, and add test for handling of
29
1526.1.4 by Robert Collins
forgot my self.
30
    def make_uncommitted_tree(self):
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
31
        """Build a branch with uncommitted unicode named changes in the cwd."""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
32
        working_tree = self.make_branch_and_tree('.')
33
        b = working_tree.branch
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
34
        filename = u'hell\u00d8'
1526.1.3 by Robert Collins
Merge from upstream.
35
        try:
36
            self.build_tree_contents([(filename, 'contents of hello')])
37
        except UnicodeEncodeError:
38
            raise TestSkipped("can't build unicode working tree in "
1185.33.97 by Martin Pool
MsgEditor tests should be skipped on platforms without unicode fs.
39
                "filesystem encoding %s" % sys.getfilesystemencoding())
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
40
        working_tree.add(filename)
41
        return working_tree
42
    
1185.33.72 by Martin Pool
Fix commit message template for non-ascii files, and add test for handling of
43
    def test_commit_template(self):
44
        """Test building a commit message template"""
1526.1.2 by Robert Collins
Fix typo in my msgeditor test changes.
45
        working_tree = self.make_uncommitted_tree()
1185.33.72 by Martin Pool
Fix commit message template for non-ascii files, and add test for handling of
46
        template = make_commit_message_template(working_tree, None)
47
        self.assertEqualDiff(template,
48
u"""\
49
added:
50
  hell\u00d8
51
""")
1185.50.93 by John Arbash Meinel
Added a test for the new list of editors.
52
53
    def test__get_editor(self):
54
        # Test that _get_editor can return a decent list of items
55
        bzr_editor = os.environ.get('BZR_EDITOR')
56
        editor = os.environ.get('EDITOR')
57
        try:
58
            os.environ['BZR_EDITOR'] = 'bzr_editor'
59
            os.environ['EDITOR'] = 'editor'
60
61
            ensure_config_dir_exists()
62
            f = open(config_filename(), 'wb')
63
            f.write('editor = config_editor\n')
64
            f.close()
65
66
            editors = list(_get_editor())
67
68
            self.assertEqual(['bzr_editor', 'config_editor', 'editor'],
69
                editors[:3])
70
71
            if sys.platform == 'win32':
72
                self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[3:])
73
            else:
74
                self.assertEqual(['vi', 'pico', 'nano', 'joe'], editors[3:])
75
76
        finally:
77
            # Restore the environment
78
            if bzr_editor is None:
79
                del os.environ['BZR_EDITOR']
80
            else:
81
                os.environ['BZR_EDITOR'] = bzr_editor
82
            if editor is None:
83
                del os.environ['EDITOR']
84
            else:
85
                os.environ['EDITOR'] = editor
86