/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    tests,
30
30
    )
31
31
 
 
32
from breezy.tests.matchers import ContainsNoVfsCalls
32
33
from breezy.urlutils import joinpath
33
34
 
34
 
from ..test_bedding import override_whoami
35
35
 
36
36
class TestAnnotate(tests.TestCaseWithTransport):
37
37
 
39
39
        super(TestAnnotate, self).setUp()
40
40
        wt = self.make_branch_and_tree('.')
41
41
        b = wt.branch
42
 
        self.build_tree_contents([('hello.txt', b'my helicopter\n'),
43
 
                                  ('nomail.txt', b'nomail\n')])
 
42
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
 
43
                                  ('nomail.txt', 'nomail\n')])
44
44
        wt.add(['hello.txt'])
45
45
        self.revision_id_1 = wt.commit('add hello',
46
 
                                       committer='test@user',
47
 
                                       timestamp=1165960000.00, timezone=0)
 
46
                              committer='test@user',
 
47
                              timestamp=1165960000.00, timezone=0)
48
48
        wt.add(['nomail.txt'])
49
49
        self.revision_id_2 = wt.commit('add nomail',
50
 
                                       committer='no mail',
51
 
                                       timestamp=1165970000.00, timezone=0)
52
 
        self.build_tree_contents([('hello.txt', b'my helicopter\n'
53
 
                                                b'your helicopter\n')])
 
50
                              committer='no mail',
 
51
                              timestamp=1165970000.00, timezone=0)
 
52
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
53
                                                'your helicopter\n')])
54
54
        self.revision_id_3 = wt.commit('mod hello',
55
 
                                       committer='user@test',
56
 
                                       timestamp=1166040000.00, timezone=0)
57
 
        self.build_tree_contents([('hello.txt', b'my helicopter\n'
58
 
                                                b'your helicopter\n'
59
 
                                                b'all of\n'
60
 
                                                b'our helicopters\n'
61
 
                                   )])
 
55
                              committer='user@test',
 
56
                              timestamp=1166040000.00, timezone=0)
 
57
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
58
                                                'your helicopter\n'
 
59
                                                'all of\n'
 
60
                                                'our helicopters\n'
 
61
                                  )])
62
62
        self.revision_id_4 = wt.commit('mod hello',
63
 
                                       committer='user@test',
64
 
                                       timestamp=1166050000.00, timezone=0)
 
63
                              committer='user@test',
 
64
                              timestamp=1166050000.00, timezone=0)
65
65
 
66
66
    def test_help_annotate(self):
67
67
        """Annotate command exists"""
108
108
%*s | your helicopter
109
109
%*s | all of
110
110
%*s | our helicopters
111
 
''' % (max_len, self.revision_id_1.decode('utf-8'),
112
 
            max_len, self.revision_id_3.decode('utf-8'),
113
 
            max_len, self.revision_id_4.decode('utf-8'),
114
 
            max_len, '',
115
 
       ), out)
 
111
''' % (max_len, self.revision_id_1,
 
112
       max_len, self.revision_id_3,
 
113
       max_len, self.revision_id_4,
 
114
       max_len, '',
 
115
      )
 
116
, out)
116
117
 
117
118
    def test_no_mail(self):
118
119
        out, err = self.run_bzr('annotate nomail.txt')
158
159
        """Create a tree with a locally edited file."""
159
160
        tree = self.make_branch_and_tree(relpath)
160
161
        file_relpath = joinpath(relpath, 'file')
161
 
        self.build_tree_contents([(file_relpath, b'foo\ngam\n')])
 
162
        self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
162
163
        tree.add('file')
163
 
        tree.commit('add file', committer="test@host", rev_id=b"rev1")
164
 
        self.build_tree_contents([(file_relpath, b'foo\nbar\ngam\n')])
 
164
        tree.commit('add file', committer="test@host", rev_id="rev1")
 
165
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
166
        return tree
166
167
 
167
168
    def test_annotate_cmd_revspec_branch(self):
187
188
 
188
189
    def test_annotate_edited_file_no_default(self):
189
190
        # Ensure that when no username is available annotate still works.
190
 
        override_whoami(self)
 
191
        self.overrideEnv('EMAIL', None)
 
192
        self.overrideEnv('BRZ_EMAIL', None)
 
193
        # Also, make sure that it's not inferred from mailname.
 
194
        self.overrideAttr(config, '_auto_user_id',
 
195
            lambda: (None, None))
191
196
        tree = self._setup_edited_file()
192
197
        out, err = self.run_bzr('annotate file')
