~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
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.
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
6
7
#
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
79
80
        self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
80
81
                         'Unable to run dummy fake editor')
81
82
 
82
 
    def test_edit_commit_message(self):
83
 
        working_tree = self.make_uncommitted_tree()
84
 
        # make fake editor
 
83
    def make_fake_editor(self):
 
84
        """Set up environment so that an editor will be a known script.
 
85
 
 
86
        Sets up BZR_EDITOR so that if an editor is spawned it will run a
 
87
        script that just adds a known message to the start of the file.
 
88
        """
85
89
        f = file('fed.py', 'wb')
86
90
        f.write('#!%s\n' % sys.executable)
87
91
        f.write("""\
111
115
            os.chmod('fed.py', 0755)
112
116
            os.environ['BZR_EDITOR'] = './fed.py'
113
117
 
 
118
    def test_edit_commit_message(self):
 
119
        working_tree = self.make_uncommitted_tree()
 
120
        self.make_fake_editor()
 
121
 
114
122
        mutter('edit_commit_message without infotext')
115
123
        self.assertEqual('test message from fed\n',
116
124
                         bzrlib.msgeditor.edit_commit_message(''))
119
127
        self.assertEqual('test message from fed\n',
120
128
                         bzrlib.msgeditor.edit_commit_message(u'\u1234'))
121
129
 
 
130
    def test_start_message(self):
 
131
        self.make_uncommitted_tree()
 
132
        self.make_fake_editor()
 
133
        self.assertEqual('test message from fed\nstart message\n',
 
134
                         bzrlib.msgeditor.edit_commit_message('',
 
135
                                              start_message='start message\n'))
 
136
        self.assertEqual('test message from fed\n',
 
137
                         bzrlib.msgeditor.edit_commit_message('',
 
138
                                              start_message=''))
 
139
 
122
140
    def test_deleted_commit_message(self):
123
141
        working_tree = self.make_uncommitted_tree()
124
142
 
169
187
                del os.environ['EDITOR']
170
188
            else:
171
189
                os.environ['EDITOR'] = editor
 
190
 
 
191
    def test__create_temp_file_with_commit_template(self):
 
192
        # check that commit template written properly
 
193
        # and has platform native line-endings (CRLF on win32)
 
194
        create_file = bzrlib.msgeditor._create_temp_file_with_commit_template
 
195
        msgfilename, hasinfo = create_file('infotext','----','start message')
 
196
        self.assertNotEqual(None, msgfilename)
 
197
        self.assertTrue(hasinfo)
 
198
        expected = os.linesep.join(['start message',
 
199
                                    '',
 
200
                                    '',
 
201
                                    '----',
 
202
                                    '',
 
203
                                    'infotext'])
 
204
        self.assertFileEqual(expected, msgfilename)
 
205
 
 
206
    def test__create_temp_file_with_empty_commit_template(self):
 
207
        # empty file
 
208
        create_file = bzrlib.msgeditor._create_temp_file_with_commit_template
 
209
        msgfilename, hasinfo = create_file('')
 
210
        self.assertNotEqual(None, msgfilename)
 
211
        self.assertFalse(hasinfo)
 
212
        self.assertFileEqual('', msgfilename)