/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_send.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
 
from cStringIO import StringIO
21
 
 
22
 
from bzrlib import (
 
19
from ... import (
23
20
    branch,
24
 
    bzrdir,
25
21
    merge_directive,
26
22
    tests,
27
23
    )
28
 
from bzrlib.bundle import serializer
29
 
from bzrlib.transport import memory
30
 
 
31
 
 
32
 
def load_tests(standard_tests, module, loader):
33
 
    """Multiply tests for the send command."""
34
 
    result = loader.suiteClass()
35
 
 
36
 
    # one for each king of change
37
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
38
 
        standard_tests, tests.condition_isinstance((
39
 
                TestSendStrictWithChanges,
40
 
                )))
41
 
    changes_scenarios = [
42
 
        ('uncommitted',
43
 
         dict(_changes_type='_uncommitted_changes')),
44
 
        ('pending_merges',
45
 
         dict(_changes_type='_pending_merges')),
46
 
        ('out-of-sync-trees',
47
 
         dict(_changes_type='_out_of_sync_trees')),
48
 
        ]
49
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
50
 
    # No parametrization for the remaining tests
51
 
    result.addTests(remaining_tests)
52
 
 
53
 
    return result
 
24
from ...controldir import ControlDir
 
25
from ...bundle import serializer
 
26
from ...sixish import (
 
27
    BytesIO,
 
28
    )
 
29
from ...transport import memory
 
30
from .. import (
 
31
    scenarios,
 
32
    )
 
33
from ..matchers import ContainsNoVfsCalls
 
34
 
 
35
 
 
36
load_tests = scenarios.load_tests_apply_scenarios
54
37
 
55
38
 
56
39
class TestSendMixin(object):
67
50
                            error_regexes=err_re)
68
51
 
69
52
    def get_MD(self, args, cmd=None, wd='branch'):
70
 
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
 
53
        out = BytesIO(self.run_send(args, cmd=cmd, wd=wd)[0])
71
54
        return merge_directive.MergeDirective.from_lines(out)
72
55
 
73
56
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
74
57
        md = self.get_MD(args, cmd=cmd, wd=wd)
75
 
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
58
        br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
76
59
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
77
60
 
78
61
 
80
63
 
81
64
    def setUp(self):
82
65
        super(TestSend, self).setUp()
83
 
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
 
66
        grandparent_tree = ControlDir.create_standalone_workingtree(
84
67
            'grandparent')
85
 
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
 
68
        self.build_tree_contents([('grandparent/file1', b'grandparent')])
86
69
        grandparent_tree.add('file1')
87
 
        grandparent_tree.commit('initial commit', rev_id='rev1')
 
70
        grandparent_tree.commit('initial commit', rev_id=b'rev1')
88
71
 
89
 
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
 
72
        parent_bzrdir = grandparent_tree.controldir.sprout('parent')
90
73
        parent_tree = parent_bzrdir.open_workingtree()
91
 
        parent_tree.commit('next commit', rev_id='rev2')
 
74
        parent_tree.commit('next commit', rev_id=b'rev2')
92
75
 
93
 
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
94
 
        self.build_tree_contents([('branch/file1', 'branch')])
95
 
        branch_tree.commit('last commit', rev_id='rev3')
 
76
        branch_tree = parent_tree.controldir.sprout('branch').open_workingtree()
 
77
        self.build_tree_contents([('branch/file1', b'branch')])
 
78
        branch_tree.commit('last commit', rev_id=b'rev3')
96
79
 
97
80
    def assertFormatIs(self, fmt_string, md):
98
81
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
130
113
 
131
114
        err = self.run_send(['--remember'], rc=3)[1]
132
115
        self.assertContainsRe(err,
133
 
                              '--remember requires a branch to be specified.')
 
116
                              b'--remember requires a branch to be specified.')
134
117
 
135
118
    def test_revision_branch_interaction(self):
136
119
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
167
150
        md = self.get_MD(['--no-patch'])
168
151
        self.assertIsNot(None, md.bundle)
169
152
        self.assertIs(None, md.patch)
170
 
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
 
153
        self.run_bzr_error([b'Format 0.9 does not permit bundle with no patch'],
171
154
                           ['send', '--no-patch', '--format=0.9', '-o-'],
172
155
                           working_dir='branch')
173
156
        md = self.get_MD(['--no-bundle', '.', '.'])
206
189
 
207
190
    def test_note_revisions(self):
208
191
        stderr = self.run_send([])[1]
209
 
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
 
192
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
210
193
 
211
194
    def test_mailto_option(self):
212
195
        b = branch.Branch.open('branch')
213
 
        b.get_config().set_user_option('mail_client', 'editor')
 
196
        b.get_config_stack().set('mail_client', 'editor')
214
197
        self.run_bzr_error(
215
198
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
216
199
            ), 'send -f branch')
217
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
200
        b.get_config_stack().set('mail_client', 'bogus')
218
201
        self.run_send([])
