/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 bzrlib/tests/blackbox/test_send.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 17:56:30 UTC
  • mfrom: (6434 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105175630-kp0kt0el27s40q0x
Merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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 (
27
26
    )
28
27
from bzrlib.bundle import serializer
29
28
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
 
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
54
36
 
55
37
 
56
38
class TestSendMixin(object):
206
188
 
207
189
    def test_note_revisions(self):
208
190
        stderr = self.run_send([])[1]
209
 
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
 
191
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
210
192
 
211
193
    def test_mailto_option(self):
212
194
        b = branch.Branch.open('branch')
218
200
        self.run_send([])
219
201
        self.run_bzr_error(('Unknown mail client: bogus',),
220
202
                           'send -f branch --mail-to jrandom@example.org')
221
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
203
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
222
204
        self.run_bzr_error(('Unknown mail client: bogus',),
223
205
                           'send -f branch')
224
206
 
227
209
        b = branch.Branch.open('branch')
228
210
        b.get_config().set_user_option('mail_client', 'bogus')
229
211
        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')
 
212
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
 
213
        self.run_bzr_error(('Unknown mail client: bogus',), 'send -f branch')
234
214
 
235
215
    def test_format(self):
236
216
        md = self.get_MD(['--format=4'])
248
228
                            'send -f branch -o- --format=0.999')[0]
249
229
 
250
230
    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')
 
231
        br = branch.Branch.open('parent')
 
232
        conf = br.get_config_stack()
 
233
        br.lock_write()
 
234
        try:
 
235
            conf.set('child_submit_format', '4')
 
236
        finally:
 
237
            br.unlock()
253
238
        md = self.get_MD([])
254
239
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
255
240
 
256
 
        parent_config.set_user_option('child_submit_format', '0.9')
 
241
        br.lock_write()
 
242
        try:
 
243
            conf.set('child_submit_format', '0.9')
 
244
        finally:
 
245
            br.unlock()
257
246
        md = self.get_MD([])
258
247
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
259
248
 
261
250
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
262
251
        self.assertIs(merge_directive.MergeDirective, md.__class__)
263
252
 
264
 
        parent_config.set_user_option('child_submit_format', '0.999')
 
253
        br.lock_write()
 
254
        try:
 
255
            conf.set('child_submit_format', '0.999')
 
256
        finally:
 
257
            br.unlock()
265
258
        self.run_bzr_error(["No such send format '0.999'"],
266
259
                            'send -f branch -o-')[0]
267
260
 
311
304
    _default_additional_warning = 'Uncommitted changes will not be sent.'
312
305
 
313
306
    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)
 
307
        br = branch.Branch.open('local')
 
308
        br.lock_write()
 
309
        conf = br.get_config_stack()
 
310
        conf.set('send_strict', value)
 
311
        br.unlock()
318
312
 
319
313
    def assertSendFails(self, args):
320
314
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
328
322
        if revs is None:
329
323
            revs = self._default_sent_revs
330
324
        out, err = self.run_send(args, err_re=err_re)
331
 
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
 
325
        if len(revs) == 1:
 
326
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
327
        else:
 
328
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
332
329
        if with_warning:
333
330
            self.assertContainsRe(err, self._default_additional_warning)
334
331
            self.assertEndsWith(err, bundling_revs)
366
363
 
367
364
 
368
365
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
369
 
                                   TestSendStrictMixin):
 
366
                                TestSendStrictMixin):
 
367
 
 
368
    # These are textually the same as test_push.strict_push_change_scenarios,
 
369
    # but since the functions are reimplemented here, the definitions are left
 
370
    # here too.
 
371
    scenarios = [
 
372
        ('uncommitted',
 
373
         dict(_changes_type='_uncommitted_changes')),
 
374
        ('pending_merges',
 
375
         dict(_changes_type='_pending_merges')),
 
376
        ('out-of-sync-trees',
 
377
         dict(_changes_type='_out_of_sync_trees')),
 
378
        ]
370
379
 
371
380
    _changes_type = None # Set by load_tests
372
381
 
441
450
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
442
451
 
443
452
    _default_command = ['bundle-revisions', '../parent']
 
453
 
 
454
 
 
455
class TestSmartServerSend(tests.TestCaseWithTransport):
 
456
 
 
457
    def test_send(self):
 
458
        self.setup_smart_server_with_call_log()
 
459
        t = self.make_branch_and_tree('branch')
 
460
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
461
        t.add("foo")
 
462
        t.commit("message")
 
463
        local = t.bzrdir.sprout('local-branch').open_workingtree()
 
464
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
 
465
        local.commit("anothermessage")
 
466
        self.reset_smart_call_log()
 
467
        out, err = self.run_bzr(
 
468
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
469
        # This figure represent the amount of work to perform this use case. It
 
470
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
471
        # being too low. If rpc_count increases, more network roundtrips have
 
472
        # become necessary for this use case. Please do not adjust this number
 
473
        # upwards without agreement from bzr's network support maintainers.
 
474
        self.assertLength(7, self.hpss_calls)
 
475
        self.assertLength(1, self.hpss_connections)
 
476
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)