~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: Wouter van Heyst
  • Date: 2006-06-07 16:05:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060607160527-2b3649154d0e2e84
more code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by 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 as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
 
4
# it under the terms of the GNU General Public License version 2 as published by
 
5
# the Free Software Foundation.
7
6
#
8
7
# This program is distributed in the hope that it will be useful,
9
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
57
56
        self._bzr_editor = os.environ.get('BZR_EDITOR', None)
58
57
 
59
58
    def tearDown(self):
60
 
        if self._bzr_editor is not None:
 
59
        if self._bzr_editor != None:
61
60
            os.environ['BZR_EDITOR'] = self._bzr_editor
62
61
        else:
63
 
            if os.environ.get('BZR_EDITOR', None) is not None:
 
62
            if os.environ.get('BZR_EDITOR', None) != None:
64
63
                del os.environ['BZR_EDITOR']
65
64
        super(MsgEditorTest, self).tearDown()
66
65
 
80
79
        self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
81
80
                         'Unable to run dummy fake editor')
82
81
 
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
 
        """
 
82
    def test_edit_commit_message(self):
 
83
        working_tree = self.make_uncommitted_tree()
 
84
        # make fake editor
89
85
        f = file('fed.py', 'wb')
90
86
        f.write('#!%s\n' % sys.executable)
91
87
        f.write("""\
106
102
            f = file('fed.bat', 'w')
107
103
            f.write("""\
108
104
@echo off
109
 
"%s" fed.py %%1
 
105
%s fed.py %%1
110
106
""" % sys.executable)
111
107
            f.close()
112
108
            os.environ['BZR_EDITOR'] = 'fed.bat'
115
111
            os.chmod('fed.py', 0755)
116
112
            os.environ['BZR_EDITOR'] = './fed.py'
117
113
 
118
 
    def test_edit_commit_message(self):
119
 
        working_tree = self.make_uncommitted_tree()
120
 
        self.make_fake_editor()
121
 
 
122
114
        mutter('edit_commit_message without infotext')
123
115
        self.assertEqual('test message from fed\n',
124
116
                         bzrlib.msgeditor.edit_commit_message(''))
127
119
        self.assertEqual('test message from fed\n',
128
120
                         bzrlib.msgeditor.edit_commit_message(u'\u1234'))
129
121
 
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
 
 
140
122
    def test_deleted_commit_message(self):
141
123
        working_tree = self.make_uncommitted_tree()
142
124
 
143
125
        if sys.platform == 'win32':
144
 
            os.environ['BZR_EDITOR'] = 'cmd.exe /c del'
 
126
            os.environ['BZR_EDITOR'] = 'del'
145
127
        else:
146
128
            os.environ['BZR_EDITOR'] = 'rm'
147
129
 
187
169
                del os.environ['EDITOR']
188
170
            else:
189
171
                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)