27
28
from bzrlib.bundle import serializer
28
from bzrlib.transport import memory
29
from bzrlib.tests import (
32
from bzrlib.tests.matchers import ContainsNoVfsCalls
35
load_tests = scenarios.load_tests_apply_scenarios
31
def load_tests(standard_tests, module, loader):
32
"""Multiply tests for the send command."""
33
result = loader.suiteClass()
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,
42
dict(_changes_type='_uncommitted_changes')),
44
dict(_changes_type='_pending_merges')),
46
dict(_changes_type='_out_of_sync_trees')),
48
tests.multiply_tests(changes_tests, changes_scenarios, result)
49
# No parametrization for the remaining tests
50
result.addTests(remaining_tests)
38
55
class TestSendMixin(object):
51
68
def get_MD(self, args, cmd=None, wd='branch'):
52
69
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
53
return merge_directive.MergeDirective.from_lines(out)
70
return merge_directive.MergeDirective.from_lines(out.readlines())
55
72
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
56
73
md = self.get_MD(args, cmd=cmd, wd=wd)
189
206
def test_note_revisions(self):
190
207
stderr = self.run_send([])[1]
191
self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
208
self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
193
210
def test_mailto_option(self):
194
211
b = branch.Branch.open('branch')
263
280
self.assertEqual('rev3', md.revision_id)
265
282
def test_nonexistant_branch(self):
266
self.vfs_transport_factory = memory.MemoryServer
267
location = self.get_url('absentdir/')
283
if sys.platform == "win32":
284
location = "C:/i/do/not/exist/"
286
location = "/i/do/not/exist/"
268
287
out, err = self.run_bzr(["send", "--from", location], retcode=3)
269
288
self.assertEqual(out, '')
270
289
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
289
308
_default_sent_revs = ['local']
290
309
_default_errors = ['Working tree ".*/local/" has uncommitted '
291
310
'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.'
295
312
def set_config_send_strict(self, value):
296
313
# set config var (any of bazaar.conf, locations.conf, branch.conf
298
conf = self.local_tree.branch.get_config_stack()
299
conf.set('send_strict', value)
315
conf = self.local_tree.branch.get_config()
316
conf.set_user_option('send_strict', value)
301
318
def assertSendFails(self, args):
302
out, err = self.run_send(args, rc=3, err_re=self._default_errors)
303
self.assertContainsRe(err, self._default_additional_error)
319
self.run_send(args, rc=3, err_re=self._default_errors)
305
def assertSendSucceeds(self, args, revs=None, with_warning=False):
307
err_re = self._default_errors
321
def assertSendSucceeds(self, args, revs=None):
311
323
revs = self._default_sent_revs
312
out, err = self.run_send(args, err_re=err_re)
314
bundling_revs = 'Bundling %d revision.\n'% len(revs)
316
bundling_revs = 'Bundling %d revisions.\n' % len(revs)
318
self.assertContainsRe(err, self._default_additional_warning)
319
self.assertEndsWith(err, bundling_revs)
321
self.assertEquals(bundling_revs, err)
322
md = merge_directive.MergeDirective.from_lines(StringIO(out))
324
out, err = self.run_send(args)
326
'Bundling %d revision(s).\n' % len(revs), err)
327
md = merge_directive.MergeDirective.from_lines(
328
StringIO(out).readlines())
323
329
self.assertEqual('parent', md.base_revision_id)
324
330
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
325
331
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
353
359
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
354
TestSendStrictMixin):
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
361
dict(_changes_type='_uncommitted_changes')),
363
dict(_changes_type='_pending_merges')),
364
('out-of-sync-trees',
365
dict(_changes_type='_out_of_sync_trees')),
360
TestSendStrictMixin):
368
362
_changes_type = None # Set by load_tests
404
398
self._default_sent_revs = ['modified-in-local', 'local']
406
400
def test_send_default(self):
407
self.assertSendSucceeds([], with_warning=True)
401
self.assertSendFails([])
409
403
def test_send_with_revision(self):
410
404
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
420
414
self.assertSendFails([])
421
415
self.assertSendSucceeds(['--no-strict'])
423
418
def test_send_bogus_config_var_ignored(self):
424
419
self.set_config_send_strict("I'm unsure")
425
self.assertSendSucceeds([], with_warning=True)
420
self.assertSendFails([])
427
423
def test_send_no_strict_command_line_override_config(self):
428
424
self.set_config_send_strict('true')
429
425
self.assertSendFails([])
430
426
self.assertSendSucceeds(['--no-strict'])
432
def test_send_strict_command_line_override_config(self):
428
def test_push_strict_command_line_override_config(self):
433
429
self.set_config_send_strict('false')
434
430
self.assertSendSucceeds([])
435
431
self.assertSendFails(['--strict'])
438
434
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
440
436
_default_command = ['bundle-revisions', '../parent']
443
class TestSmartServerSend(tests.TestCaseWithTransport):
446
self.setup_smart_server_with_call_log()
447
t = self.make_branch_and_tree('branch')
448
self.build_tree_contents([('branch/foo', 'thecontents')])
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)