219
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
202
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
220
203
                           'send -f branch --mail-to jrandom@example.org')
221
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
222
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
204
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
 
205
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
223
206
                           'send -f branch')
224
207
 
225
208
    def test_mailto_child_option(self):
226
209
        """Make sure that child_submit_to is used."""
227
210
        b = branch.Branch.open('branch')
228
 
        b.get_config().set_user_option('mail_client', 'bogus')
 
211
        b.get_config_stack().set('mail_client', 'bogus')
229
212
        parent = branch.Branch.open('parent')
230
 
        parent.get_config().set_user_option('child_submit_to',
231
 
                           'somebody@example.org')
232
 
        self.run_bzr_error(('Unknown mail client: bogus',),
233
 
                           'send -f branch')
 
213
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
 
214
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
 
215
                'send -f branch')
234
216
 
235
217
    def test_format(self):
236
218
        md = self.get_MD(['--format=4'])
244
226
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
245
227
        self.assertIs(merge_directive.MergeDirective, md.__class__)
246
228
 
247
 
        self.run_bzr_error(['Bad value .* for option .format.'],
 
229
        self.run_bzr_error([b'Bad value .* for option .format.'],
248
230
                            'send -f branch -o- --format=0.999')[0]
249
231
 
250
232
    def test_format_child_option(self):
251
 
        parent_config = branch.Branch.open('parent').get_config()
252
 
        parent_config.set_user_option('child_submit_format', '4')
 
233
        br = branch.Branch.open('parent')
 
234
        conf = br.get_config_stack()
 
235
        conf.set('child_submit_format', '4')
253
236
        md = self.get_MD([])
254
237
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
255
238
 
256
 
        parent_config.set_user_option('child_submit_format', '0.9')
 
239
        conf.set('child_submit_format', '0.9')
257
240
        md = self.get_MD([])
258
241
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
259
242
 
261
244
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
262
245
        self.assertIs(merge_directive.MergeDirective, md.__class__)
263
246
 
264
 
        parent_config.set_user_option('child_submit_format', '0.999')
265
 
        self.run_bzr_error(["No such send format '0.999'"],
 
247
        conf.set('child_submit_format', '0.999')
 
248
        self.run_bzr_error([b"No such send format '0.999'"],
266
249
                            'send -f branch -o-')[0]
267
250
 
268
251
    def test_message_option(self):
285
268
        location = self.get_url('absentdir/')
286
269
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
287
270
        self.assertEqual(out, '')
288
 
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
 
271
        self.assertEqual(err, 'brz: ERROR: Not a branch: "%s".\n' % location)
289
272
 
290
273
 
291
274
class TestSendStrictMixin(TestSendMixin):
292
275
 
293
276
    def make_parent_and_local_branches(self):
294
277
        # Create a 'parent' branch as the base
295
 
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
296
 
        self.build_tree_contents([('parent/file', 'parent')])
 
278
        self.parent_tree = ControlDir.create_standalone_workingtree('parent')
 
279
        self.build_tree_contents([('parent/file', b'parent')])
297
280
        self.parent_tree.add('file')
298
 
        self.parent_tree.commit('first commit', rev_id='parent')
 
281
        self.parent_tree.commit('first commit', rev_id=b'parent')
299
282
        # Branch 'local' from parent and do a change
300
 
        local_bzrdir = self.parent_tree.bzrdir.sprout('local')
 
283
        local_bzrdir = self.parent_tree.controldir.sprout('local')
301
284
        self.local_tree = local_bzrdir.open_workingtree()
302
 
        self.build_tree_contents([('local/file', 'local')])
303
 
        self.local_tree.commit('second commit', rev_id='local')
 
285
        self.build_tree_contents([('local/file', b'local')])
 
286
        self.local_tree.commit('second commit', rev_id=b'local')
304
287
 
305
288
    _default_command = ['send', '-o-', '../parent']
306
289
    _default_wd = 'local'
307
290
    _default_sent_revs = ['local']
308
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
309
 
                       'changes \(See bzr status\)\.',]
310
 
    _default_additional_error = 'Use --no-strict to force the send.\n'
311
 
    _default_additional_warning = 'Uncommitted changes will not be sent.'
 
291
    _default_errors = [b'Working tree ".*/local/" has uncommitted '
 
292
                       b'changes \\(See brz status\\)\\.',]
 
293
    _default_additional_error = b'Use --no-strict to force the send.\n'
 
294
    _default_additional_warning = b'Uncommitted changes will not be sent.'
312
295
 
313
296
    def set_config_send_strict(self, value):
314
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
315
 
        # should do)
316
 
        conf = self.local_tree.branch.get_config()
317
 
        conf.set_user_option('send_strict', value)
 
297
        br = branch.Branch.open('local')
 
298
        br.get_config_stack().set('send_strict', value)
318
299
 
319
300
    def assertSendFails(self, args):
320
301
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
328
309
        if revs is None:
329
310
            revs = self._default_sent_revs
330
311
        out, err = self.run_send(args, err_re=err_re)
331
 
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
 
312
        if len(revs) == 1:
 
313
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
314
        else:
 
315
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
332
316
        if with_warning:
333
317
            self.assertContainsRe(err, self._default_additional_warning)
334
318
            self.assertEndsWith(err, bundling_revs)
335
319
        else:
336
 
            self.assertEquals(bundling_revs, err)
337
 
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
 
320
            self.assertEqual(bundling_revs, err)
 
321
        md = merge_directive.MergeDirective.from_lines(BytesIO(out))
338
322
        self.assertEqual('parent', md.base_revision_id)
339
 
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
323
        br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
340
324
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
341
325
 
342
326
 
347
331
        super(TestSendStrictWithoutChanges, self).setUp()
348
332
        self.make_parent_and_local_branches()
349
333
 
 
334
    def test_send_without_workingtree(self):
 
335
        ControlDir.open("local").destroy_workingtree()
 
336
        self.assertSendSucceeds([])
 
337
 
350
338
    def test_send_default(self):
351
339
        self.assertSendSucceeds([])
352
340
 
366
354
 
367
355
 
368
356
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
369
 
                                   TestSendStrictMixin):
 
