~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

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-2011 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 (
26
25
    tests,
27
26
    )
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):
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')
280
263
        self.assertEqual('rev3', md.revision_id)
281
264
 
282
265
    def test_nonexistant_branch(self):
283
 
        self.vfs_transport_factory = tests.MemoryServer
 
266
        self.vfs_transport_factory = memory.MemoryServer
284
267
        location = self.get_url('absentdir/')
285
268
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
286
269
        self.assertEqual(out, '')
306
289
    _default_sent_revs = ['local']
307
290
    _default_errors = ['Working tree ".*/local/" has uncommitted '
308
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.'
309
294
 
310
295
    def set_config_send_strict(self, value):
311
296
        # set config var (any of bazaar.conf, locations.conf, branch.conf
312
297
        # should do)
313
 
        conf = self.local_tree.branch.get_config()
314
 
        conf.set_user_option('send_strict', value)
 
298
        conf = self.local_tree.branch.get_config_stack()
 
299
        conf.set('send_strict', value)
315
300
 
316
301
    def assertSendFails(self, args):
317
 
        self.run_send(args, rc=3, err_re=self._default_errors)
 
302
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
 
303
        self.assertContainsRe(err, self._default_additional_error)
318
304
 
319
 
    def assertSendSucceeds(self, args, revs=None):
 
305
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
 
306
        if with_warning:
 
307
            err_re = self._default_errors
 
308
        else:
 
309
            err_re = []
320
310
        if revs is None:
321
311
            revs = self._default_sent_revs
322
 
        out, err = self.run_send(args)
323
 
        self.assertEquals(
324
 
            'Bundling %d revision(s).\n' % len(revs), err)
 
312
        out, err = self.run_send(args, err_re=err_re)
 
313
        if len(revs) == 1:
 
314
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
 
315
        else:
 
316
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
 
317
        if with_warning:
 
318
            self.assertContainsRe(err, self._default_additional_warning)
 
319
            self.assertEndsWith(err, bundling_revs)
 
320
        else:
 
321
            self.assertEquals(bundling_revs, err)
325
322
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
326
323
        self.assertEqual('parent', md.base_revision_id)
327
324
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
354
351
 
355
352
 
356
353
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
357
 
                                   TestSendStrictMixin):
 
354
                                TestSendStrictMixin):
 
355
 
 
356
    # These are textually the same as test_push.strict_push_change_scenarios,
 
357
    # but since the functions are reimplemented here, the definitions are left
 
358
    # here too.
 
359
    scenarios = [
 
360
        ('uncommitted',
 
361
         dict(_changes_type='_uncommitted_changes')),
 
362
        ('pending_merges',
 
363
         dict(_changes_type='_pending_merges')),
 
364
        ('out-of-sync-trees',
 
365
         dict(_changes_type='_out_of_sync_trees')),
 
366
        ]
358
367
 
359
368
    _changes_type = None # Set by load_tests
360
369
 
395
404
        self._default_sent_revs = ['modified-in-local', 'local']
396
405
 
397
406
    def test_send_default(self):
398
 
        self.assertSendFails([])
 
407
        self.assertSendSucceeds([], with_warning=True)
399
408
 
400
409
    def test_send_with_revision(self):
401
410
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
411
420
        self.assertSendFails([])
412
421
        self.assertSendSucceeds(['--no-strict'])
413
422
 
414
 
 
415
423
    def test_send_bogus_config_var_ignored(self):
416
424
        self.set_config_send_strict("I'm unsure")
417
 
        self.assertSendFails([])
418
 
 
 
425
        self.assertSendSucceeds([], with_warning=True)
419
426
 
420
427
    def test_send_no_strict_command_line_override_config(self):
421
428
        self.set_config_send_strict('true')
431
438
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
432
439
 
433
440
    _default_command = ['bundle-revisions', '../parent']
 
441
 
 
442
 
 
443
class TestSmartServerSend(tests.TestCaseWithTransport):
 
444
 
 
445
    def test_send(self):
 
446
        self.setup_smart_server_with_call_log()
 
447
        t = self.make_branch_and_tree('branch')
 
448
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
449
        t.add("foo")
 
450
        t.commit("message")
 
451
        local = t.bzrdir.sprout('local-branch').open_workingtree()
 
452
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
 
453
        local.commit("anothermessage")
 
454
        self.reset_smart_call_log()
 
455
        out, err = self.run_bzr(
 
456
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
 
457
        # This figure represent the amount of work to perform this use case. It
 
458
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
459
        # being too low. If rpc_count increases, more network roundtrips have
 
460
        # become necessary for this use case. Please do not adjust this number
 
461
        # upwards without agreement from bzr's network support maintainers.
 
462
        self.assertLength(9, self.hpss_calls)
 
463
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)