28
28
from bzrlib.bundle import serializer
29
from bzrlib.transport import memory
32
def load_tests(standard_tests, module, loader):
33
"""Multiply tests for the send command."""
34
result = loader.suiteClass()
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,
43
dict(_changes_type='_uncommitted_changes')),
45
dict(_changes_type='_pending_merges')),
47
dict(_changes_type='_out_of_sync_trees')),
49
tests.multiply_tests(changes_tests, changes_scenarios, result)
50
# No parametrization for the remaining tests
51
result.addTests(remaining_tests)
56
class TestSendMixin(object):
58
_default_command = ['send', '-o-']
59
_default_wd = 'branch'
61
def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
62
if cmd is None: cmd = self._default_command
63
if wd is None: wd = self._default_wd
64
if err_re is None: err_re = []
65
return self.run_bzr(cmd + args, retcode=rc,
69
def get_MD(self, args, cmd=None, wd='branch'):
70
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
71
return merge_directive.MergeDirective.from_lines(out)
73
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
74
md = self.get_MD(args, cmd=cmd, wd=wd)
75
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
76
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
79
class TestSend(tests.TestCaseWithTransport, TestSendMixin):
31
def read_bundle(fileobj):
32
md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
33
return serializer.read_bundle(StringIO(md.get_raw_bundle()))
36
class TestSend(tests.TestCaseWithTransport):
82
39
super(TestSend, self).setUp()
94
51
self.build_tree_contents([('branch/file1', 'branch')])
95
52
branch_tree.commit('last commit', rev_id='rev3')
54
def run_send(self, args, cmd=None, rc=0, wd='branch'):
57
return self.run_bzr(cmd + args, retcode=rc, working_dir=wd)
59
def get_MD(self, args, cmd=None, wd='branch'):
60
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
61
return merge_directive.MergeDirective.from_lines(out.readlines())
63
def get_bundle(self, args, cmd=None, wd='branch'):
64
md = self.get_MD(args, cmd=cmd, wd=wd)
65
return serializer.read_bundle(StringIO(md.get_raw_bundle()))
67
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
68
out = self.run_send(args, cmd=cmd, wd=wd)[0]
69
br = read_bundle(StringIO(out))
70
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
97
72
def assertFormatIs(self, fmt_string, md):
98
73
self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
281
256
self.assertEqual('rev3', md.revision_id)
283
258
def test_nonexistant_branch(self):
284
self.vfs_transport_factory = memory.MemoryServer
285
location = self.get_url('absentdir/')
259
if sys.platform == "win32":
260
location = "C:/i/do/not/exist/"
262
location = "/i/do/not/exist/"
286
263
out, err = self.run_bzr(["send", "--from", location], retcode=3)
287
264
self.assertEqual(out, '')
288
265
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
291
class TestSendStrictMixin(TestSendMixin):
293
def make_parent_and_local_branches(self):
294
# 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')])
297
self.parent_tree.add('file')
298
self.parent_tree.commit('first commit', rev_id='parent')
299
# Branch 'local' from parent and do a change
300
local_bzrdir = self.parent_tree.bzrdir.sprout('local')
301
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')
305
_default_command = ['send', '-o-', '../parent']
306
_default_wd = 'local'
307
_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.'
313
def set_config_send_strict(self, value):
314
# set config var (any of bazaar.conf, locations.conf, branch.conf
316
conf = self.local_tree.branch.get_config()
317
conf.set_user_option('send_strict', value)
319
def assertSendFails(self, args):
320
out, err = self.run_send(args, rc=3, err_re=self._default_errors)
321
self.assertContainsRe(err, self._default_additional_error)
323
def assertSendSucceeds(self, args, revs=None, with_warning=False):
325
err_re = self._default_errors
329
revs = self._default_sent_revs
330
out, err = self.run_send(args, err_re=err_re)
331
bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
333
self.assertContainsRe(err, self._default_additional_warning)
334
self.assertEndsWith(err, bundling_revs)
336
self.assertEquals(bundling_revs, err)
337
md = merge_directive.MergeDirective.from_lines(StringIO(out))
338
self.assertEqual('parent', md.base_revision_id)
339
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
340
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
343
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
344
TestSendStrictMixin):
347
super(TestSendStrictWithoutChanges, self).setUp()
348
self.make_parent_and_local_branches()
350
def test_send_default(self):
351
self.assertSendSucceeds([])
353
def test_send_strict(self):
354
self.assertSendSucceeds(['--strict'])
356
def test_send_no_strict(self):
357
self.assertSendSucceeds(['--no-strict'])
359
def test_send_config_var_strict(self):
360
self.set_config_send_strict('true')
361
self.assertSendSucceeds([])
363
def test_send_config_var_no_strict(self):
364
self.set_config_send_strict('false')
365
self.assertSendSucceeds([])
368
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
369
TestSendStrictMixin):
371
_changes_type = None # Set by load_tests
374
super(TestSendStrictWithChanges, self).setUp()
375
# load tests set _changes_types to the name of the method we want to
377
do_changes_func = getattr(self, self._changes_type)
380
def _uncommitted_changes(self):
381
self.make_parent_and_local_branches()
382
# Make a change without committing it
383
self.build_tree_contents([('local/file', 'modified')])
385
def _pending_merges(self):
386
self.make_parent_and_local_branches()
387
# Create 'other' branch containing a new file
388
other_bzrdir = self.parent_tree.bzrdir.sprout('other')
389
other_tree = other_bzrdir.open_workingtree()
390
self.build_tree_contents([('other/other-file', 'other')])
391
other_tree.add('other-file')
392
other_tree.commit('other commit', rev_id='other')
393
# Merge and revert, leaving a pending merge
394
self.local_tree.merge_from_branch(other_tree.branch)
395
self.local_tree.revert(filenames=['other-file'], backups=False)
397
def _out_of_sync_trees(self):
398
self.make_parent_and_local_branches()
399
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
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')
403
# Exercise commands from the checkout directory
404
self._default_wd = 'checkout'
405
self._default_errors = ["Working tree is out of date, please run"
407
self._default_sent_revs = ['modified-in-local', 'local']
409
def test_send_default(self):
410
self.assertSendSucceeds([], with_warning=True)
412
def test_send_with_revision(self):
413
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
415
def test_send_no_strict(self):
416
self.assertSendSucceeds(['--no-strict'])
418
def test_send_strict_with_changes(self):
419
self.assertSendFails(['--strict'])
421
def test_send_respect_config_var_strict(self):
422
self.set_config_send_strict('true')
423
self.assertSendFails([])
424
self.assertSendSucceeds(['--no-strict'])
426
def test_send_bogus_config_var_ignored(self):
427
self.set_config_send_strict("I'm unsure")
428
self.assertSendSucceeds([], with_warning=True)
430
def test_send_no_strict_command_line_override_config(self):
431
self.set_config_send_strict('true')
432
self.assertSendFails([])
433
self.assertSendSucceeds(['--no-strict'])
435
def test_send_strict_command_line_override_config(self):
436
self.set_config_send_strict('false')
437
self.assertSendSucceeds([])
438
self.assertSendFails(['--strict'])
441
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
443
_default_command = ['bundle-revisions', '../parent']