~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_annotate.py

  • Committer: Vincent Ladeuil
  • Date: 2008-09-11 19:36:38 UTC
  • mfrom: (3703 +trunk)
  • mto: (3705.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 3708.
  • Revision ID: v.ladeuil+lp@free.fr-20080911193638-wtjyc1kcmacc6t1f
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
"""Black-box tests for bzr.
20
20
 
21
21
These check that it behaves properly when it's invoked through the regular
22
 
command-line interface. This doesn't actually run a new interpreter but
 
22
command-line interface. This doesn't actually run a new interpreter but 
23
23
rather starts again from the run_bzr function.
24
24
"""
25
25
 
26
26
 
27
 
from bzrlib import (
28
 
    config,
29
 
    tests,
30
 
    )
31
 
 
32
 
from bzrlib.urlutils import joinpath
33
 
 
34
 
 
35
 
class TestAnnotate(tests.TestCaseWithTransport):
 
27
import os
 
28
 
 
29
from bzrlib.tests import TestCaseWithTransport
 
30
 
 
31
 
 
32
class TestAnnotate(TestCaseWithTransport):
36
33
 
37
34
    def setUp(self):
38
35
        super(TestAnnotate, self).setUp()
140
137
        out, err = self.run_bzr('annotate hello.txt -r 10',
141
138
                                retcode=3)
142
139
        self.assertEqual('', out)
143
 
        self.assertContainsRe(err, "Requested revision: '10' does not exist")
 
140
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
144
141
 
145
142
    def test_annotate_cmd_two_revisions(self):
146
143
        out, err = self.run_bzr('annotate hello.txt -r1..2',
147
144
                                retcode=3)
148
145
        self.assertEqual('', out)
149
146
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
150
 
                         ' exactly one revision identifier\n',
 
147
                         ' exactly 1 argument\n',
151
148
                         err)
152
149
 
153
 
 
154
 
class TestSimpleAnnotate(tests.TestCaseWithTransport):
155
 
    """Annotate tests with no complex setup."""
156
 
 
157
 
    def _setup_edited_file(self, relpath='.'):
158
 
        """Create a tree with a locally edited file."""
159
 
        tree = self.make_branch_and_tree(relpath)
160
 
        file_relpath = joinpath(relpath, 'file')
161
 
        self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
162
 
        tree.add('file')
163
 
        tree.commit('add file', committer="test@host", rev_id="rev1")
164
 
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
 
        return tree
166
 
 
167
 
    def test_annotate_cmd_revspec_branch(self):
168
 
        tree = self._setup_edited_file('trunk')
169
 
        tree.branch.create_checkout(self.get_url('work'), lightweight=True)
170
 
        out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
171
 
                                working_dir='work')
172
 
        self.assertEqual('', err)
173
 
        self.assertEqual(
174
 
            '1   test@ho | foo\n'
175
 
            '            | gam\n',
176
 
            out)
177
 
 
178
 
    def test_annotate_edited_file(self):
179
 
        tree = self._setup_edited_file()
180
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
181
 
        out, err = self.run_bzr('annotate file')
182
 
        self.assertEqual(
183
 
            '1   test@ho | foo\n'
184
 
            '2?  current | bar\n'
185
 
            '1   test@ho | gam\n',
186
 
            out)
187
 
 
188
 
    def test_annotate_edited_file_no_default(self):
189
 
        # Ensure that when no username is available annotate still works.
190
 
        self.overrideEnv('EMAIL', None)
191
 
        self.overrideEnv('BZR_EMAIL', None)
192
 
        # Also, make sure that it's not inferred from mailname.
193
 
        self.overrideAttr(config, '_auto_user_id',
194
 
            lambda: (None, None))
195
 
        tree = self._setup_edited_file()
196
 
        out, err = self.run_bzr('annotate file')
197
 
        self.assertEqual(
198
 
            '1   test@ho | foo\n'
199
 
            '2?  local u | bar\n'
200
 
            '1   test@ho | gam\n',
201
 
            out)
202
 
 
203
 
    def test_annotate_edited_file_show_ids(self):
204
 
        tree = self._setup_edited_file()
205
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
206
 
        out, err = self.run_bzr('annotate file --show-ids')
207
 
        self.assertEqual(
208
 
            '    rev1 | foo\n'
209
 
            'current: | bar\n'
210
 
            '    rev1 | gam\n',
211
 
            out)
212
 
 
213
 
    def _create_merged_file(self):
214
 
        """Create a file with a pending merge and local edit."""
215
 
        tree = self.make_branch_and_tree('.')
216
 
        self.build_tree_contents([('file', 'foo\ngam\n')])
217
 
        tree.add('file')
