~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2017-01-30 14:30:10 UTC
  • mfrom: (6615.3.7 merges)
  • mto: This revision was merged to the branch mainline in revision 6621.
  • Revision ID: v.ladeuil+lp@free.fr-20170130143010-p31t1ranfeqbaeki
Merge  2.7 into trunk including fix for bug #1657238

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
 
19
 
import sys
20
19
from cStringIO import StringIO
21
20
 
22
21
from bzrlib import (
23
22
    branch,
24
 
    bzrdir,
25
23
    merge_directive,
26
24
    tests,
27
25
    )
 
26
from bzrlib.controldir import ControlDir
28
27
from bzrlib.bundle import serializer
29
 
 
30
 
 
31
 
def load_tests(standard_tests, module, loader):
32
 
    """Multiply tests for the send command."""
33
 
    result = loader.suiteClass()
34
 
 
35
 
    # one for each king of change
36
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
37
 
        standard_tests, tests.condition_isinstance((
38
 
                TestSendStrictWithChanges,
39
 
                )))
40
 
    changes_scenarios = [
41
 
        ('uncommitted',
42
 
         dict(_changes_type='_uncommitted_changes')),
43
 
        ('pending_merges',
44
 
         dict(_changes_type='_pending_merges')),
45
 
        ('out-of-sync-trees',
46
 
         dict(_changes_type='_out_of_sync_trees')),
47
 
        ]
48
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
49
 
    # No parametrization for the remaining tests
50
 
    result.addTests(remaining_tests)
51
 
 
52
 
    return result
 
28
from bzrlib.transport import memory
 
29
from bzrlib.tests import (
 
30
    scenarios,
 
31
    )
 
32
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
33
 
 
34
 
 
35
load_tests = scenarios.load_tests_apply_scenarios
53
36
 
54
37
 
55
38
class TestSendMixin(object):
67
50
 
68
51
    def get_MD(self, args, cmd=None, wd='branch'):
69
52
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
70
 
        return merge_directive.MergeDirective.from_lines(out.readlines())
 
53
        return merge_directive.MergeDirective.from_lines(out)
71
54
 
72
55
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
73
56
        md = self.get_MD(args, cmd=cmd, wd=wd)
79
62
 
80
63
    def setUp(self):
81
64
        super(TestSend, self).setUp()
82
 
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
 
65
        grandparent_tree = ControlDir.create_standalone_workingtree(
83
66
            'grandparent')
84
67
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
85
68
        grandparent_tree.add('file1')
205
188
 
206
189
    def test_note_revisions(self):
207
190
        stderr = self.run_send([])[1]
208
 
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
 
191
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
209
192
 
210
193
    def test_mailto_option(self):
211
194
        b = branch.Branch.open('branch')
212
 
        b.get_config().set_user_option('mail_client', 'editor')
 
195
        b.get_config_stack().set('mail_client', 'editor')
213
196
        self.run_bzr_error(
214
197
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
215
198
            ), 'send -f branch')
216
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
199
        b.get_config_stack().set('mail_client', 'bogus')
217
200
        self.run_send([])
218
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
201
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
219
202
                           'send -f branch --mail-to jrandom@example.org')
220
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
221
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
203
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
 
204
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
222
205
                           'send -f branch')
223
206
 
224
207
    def test_mailto_child_option(self):
225
208
        """Make sure that child_submit_to is used."""
226
209
        b = branch.Branch.open('branch')
227
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
210
        b.get_config_stack().set('mail_client', 'bogus')
228
211
        parent = branch.Branch.open('parent')
229
 
        parent.get_config().set_user_option('child_submit_to',
230
 
                           'somebody@example.org')
231
 
        self.run_bzr_error(('Unknown mail client: bogus',),
232
 
                           'send -f branch')
 
212
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
 
213
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
 
214
                'send -f branch')
233
215
 
234
216
    def test_format(self):
235
217
        md = self.get_MD(['--format=4'])
247
229
                            'send -f branch -o- --format=0.999')[0]
248
230
 
249
231
    def test_format_child_option(self):
250
 
        parent_config = branch.Branch.open('parent').get_config()
251
 
        parent_config.set_user_option('child_submit_format', '4')
 
232
        br = branch.Branch.open('parent')
 
233
        conf = br.get_config_stack()
 
234
        conf.set('child_submit_format', '4')
252
235
        md = self.get_MD([])
253
236
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
254
237
 
255
 
        parent_config.set_user_option('child_submit_format', '0.9')
 
238
        conf.set('child_submit_format', '0.9')
256
239
        md = self.get_MD([])
257
240
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
258
241
 
260
243
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
261
244
        self.assertIs(merge_directive.MergeDirective, md.__class__)
262
245
 
263
 
        parent_config.set_user_option('child_submit_format', '0.999')
 
246
        conf.set('child_submit_format', '0.999')
264
247
        self.run_bzr_error(["No such send format '0.999'"],
265
248
                            'send -f branch -o-')[0]
266
249
 
280
263
        self.assertEqual('rev3', md.revision_id)
281
264
 
282
265
    def test_nonexistant_branch(self):
283
 
        if sys.platform == "win32":
284
 
            location = "C:/i/do/not/exist/"
285
 
        else:
286
 
            location = "/i/do/not/exist/"
 
266
        self.vfs_transport_factory = memory.MemoryServer
 
267
        location = self.get_url('absentdir/')
287
268
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
288
269
        self.assertEqual(out, '')
289
270
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
293
274
 
294
275
    def make_parent_and_local_branches(self):
295
276
        # Create a 'parent' branch as the base
296
 
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
 
