~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Starr-Bochicchio
  • Date: 2015-07-31 01:04:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6606.
  • Revision ID: a.starr.b@gmail.com-20150731010441-3domwjjtnjijxlr2
Use hexlify() from binascii directly as paramiko removed hexify().

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
from bzrlib.tests.matchers import ContainsNoVfsCalls
32
33
from bzrlib.urlutils import joinpath
33
34
 
34
35
 
35
 
class TestAnnotate(TestCaseWithTransport):
 
36
class TestAnnotate(tests.TestCaseWithTransport):
36
37
 
37
38
    def setUp(self):
38
39
        super(TestAnnotate, self).setUp()
151
152
                         err)
152
153
 
153
154
 
154
 
class TestSimpleAnnotate(TestCaseWithTransport):
 
155
class TestSimpleAnnotate(tests.TestCaseWithTransport):
155
156
    """Annotate tests with no complex setup."""
156
157
 
157
158
    def _setup_edited_file(self, relpath='.'):
162
163
        tree.add('file')
163
164
        tree.commit('add file', committer="test@host", rev_id="rev1")
164
165
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
165
 
        tree.branch.get_config().set_user_option('email', 'current@host2')
166
166
        return tree
167
167
 
168
168
    def test_annotate_cmd_revspec_branch(self):
169
169
        tree = self._setup_edited_file('trunk')
170
170
        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')
 
171
        out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
 
172
                                working_dir='work')
173
173
        self.assertEqual('', err)
174
174
        self.assertEqual(
175
175
            '1   test@ho | foo\n'
178
178
 
179
179
    def test_annotate_edited_file(self):
180
180
        tree = self._setup_edited_file()
 
181
        self.overrideEnv('BZR_EMAIL', 'current@host2')
181
182
        out, err = self.run_bzr('annotate file')
182
183
        self.assertEqual(
183
184
            '1   test@ho | foo\n'
185
186
            '1   test@ho | gam\n',
186
187
            out)
187
188
 
 
189
    def test_annotate_edited_file_no_default(self):
 
190
        # Ensure that when no username is available annotate still works.
 
191
        self.overrideEnv('EMAIL', None)
 
192
        self.overrideEnv('BZR_EMAIL', None)
 
193
        # Also, make sure that it's not inferred from mailname.
 
194
        self.overrideAttr(config, '_auto_user_id',
 
195
            lambda: (None, None))
 
196
        tree = self._setup_edited_file()
 
197
        out, err = self.run_bzr('annotate file')
 
198
        self.assertEqual(
 
199
            '1   test@ho | foo\n'
 
200
            '2?  local u | bar\n'
 
201
            '1   test@ho | gam\n',
 
202
            out)
 
203
 
188
204
    def test_annotate_edited_file_show_ids(self):
189
205
        tree = self._setup_edited_file()
 
206
        self.overrideEnv('BZR_EMAIL', 'current@host2')
190
207
        out, err = self.run_bzr('annotate file --show-ids')
191
208
        self.assertEqual(
192
209
            '    rev1 | foo\n'
211
228
        tree.merge_from_branch(tree.branch, "rev1.1.1")
212
229
        # edit the file to be 'resolved' and have a further local edit
213
230
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
 
231
        return tree
214
232
 
215
233
    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())
 
234
        wt = self._create_merged_file()
 
235
        out, err = self.run_bzr(['annotate', 'file'])
 
236
        email = config.extract_email_address(
 
237
            wt.branch.get_config_stack().get('email'))
219
238
        self.assertEqual(
220
239
            '3?    %-7s | local\n'
221
240
            '1     test@ho | foo\n'
226
245
 
227
246
    def test_annotated_edited_merged_file_ids(self):
228
247
        self._create_merged_file()
229
 
        out, err = self.run_bzr('annotate file --show-ids')
 
248
        out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
230
249
        self.assertEqual(
231
250
            'current: | local\n'
232
251
            '    rev1 | foo\n'
236
255
            out)
237
256
 
238
257
    def test_annotate_empty_file(self):
239
 
        tree = self.make_branch_and_tree('tree')
240
 
        self.build_tree_contents([('tree/empty', '')])
 
258
        tree = self.make_branch_and_tree('.')
 
259
        self.build_tree_contents([('empty', '')])
241
260
        tree.add('empty')
242
261
        tree.commit('add empty file')
 
262
        out, err = self.run_bzr(['annotate', 'empty'])
 
263
        self.assertEqual('', out)
243
264
 
244
 
        os.chdir('tree')
245
 
        out, err = self.run_bzr('annotate empty')
 
265
    def test_annotate_removed_file(self):
 
266
        tree = self.make_branch_and_tree('.')
 
267
        self.build_tree_contents([('empty', '')])
 
268
        tree.add('empty')
 
269
        tree.commit('add empty file')
 
270
        # delete the file.
 
271
        tree.remove('empty')
 
272
        tree.commit('remove empty file')
 
273
        out, err = self.run_bzr(['annotate', '-r1', 'empty'])
246
274
        self.assertEqual('', out)
247
275
 
248
276
    def test_annotate_empty_file_show_ids(self):
249
 
        tree = self.make_branch_and_tree('tree')
250
 
        self.build_tree_contents([('tree/empty', '')])
 
277
        tree = self.make_branch_and_tree('.')
 
278
        self.build_tree_contents([('empty', '')])
251
279
        tree.add('empty')
252
280
        tree.commit('add empty file')
253
 
 
254
 
        os.chdir('tree')
255
281
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
256
282
        self.assertEqual('', out)
257
283
 
258
284
    def test_annotate_nonexistant_file(self):
259
 
        tree = self.make_branch_and_tree('tree')
260
 
        self.build_tree(['tree/file'])
 
285
        tree = self.make_branch_and_tree('.')
 
286
        self.build_tree(['file'])
261
287
        tree.add(['file'])
262
288
        tree.commit('add a file')
263
 
 
264
 
        os.chdir('tree')
265
 
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
 
289
        out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
266
290
        self.assertEqual('', out)
267
291
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
268
292
 
269
293
    def test_annotate_without_workingtree(self):
270
 
        tree = self.make_branch_and_tree('branch')
271
 
        self.build_tree_contents([('branch/empty', '')])
 
294
        tree = self.make_branch_and_tree('.')
 
295
        self.build_tree_contents([('empty', '')])
272
296
        tree.add('empty')
273
297
        tree.commit('add empty file')
274
298
        bzrdir = tree.branch.bzrdir
275
299
        bzrdir.destroy_workingtree()
276
300
        self.assertFalse(bzrdir.has_workingtree())
277
 
 
278
 
        os.chdir('branch')
279
 
        out, err = self.run_bzr('annotate empty')
 
301
        out, err = self.run_bzr(['annotate', 'empty'])
280
302
        self.assertEqual('', out)
281
303
 
282
304
    def test_annotate_directory(self):
285
307
        self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
286
308
        wt.add(['hello.txt'])
287
309
        wt.commit('commit', committer='test@user')
288
 
        out, err = self.run_bzr('annotate -d a hello.txt')
 
310
        out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
289
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)