~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2009-06-02 19:56:24 UTC
  • mto: This revision was merged to the branch mainline in revision 4469.
  • Revision ID: john@arbash-meinel.com-20090602195624-utljsyz0qgmq63lg
Add a chunks_to_gzip function.
This allows the _record_to_data code to build up a list of chunks,
rather than requiring a single string.
It should be ~ the same performance when using a single string, since
we are only adding a for() loop over the chunks and an if check.
We could possibly just remove the if check and not worry about adding
some empty strings in there.

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
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.branch import Branch
 
30
from bzrlib.config import extract_email_address
 
31
from bzrlib.tests import TestCaseWithTransport
 
32
 
 
33
 
 
34
class TestAnnotate(TestCaseWithTransport):
36
35
 
37
36
    def setUp(self):
38
37
        super(TestAnnotate, self).setUp()
140
139
        out, err = self.run_bzr('annotate hello.txt -r 10',
141
140
                                retcode=3)
142
141
        self.assertEqual('', out)
143
 
        self.assertContainsRe(err, "Requested revision: '10' does not exist")
 
142
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
144
143
 
145
144
    def test_annotate_cmd_two_revisions(self):
146
145
        out, err = self.run_bzr('annotate hello.txt -r1..2',
151
150
                         err)
152
151
 
153
152
 
154
 
class TestSimpleAnnotate(tests.TestCaseWithTransport):
 
153
class TestSimpleAnnotate(TestCaseWithTransport):
155
154
    """Annotate tests with no complex setup."""
156
155
 
157
 
    def _setup_edited_file(self, relpath='.'):
 
156
    def _setup_edited_file(self):
158
157
        """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')])
 
158
        tree = self.make_branch_and_tree('.')
 
159
        self.build_tree_contents([('file', 'foo\ngam\n')])
162
160
        tree.add('file')
163
161
        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)
 
162
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
163
        tree.branch.get_config().set_user_option('email', 'current@host2')
177
164
 
178
165
    def test_annotate_edited_file(self):
179
166
        tree = self._setup_edited_file()
180
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
181
167
        out, err = self.run_bzr('annotate file')
182
168
        self.assertEqual(
183
169
            '1   test@ho | foo\n'
185
171
            '1   test@ho | gam\n',
186
172
            out)
187
173
 
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
174
    def test_annotate_edited_file_show_ids(self):
204
175
        tree = self._setup_edited_file()
205
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
206
176
        out, err = self.run_bzr('annotate file --show-ids')
207
177
        self.assertEqual(
208
178
            '    rev1 | foo\n'
227
197
        tree.merge_from_branch(tree.branch, "rev1.1.1")
228
198
        # edit the file to be 'resolved' and have a further local edit
229
199
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
230
 
        return tree
231
200
 
232
201
    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())
 
202
        self._create_merged_file()
 
203
        out, err = self.run_bzr('annotate file')
 
204
        email = extract_email_address(Branch.open('.').get_config().username())
236
205
        self.assertEqual(
237
206
            '3?    %-7s | local\n'
238
207
            '1     test@ho | foo\n'
243
212
 
244
213
    def test_annotated_edited_merged_file_ids(self):
245
214
        self._create_merged_file()
246
 
        out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
 
215
        out, err = self.run_bzr('annotate file --show-ids')
247
216
        self.assertEqual(
248
217
            'current: | local\n'
249
218
            '    rev1 | foo\n'
253
222
            out)
254
223
 
255
224
    def test_annotate_empty_file(self):
256
 
        tree = self.make_branch_and_tree('.')
257
 
        self.build_tree_contents([('empty', '')])
 
225
        tree = self.make_branch_and_tree('tree')
 
226
        self.build_tree_contents([('tree/empty', '')])
258
227
        tree.add('empty')
259
228
        tree.commit('add empty file')
260
 
        out, err = self.run_bzr(['annotate', 'empty'])
261
 
        self.assertEqual('', out)
262
229
 
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'])
 
230
        os.chdir('tree')
 
231
        out, err = self.run_bzr('annotate empty')
272
232
        self.assertEqual('', out)
273
233
 
274
234
    def test_annotate_empty_file_show_ids(self):
275
 
        tree = self.make_branch_and_tree('.')
276
 
        self.build_tree_contents([('empty', '')])
 
235
        tree = self.make_branch_and_tree('tree')
 
236
        self.build_tree_contents([('tree/empty', '')])
277
237
        tree.add('empty')
278
238
        tree.commit('add empty file')
 
239
 
 
240
        os.chdir('tree')
279
241
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
280
242
        self.assertEqual('', out)
281
243
 
282
244
    def test_annotate_nonexistant_file(self):
283
 
        tree = self.make_branch_and_tree('.')
284
 
        self.build_tree(['file'])
 
245
        tree = self.make_branch_and_tree('tree')
 
246
        self.build_tree(['tree/file'])
285
247
        tree.add(['file'])
286
248
        tree.commit('add a file')
287
 
        out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
 
249
 
 
250
        os.chdir('tree')
 
251
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
288
252
        self.assertEqual('', out)
289
253
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
290
254
 
291
255
    def test_annotate_without_workingtree(self):
292
 
        tree = self.make_branch_and_tree('.')
293
 
        self.build_tree_contents([('empty', '')])
 
256
        tree = self.make_branch_and_tree('branch')
 
257
        self.build_tree_contents([('branch/empty', '')])
294
258
        tree.add('empty')
295
259
        tree.commit('add empty file')
296
260
        bzrdir = tree.branch.bzrdir
297
261
        bzrdir.destroy_workingtree()
298
262
        self.assertFalse(bzrdir.has_workingtree())
299
 
        out, err = self.run_bzr(['annotate', 'empty'])
 
263
 
 
264
        os.chdir('branch')
 
265
        out, err = self.run_bzr('annotate empty')
300
266
        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)