277
        self.parent_tree = ControlDir.create_standalone_workingtree('parent')
297
278
        self.build_tree_contents([('parent/file', 'parent')])
298
279
        self.parent_tree.add('file')
299
280
        self.parent_tree.commit('first commit', rev_id='parent')
308
289
    _default_sent_revs = ['local']
309
290
    _default_errors = ['Working tree ".*/local/" has uncommitted '
310
291
                       'changes \(See bzr status\)\.',]
 
292
    _default_additional_error = 'Use --no-strict to force the send.\n'
 
293
    _default_additional_warning = 'Uncommitted changes will not be sent.'
311
294
 
312
295
    def set_config_send_strict(self, value):
313
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
314
 
        # should do)
315
 
        conf = self.local_tree.branch.get_config()
316
 
        conf.set_user_option('send_strict', value)
 
296
        br = branch.Branch.open('local')
 
297
        br.get_config_stack().set('send_strict', value)
317
298
 
318
299
    def assertSendFails(self, args):
319
 
        self.run_send(args, rc=3, err_re=self._default_errors)
 
300
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
 
301
        self.assertContainsRe(err, self._default_additional_error)
320
302
 
321
 
    def assertSendSucceeds(self, args, revs=None):
 
303
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
 
304
        if with_warning:
 
305
            err_re = self._default_errors
 
306
        else:
 
307
            err_re = []
322
308
        if revs is None:
323
309
            revs = self._default_sent_revs
324
 
        out, err = self.run_send(args)
325
 
        self.assertEquals(
326
 
            'Bundling %d revision(s).\n' % len(revs), err)
327
 
        md = merge_directive.MergeDirective.from_lines(
328
 
                StringIO(out).readlines())
 
310
        out, err = self.run_send(args, err_re=err_re)
 
311
        if len(revs) == 1:
 
312
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
313
        else:
 
314
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
 
315
        if with_warning:
 
316
            self.assertContainsRe(err, self._default_additional_warning)
 
317
            self.assertEndsWith(err, bundling_revs)
 
318
        else:
 
319
            self.assertEqual(bundling_revs, err)
 
320
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
329
321
        self.assertEqual('parent', md.base_revision_id)
330
322
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
331
323
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
338
330
        super(TestSendStrictWithoutChanges, self).setUp()
339
331
        self.make_parent_and_local_branches()
340
332
 
 
333
    def test_send_without_workingtree(self):
 
334
        ControlDir.open("local").destroy_workingtree()
 
335
        self.assertSendSucceeds([])
 
336
 
341
337
    def test_send_default(self):
342
338
        self.assertSendSucceeds([])
343
339
 
357
353
 
358
354
 
359
355
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
360
 
                                   TestSendStrictMixin):
 
356
                                TestSendStrictMixin):
 
357
 
 
358
    # These are textually the same as test_push.strict_push_change_scenarios,
 
359
    # but since the functions are reimplemented here, the definitions are left
 
360
    # here too.
 
361
    scenarios = [
 
362
        ('uncommitted',
 
363
         dict(_changes_type='_uncommitted_changes')),
 
364
        ('pending_merges',
 
365
         dict(_changes_type='_pending_merges')),
 
366
        ('out-of-sync-trees',
 
367
         dict(_changes_type='_out_of_sync_trees')),
 
368
        ]
361
369
 
362
370
    _changes_type = None # Set by load_tests
363
371
 
398
406
        self._default_sent_revs = ['modified-in-local', 'local']
399
407
 
400
408
    def test_send_default(self):
401
 
        self.assertSendFails([])
 
409
        self.assertSendSucceeds([], with_warning=True)
402
410
 
403
411
    def test_send_with_revision(self):
404
412
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
414
422
        self.assertSendFails([])
415
423
        self.assertSendSucceeds(['--no-strict'])
416
424
 
417
 
 
418
425
    def test_send_bogus_config_var_ignored(self):
419
426
        self.set_config_send_strict("I'm unsure")
420
 
        self.assertSendFails([])
421
 
 
 
427
        self.assertSendSucceeds([], with_warning=True)
422
428
 
423
429
    def test_send_no_strict_command_line_override_config(self):
424
430
        self.set_config_send_strict('true')
425
431
        self.assertSendFails([])
426
432
        self.assertSendSucceeds(['--no-strict'])
427
433
 
428
 
    def test_push_strict_command_line_override_config(self):
 
434
    def test_send_strict_command_line_override_config(self):
429
435
        self.set_config_send_strict('false')
430
436
        self.assertSendSucceeds([])
431
437
        self.assertSendFails(['--strict'])
434
440
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
435
441
 
436
442
    _default_command = ['bundle-revisions', '../parent']
 
443
 
 
444
 
 
445
class TestSmartServerSend(tests.TestCaseWithTransport):
 
446
 
 
447
    def test_send(self):
 
448
        self.setup_smart_server_with_call_log()
 
449
        t = self.make_branch_and_tree('branch')
 
450
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
451
        t.add("foo")
 
452
        t.commit("message")
 
453
        local = t.bzrdir.sprout('local-branch').open_workingtree()
 
454
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
 
455
        local.commit("anothermessage")
 
456
        self.reset_smart_call_log()
 
457
        out, err = self.run_bzr(
 
458
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
459
        # This figure represent the amount of work to perform this use case. It
 
460
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
461
        # being too low. If rpc_count increases, more network roundtrips have
 
462
        # become necessary for this use case. Please do not adjust this number
 
463
        # upwards without agreement from bzr's network support maintainers.
 
464
        self.assertLength(7, self.hpss_calls)
 
465
        self.assertLength(1, self.hpss_connections)
 
466
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)