218
 
        tree.commit('add file', rev_id="rev1", committer="test@host")
219
 
        # right side
220
 
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
221
 
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
222
 
        tree.pull(tree.branch, True, "rev1")
223
 
        # left side
224
 
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
225
 
        tree.commit("left", rev_id="rev2", committer="test@host")
226
 
        # merge
227
 
        tree.merge_from_branch(tree.branch, "rev1.1.1")
228
 
        # edit the file to be 'resolved' and have a further local edit
229
 
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
230
 
        return tree
231
 
 
232
 
    def test_annotated_edited_merged_file_revnos(self):
233
 
        wt = self._create_merged_file()
234
 
        out, err = self.run_bzr(['annotate', 'file'])
235
 
        email = config.extract_email_address(wt.branch.get_config().username())
236
 
        self.assertEqual(
237
 
            '3?    %-7s | local\n'
238
 
            '1     test@ho | foo\n'
239
 
            '1.1.1 test@ho | bar\n'
240
 
            '2     test@ho | baz\n'
241
 
            '1     test@ho | gam\n' % email[:7],
242
 
            out)
243
 
 
244
 
    def test_annotated_edited_merged_file_ids(self):
245
 
        self._create_merged_file()
246
 
        out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
247
 
        self.assertEqual(
248
 
            'current: | local\n'
249
 
            '    rev1 | foo\n'
250
 
            'rev1.1.1 | bar\n'
251
 
            '    rev2 | baz\n'
252
 
            '    rev1 | gam\n',
253
 
            out)
254
 
 
255
150
    def test_annotate_empty_file(self):
256
 
        tree = self.make_branch_and_tree('.')
257
 
        self.build_tree_contents([('empty', '')])
258
 
        tree.add('empty')
259
 
        tree.commit('add empty file')
260
 
        out, err = self.run_bzr(['annotate', 'empty'])
261
 
        self.assertEqual('', out)
262
 
 
263
 
    def test_annotate_removed_file(self):
264
 
        tree = self.make_branch_and_tree('.')
265
 
        self.build_tree_contents([('empty', '')])
266
 
        tree.add('empty')
267
 
        tree.commit('add empty file')
268
 
        # delete the file.
269
 
        tree.remove('empty')
270
 
        tree.commit('remove empty file')
271
 
        out, err = self.run_bzr(['annotate', '-r1', 'empty'])
272
 
        self.assertEqual('', out)
273
 
 
274
 
    def test_annotate_empty_file_show_ids(self):
275
 
        tree = self.make_branch_and_tree('.')
276
 
        self.build_tree_contents([('empty', '')])
277
 
        tree.add('empty')
278
 
        tree.commit('add empty file')
279
 
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
 
151
        tree = self.make_branch_and_tree('tree')
 
152
        self.build_tree_contents([('tree/empty', '')])
 
153
        tree.add('empty')
 
154
        tree.commit('add empty file')
 
155
 
 
156
        os.chdir('tree')
 
157
        out, err = self.run_bzr('annotate empty')
280
158
        self.assertEqual('', out)
281
159
 
282
160
    def test_annotate_nonexistant_file(self):
283
 
        tree = self.make_branch_and_tree('.')
284
 
        self.build_tree(['file'])
 
161
        tree = self.make_branch_and_tree('tree')
 
162
        self.build_tree(['tree/file'])
285
163
        tree.add(['file'])
286
164
        tree.commit('add a file')
287
 
        out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
 
165
 
 
166
        os.chdir('tree')
 
167
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
288
168
        self.assertEqual('', out)
289
169
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
290
170
 
291
171
    def test_annotate_without_workingtree(self):
292
 
        tree = self.make_branch_and_tree('.')
293
 
        self.build_tree_contents([('empty', '')])
 
172
        tree = self.make_branch_and_tree('branch')
 
173
        self.build_tree_contents([('branch/empty', '')])
294
174
        tree.add('empty')
295
175
        tree.commit('add empty file')
296
176
        bzrdir = tree.branch.bzrdir
297
177
        bzrdir.destroy_workingtree()
298
178
        self.assertFalse(bzrdir.has_workingtree())
299
 
        out, err = self.run_bzr(['annotate', 'empty'])
 
179
 
 
180
        os.chdir('branch')
 
181
        out, err = self.run_bzr('annotate empty')
300
182
        self.assertEqual('', out)
301
 
 
302
 
    def test_annotate_directory(self):
303
 
        """Test --directory option"""
304
 
        wt = self.make_branch_and_tree('a')
305
 
        self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
306
 
        wt.add(['hello.txt'])
307
 
        wt.commit('commit', committer='test@user')
308
 
        out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
309
 
        self.assertEqualDiff('1   test@us | my helicopter\n', out)