193
198
        self.assertEqual(
209
214
    def _create_merged_file(self):
210
215
        """Create a file with a pending merge and local edit."""
211
216
        tree = self.make_branch_and_tree('.')
212
 
        self.build_tree_contents([('file', b'foo\ngam\n')])
 
217
        self.build_tree_contents([('file', 'foo\ngam\n')])
213
218
        tree.add('file')
214
 
        tree.commit('add file', rev_id=b"rev1", committer="test@host")
 
219
        tree.commit('add file', rev_id="rev1", committer="test@host")
215
220
        # right side
216
 
        self.build_tree_contents([('file', b'foo\nbar\ngam\n')])
217
 
        tree.commit("right", rev_id=b"rev1.1.1", committer="test@host")
218
 
        tree.pull(tree.branch, True, b"rev1")
 
221
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
222
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
 
223
        tree.pull(tree.branch, True, "rev1")
219
224
        # left side
220
 
        self.build_tree_contents([('file', b'foo\nbaz\ngam\n')])
221
 
        tree.commit("left", rev_id=b"rev2", committer="test@host")
 
225
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
 
226
        tree.commit("left", rev_id="rev2", committer="test@host")
222
227
        # merge
223
 
        tree.merge_from_branch(tree.branch, b"rev1.1.1")
 
228
        tree.merge_from_branch(tree.branch, "rev1.1.1")
224
229
        # edit the file to be 'resolved' and have a further local edit
225
 
        self.build_tree_contents([('file', b'local\nfoo\nbar\nbaz\ngam\n')])
 
230
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
226
231
        return tree
227
232
 
228
233
    def test_annotated_edited_merged_file_revnos(self):
251
256
 
252
257
    def test_annotate_empty_file(self):
253
258
        tree = self.make_branch_and_tree('.')
254
 
        self.build_tree_contents([('empty', b'')])
 
259
        self.build_tree_contents([('empty', '')])
255
260
        tree.add('empty')
256
261
        tree.commit('add empty file')
257
262
        out, err = self.run_bzr(['annotate', 'empty'])
259
264
 
260
265
    def test_annotate_removed_file(self):
261
266
        tree = self.make_branch_and_tree('.')
262
 
        self.build_tree_contents([('empty', b'')])
 
267
        self.build_tree_contents([('empty', '')])
263
268
        tree.add('empty')
264
269
        tree.commit('add empty file')
265
270
        # delete the file.
270
275
 
271
276
    def test_annotate_empty_file_show_ids(self):
272
277
        tree = self.make_branch_and_tree('.')
273
 
        self.build_tree_contents([('empty', b'')])
 
278
        self.build_tree_contents([('empty', '')])
274
279
        tree.add('empty')
275
280
        tree.commit('add empty file')
276
281
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
287
292
 
288
293
    def test_annotate_without_workingtree(self):
289
294
        tree = self.make_branch_and_tree('.')
290
 
        self.build_tree_contents([('empty', b'')])
 
295
        self.build_tree_contents([('empty', '')])
291
296
        tree.add('empty')
292
297
        tree.commit('add empty file')
293
298
        bzrdir = tree.branch.controldir
299
304
    def test_annotate_directory(self):
300
305
        """Test --directory option"""
301
306
        wt = self.make_branch_and_tree('a')
302
 
        self.build_tree_contents([('a/hello.txt', b'my helicopter\n')])
 
307
        self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
303
308
        wt.add(['hello.txt'])
304
309
        wt.commit('commit', committer='test@user')
305
310
        out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
306
311
        self.assertEqualDiff('1   test@us | my helicopter\n', out)
 
312
 
 
313
 
 
314
class TestSmartServerAnnotate(tests.TestCaseWithTransport):
 
315
 
 
316
    def test_simple_annotate(self):
 
317
        self.setup_smart_server_with_call_log()
 
318
        wt = self.make_branch_and_tree('branch')
 
319
        self.build_tree_contents([('branch/hello.txt', 'my helicopter\n')])
 
320
        wt.add(['hello.txt'])
 
321
        wt.commit('commit', committer='test@user')
 
322
        self.reset_smart_call_log()
 
323
        out, err = self.run_bzr(['annotate', "-d", self.get_url('branch'),
 
324
            "hello.txt"])
 
325
        # This figure represent the amount of work to perform this use case. It
 
326
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
327
        # being too low. If rpc_count increases, more network roundtrips have
 
328
        # become necessary for this use case. Please do not adjust this number
 
329
        # upwards without agreement from bzr's network support maintainers.
 
330
        self.assertLength(16, self.hpss_calls)
 
331
        self.assertLength(1, self.hpss_connections)
 
332
        self.expectFailure("annotate accesses inventories, which require VFS access",
 
333
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)