/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 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

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')
311
293
    _default_additional_warning = 'Uncommitted changes will not be sent.'
312
294
 
313
295
    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)
 
296
        br = branch.Branch.open('local')
 
297
        br.lock_write()
 
298
        conf = br.get_config_stack()
 
299
        conf.set('send_strict', value)
 
300
        br.unlock()
318
301
 
319
302
    def assertSendFails(self, args):
320
303
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
328
311
        if revs is None:
329
312
            revs = self._default_sent_revs
330
313
        out, err = self.run_send(args, err_re=err_re)
331
 
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
 
314
        if len(revs) == 1:
 
315
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
316
        else:
 
317
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
332
318
        if with_warning:
333
319
            self.assertContainsRe(err, self._default_additional_warning)
334
320
            self.assertEndsWith(err, bundling_revs)
366
352
 
367
353
 
368
354
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
369
 
                                   TestSendStrictMixin):
 
355
                                TestSendStrictMixin):
 
356
 
 
357
    # These are textually the same as test_push.strict_push_change_scenarios,
 
358
    # but since the functions are reimplemented here, the definitions are left
 
359
    # here too.
 
360
    scenarios = [
 
361
        ('uncommitted',
 
362
         dict(_changes_type='_uncommitted_changes')),
 
363
        ('pending_merges',
 
364
         dict(_changes_type='_pending_merges')),
 
365
        ('out-of-sync-trees',
 
366
         dict(_changes_type='_out_of_sync_trees')),
 
367
        ]
370
368
 
371
369
    _changes_type = None # Set by load_tests
372
370
 
441
439
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
442
440
 
443
441
    _default_command = ['bundle-revisions', '../parent']
 
442
 
 
443
 
 
444
class TestSmartServerSend(tests.TestCaseWithTransport):
 
445
 
 
446
    def test_send(self):
 
447
        self.setup_smart_server_with_call_log()
 
448
        t = self.make_branch_and_tree('branch')
 
449
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
450
        t.add("foo")
 
451
        t.commit("message")
 
452
        local = t.bzrdir.sprout('local-branch').open_workingtree()
 
453
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
 
454
        local.commit("anothermessage")
 
455
        self.reset_smart_call_log()
 
456
        out, err = self.run_bzr(
 
457
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
458
        # This figure represent the amount of work to perform this use case. It
 
459
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
460
        # being too low. If rpc_count increases, more network roundtrips have
 
461
        # become necessary for this use case. Please do not adjust this number
 
462
        # upwards without agreement from bzr's network support maintainers.
 
463
        self.assertLength(9, self.hpss_calls)
 
464
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)