~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2011-09-22 14:12:18 UTC
  • mfrom: (6155.3.1 jam)
  • Revision ID: pqm@pqm.ubuntu.com-20110922141218-86s4uu6nqvourw4f
(jameinel) Cleanup comments bzrlib/smart/__init__.py (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
 
26
26
 
27
 
import os
 
27
from bzrlib import (
 
28
    config,
 
29
    tests,
 
30
    )
28
31
 
29
 
from bzrlib.branch import Branch
30
 
from bzrlib.config import extract_email_address
31
 
from bzrlib.tests import TestCaseWithTransport
32
32
from bzrlib.urlutils import joinpath
33
33
 
34
34
 
35
 
class TestAnnotate(TestCaseWithTransport):
 
35
class TestAnnotate(tests.TestCaseWithTransport):
36
36
 
37
37
    def setUp(self):
38
38
        super(TestAnnotate, self).setUp()
151
151
                         err)
152
152
 
153
153
 
154
 
class TestSimpleAnnotate(TestCaseWithTransport):
 
154
class TestSimpleAnnotate(tests.TestCaseWithTransport):
155
155
    """Annotate tests with no complex setup."""
156
156
 
157
157
    def _setup_edited_file(self, relpath='.'):
162
162
        tree.add('file')
163
163
        tree.commit('add file', committer="test@host", rev_id="rev1")
164
164
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
166
165
        return tree
167
166
 
168
167
    def test_annotate_cmd_revspec_branch(self):
169
168
        tree = self._setup_edited_file('trunk')
170
169
        tree.branch.create_checkout(self.get_url('work'), lightweight=True)
171
 
        os.chdir('work')
172
 
        out, err = self.run_bzr('annotate file -r branch:../trunk')
 
170
        out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
 
171
                                working_dir='work')
173
172
        self.assertEqual('', err)
174
173
        self.assertEqual(
175
174
            '1   test@ho | foo\n'
178
177
 
179
178
    def test_annotate_edited_file(self):
180
179
        tree = self._setup_edited_file()
 
180
        tree.branch.get_config().set_user_option('email', 'current@host2')
181
181
        out, err = self.run_bzr('annotate file')
182
182
        self.assertEqual(
183
183
            '1   test@ho | foo\n'
185
185
            '1   test@ho | gam\n',
186
186
            out)
187
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
 
188
203
    def test_annotate_edited_file_show_ids(self):
189
204
        tree = self._setup_edited_file()
 
205
        tree.branch.get_config().set_user_option('email', 'current@host2')
190
206
        out, err = self.run_bzr('annotate file --show-ids')
191
207
        self.assertEqual(
192
208
            '    rev1 | foo\n'
211
227
        tree.merge_from_branch(tree.branch, "rev1.1.1")
212
228
        # edit the file to be 'resolved' and have a further local edit
213
229
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
 
230
        return tree
214
231
 
215
232
    def test_annotated_edited_merged_file_revnos(self):
216
 
        self._create_merged_file()
217
 
        out, err = self.run_bzr('annotate file')
218
 
        email = extract_email_address(Branch.open('.').get_config().username())
 
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())
219
236
        self.assertEqual(
220
237
            '3?    %-7s | local\n'
221
238
            '1     test@ho | foo\n'
226
243
 
227
244
    def test_annotated_edited_merged_file_ids(self):
228
245
        self._create_merged_file()
229
 
        out, err = self.run_bzr('annotate file --show-ids')
 
246
        out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
230
247
        self.assertEqual(
231
248
            'current: | local\n'
232
249
            '    rev1 | foo\n'
236
253
            out)
237
254
 
238
255
    def test_annotate_empty_file(self):
239
 
        tree = self.make_branch_and_tree('tree')
240
 
        self.build_tree_contents([('tree/empty', '')])
 
256
        tree = self.make_branch_and_tree('.')
 
257
        self.build_tree_contents([('empty', '')])
241
258
        tree.add('empty')
242
259
        tree.commit('add empty file')
 
260
        out, err = self.run_bzr(['annotate', 'empty'])
 
261
        self.assertEqual('', out)
243
262
 
244
 
        os.chdir('tree')
245
 
        out, err = self.run_bzr('annotate empty')
 
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'])
246
272
        self.assertEqual('', out)
247
273
 
248
274
    def test_annotate_empty_file_show_ids(self):
249
 
        tree = self.make_branch_and_tree('tree')
250
 
        self.build_tree_contents([('tree/empty', '')])
 
275
        tree = self.make_branch_and_tree('.')
 
276
        self.build_tree_contents([('empty', '')])
251
277
        tree.add('empty')
252
278
        tree.commit('add empty file')
253
 
 
254
 
        os.chdir('tree')
255
279
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
256
280
        self.assertEqual('', out)
257
281
 
258
282
    def test_annotate_nonexistant_file(self):
259
 
        tree = self.make_branch_and_tree('tree')
260
 
        self.build_tree(['tree/file'])
 
283
        tree = self.make_branch_and_tree('.')
 
284
        self.build_tree(['file'])
261
285
        tree.add(['file'])
262
286
        tree.commit('add a file')
263
 
 
264
 
        os.chdir('tree')
265
 
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
 
287
        out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
266
288
        self.assertEqual('', out)
267
289
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
268
290
 
269
291
    def test_annotate_without_workingtree(self):
270
 
        tree = self.make_branch_and_tree('branch')
271
 
        self.build_tree_contents([('branch/empty', '')])
 
292
        tree = self.make_branch_and_tree('.')
 
293
        self.build_tree_contents([('empty', '')])
272
294
        tree.add('empty')
273
295
        tree.commit('add empty file')
274
296
        bzrdir = tree.branch.bzrdir
275
297
        bzrdir.destroy_workingtree()
276
298
        self.assertFalse(bzrdir.has_workingtree())
277
 
 
278
 
        os.chdir('branch')
279
 
        out, err = self.run_bzr('annotate empty')
 
299
        out, err = self.run_bzr(['annotate', 'empty'])
280
300
        self.assertEqual('', out)
281
301
 
282
302
    def test_annotate_directory(self):
285
305
        self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
286
306
        wt.add(['hello.txt'])
287
307
        wt.commit('commit', committer='test@user')
288
 
        out, err = self.run_bzr('annotate -d a hello.txt')
 
308
        out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
289
309
        self.assertEqualDiff('1   test@us | my helicopter\n', out)