~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: 2007-08-31 06:25:01 UTC
  • mfrom: (2772.1.1 show-diff)
  • Revision ID: pqm@pqm.ubuntu.com-20070831062501-zi3hbjphrmz4jv4x
Merge commit --show-diff feature from Goffredo

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import sys
22
22
 
 
23
from bzrlib import (
 
24
    errors,
 
25
    msgeditor,
 
26
    osutils,
 
27
    )
23
28
from bzrlib.branch import Branch
24
29
from bzrlib.config import ensure_config_dir_exists, config_filename
25
 
import bzrlib.msgeditor 
 
30
from bzrlib.msgeditor import (
 
31
    make_commit_message_template_encoded,
 
32
    edit_commit_message_encoded
 
33
)
26
34
from bzrlib.tests import TestCaseWithTransport, TestSkipped
27
35
from bzrlib.trace import mutter
28
36
 
29
 
from bzrlib import (
30
 
    osutils,
31
 
    errors
32
 
    )
33
 
 
34
 
 
35
37
class MsgEditorTest(TestCaseWithTransport):
36
38
 
37
39
    def make_uncommitted_tree(self):
50
52
    def test_commit_template(self):
51
53
        """Test building a commit message template"""
52
54
        working_tree = self.make_uncommitted_tree()
53
 
        template = bzrlib.msgeditor.make_commit_message_template(working_tree, None)
 
55
        template = msgeditor.make_commit_message_template(working_tree,
 
56
                                                                 None)
54
57
        self.assertEqualDiff(template,
55
58
u"""\
56
59
added:
57
60
  hell\u00d8
58
61
""")
59
62
 
 
63
    def test_commit_template_encoded(self):
 
64
        """Test building a commit message template"""
 
65
        working_tree = self.make_uncommitted_tree()
 
66
        template = make_commit_message_template_encoded(working_tree,
 
67
                                                        None,
 
68
                                                        output_encoding='utf8')
 
69
        self.assertEqualDiff(template,
 
70
u"""\
 
71
added:
 
72
  hell\u00d8
 
73
""".encode("utf8"))
 
74
 
 
75
 
 
76
    def test_commit_template_and_diff(self):
 
77
        """Test building a commit message template"""
 
78
        working_tree = self.make_uncommitted_tree()
 
79
        template = make_commit_message_template_encoded(working_tree,
 
80
                                                        None,
 
81
                                                        diff=True,
 
82
                                                        output_encoding='utf8')
 
83
 
 
84
        self.assertTrue("""\
 
85
@@ -0,0 +1,1 @@
 
86
+contents of hello
 
87
""" in template)
 
88
        self.assertTrue(u"""\
 
89
added:
 
90
  hell\u00d8
 
91
""".encode('utf8') in template)
 
92
 
60
93
    def setUp(self):
61
94
        super(MsgEditorTest, self).setUp()
62
95
        self._bzr_editor = os.environ.get('BZR_EDITOR', None)
82
115
            os.chmod('fed.sh', 0755)
83
116
            os.environ['BZR_EDITOR'] = './fed.sh'
84
117
 
85
 
        self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
 
118
        self.assertEqual(True, msgeditor._run_editor(''),
86
119
                         'Unable to run dummy fake editor')
87
120
 
88
121
    def make_fake_editor(self, message='test message from fed\\n'):
127
160
 
128
161
        mutter('edit_commit_message without infotext')
129
162
        self.assertEqual('test message from fed\n',
130
 
                         bzrlib.msgeditor.edit_commit_message(''))
 
163
                         msgeditor.edit_commit_message(''))
131
164
 
132
165
        mutter('edit_commit_message with unicode infotext')
133
166
        self.assertEqual('test message from fed\n',
134
 
                         bzrlib.msgeditor.edit_commit_message(u'\u1234'))
 
167
                         msgeditor.edit_commit_message(u'\u1234'))
 
168
 
 
169
        tmpl = edit_commit_message_encoded(u'\u1234'.encode("utf8"))
 
170
        self.assertEqual('test message from fed\n', tmpl)
135
171
 
136
172
    def test_start_message(self):
137
173
        self.make_uncommitted_tree()
138
174
        self.make_fake_editor()
139
175
        self.assertEqual('test message from fed\nstart message\n',
140
 
                         bzrlib.msgeditor.edit_commit_message('',
 
176
                         msgeditor.edit_commit_message('',
141
177
                                              start_message='start message\n'))
142
178
        self.assertEqual('test message from fed\n',
143
 
                         bzrlib.msgeditor.edit_commit_message('',
 
179
                         msgeditor.edit_commit_message('',
144
180
                                              start_message=''))
145
181
 
146
182
    def test_deleted_commit_message(self):
151
187
        else:
152
188
            os.environ['BZR_EDITOR'] = 'rm'
153
189
 
154
 
        self.assertRaises((IOError, OSError), bzrlib.msgeditor.edit_commit_message, '')
 
190
        self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
155
191
 
156
192
    def test__get_editor(self):
157
193
        # Test that _get_editor can return a decent list of items
168
204
            f.write('editor = config_editor\n')
169
205
            f.close()
170
206
 
171
 
            editors = list(bzrlib.msgeditor._get_editor())
 
207
            editors = list(msgeditor._get_editor())
172
208
 
173
209
            self.assertEqual(['bzr_editor', 'config_editor', 'visual',
174
210
                              'editor'], editors[:4])
197
233
    def test__create_temp_file_with_commit_template(self):
198
234
        # check that commit template written properly
199
235
        # and has platform native line-endings (CRLF on win32)
200
 
        create_file = bzrlib.msgeditor._create_temp_file_with_commit_template
 
236
        create_file = msgeditor._create_temp_file_with_commit_template
201
237
        msgfilename, hasinfo = create_file('infotext','----','start message')
202
238
        self.assertNotEqual(None, msgfilename)
203
239
        self.assertTrue(hasinfo)
211
247
 
212
248
    def test__create_temp_file_with_empty_commit_template(self):
213
249
        # empty file
214
 
        create_file = bzrlib.msgeditor._create_temp_file_with_commit_template
 
250
        create_file = msgeditor._create_temp_file_with_commit_template
215
251
        msgfilename, hasinfo = create_file('')
216
252
        self.assertNotEqual(None, msgfilename)
217
253
        self.assertFalse(hasinfo)
224
260
 
225
261
            working_tree = self.make_uncommitted_tree()
226
262
            self.assertRaises(errors.BadCommitMessageEncoding,
227
 
                                    bzrlib.msgeditor.edit_commit_message, '')
 
263
                              msgeditor.edit_commit_message, '')
228
264
        finally:
229
265
            osutils.set_or_unset_env('LANG', old_env)