357
                                TestSendStrictMixin):
 
358
 
 
359
    # These are textually the same as test_push.strict_push_change_scenarios,
 
360
    # but since the functions are reimplemented here, the definitions are left
 
361
    # here too.
 
362
    scenarios = [
 
363
        ('uncommitted',
 
364
         dict(_changes_type='_uncommitted_changes')),
 
365
        ('pending_merges',
 
366
         dict(_changes_type='_pending_merges')),
 
367
        ('out-of-sync-trees',
 
368
         dict(_changes_type='_out_of_sync_trees')),
 
369
        ]
370
370
 
371
371
    _changes_type = None # Set by load_tests
372
372
 
380
380
    def _uncommitted_changes(self):
381
381
        self.make_parent_and_local_branches()
382
382
        # Make a change without committing it
383
 
        self.build_tree_contents([('local/file', 'modified')])
 
383
        self.build_tree_contents([('local/file', b'modified')])
384
384
 
385
385
    def _pending_merges(self):
386
386
        self.make_parent_and_local_branches()
387
387
        # Create 'other' branch containing a new file
388
 
        other_bzrdir = self.parent_tree.bzrdir.sprout('other')
 
388
        other_bzrdir = self.parent_tree.controldir.sprout('other')
389
389
        other_tree = other_bzrdir.open_workingtree()
390
 
        self.build_tree_contents([('other/other-file', 'other')])
 
390
        self.build_tree_contents([('other/other-file', b'other')])
391
391
        other_tree.add('other-file')
392
 
        other_tree.commit('other commit', rev_id='other')
 
392
        other_tree.commit('other commit', rev_id=b'other')
393
393
        # Merge and revert, leaving a pending merge
394
394
        self.local_tree.merge_from_branch(other_tree.branch)
395
395
        self.local_tree.revert(filenames=['other-file'], backups=False)
398
398
        self.make_parent_and_local_branches()
399
399
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
400
400
        # Make a change and commit it
401
 
        self.build_tree_contents([('local/file', 'modified in local')])
402
 
        self.local_tree.commit('modify file', rev_id='modified-in-local')
 
401
        self.build_tree_contents([('local/file', b'modified in local')])
 
402
        self.local_tree.commit('modify file', rev_id=b'modified-in-local')
403
403
        # Exercise commands from the checkout directory
404
404
        self._default_wd = 'checkout'
405
405
        self._default_errors = ["Working tree is out of date, please run"
406
 
                                " 'bzr update'\.",]
 
406
                                " 'brz update'\\.",]
407
407
        self._default_sent_revs = ['modified-in-local', 'local']
408
408
 
409
409
    def test_send_default(self):
441
441
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
442
442
 
443
443
    _default_command = ['bundle-revisions', '../parent']
 
444
 
 
445
 
 
446
class TestSmartServerSend(tests.TestCaseWithTransport):
 
447
 
 
448
    def test_send(self):
 
449
        self.setup_smart_server_with_call_log()
 
450
        t = self.make_branch_and_tree('branch')
 
451
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
452
        t.add("foo")
 
453
        t.commit("message")
 
454
        local = t.controldir.sprout('local-branch').open_workingtree()
 
455
        self.build_tree_contents([('branch/foo', b'thenewcontents')])
 
456
        local.commit("anothermessage")
 
457
        self.reset_smart_call_log()
 
458
        out, err = self.run_bzr(
 
459
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
460
        # This figure represent the amount of work to perform this use case. It
 
461
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
462
        # being too low. If rpc_count increases, more network roundtrips have
 
463
        # become necessary for this use case. Please do not adjust this number
 
464
        # upwards without agreement from bzr's network support maintainers.
 
465
        self.assertLength(7, self.hpss_calls)
 
466
        self.assertLength(1, self.hpss_connections)
 
467
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)