28
28
from bzrlib.bundle import serializer
29
from bzrlib.transport import memory
30
from bzrlib.tests import (
36
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)
39
55
class TestSendMixin(object):
52
68
def get_MD(self, args, cmd=None, wd='branch'):
53
69
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
54
return merge_directive.MergeDirective.from_lines(out)
70
return merge_directive.MergeDirective.from_lines(out.readlines())
56
72
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
57
73
md = self.get_MD(args, cmd=cmd, wd=wd)
190
206
def test_note_revisions(self):
191
207
stderr = self.run_send([])[1]
192
self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
208
self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
194
210
def test_mailto_option(self):
195
211
b = branch.Branch.open('branch')
264
280
self.assertEqual('rev3', md.revision_id)
266
282
def test_nonexistant_branch(self):
267
self.vfs_transport_factory = memory.MemoryServer
268
location = self.get_url('absentdir/')
283
if sys.platform == "win32":
284
location = "C:/i/do/not/exist/"
286
location = "/i/do/not/exist/"
269
287
out, err = self.run_bzr(["send", "--from", location], retcode=3)
270
288
self.assertEqual(out, '')
271
289
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
290
308
_default_sent_revs = ['local']
291
309
_default_errors = ['Working tree ".*/local/" has uncommitted '
292
310
'changes \(See bzr status\)\.',]
293
_default_additional_error = 'Use --no-strict to force the send.\n'
294
_default_additional_warning = 'Uncommitted changes will not be sent.'
296
312
def set_config_send_strict(self, value):
297
313
# set config var (any of bazaar.conf, locations.conf, branch.conf
299
conf = self.local_tree.branch.get_config_stack()
300
conf.set('send_strict', value)
315
conf = self.local_tree.branch.get_config()
316
conf.set_user_option('send_strict', value)
302
318
def assertSendFails(self, args):
303
out, err = self.run_send(args, rc=3, err_re=self._default_errors)
304
self.assertContainsRe(err, self._default_additional_error)
319
self.run_send(args, rc=3, err_re=self._default_errors)
306
def assertSendSucceeds(self, args, revs=None, with_warning=False):
308
err_re = self._default_errors
321
def assertSendSucceeds(self, args, revs=None):
312
323
revs = self._default_sent_revs
313
out, err = self.run_send(args, err_re=err_re)
315
bundling_revs = 'Bundling %d revision.\n'% len(revs)
317
bundling_revs = 'Bundling %d revisions.\n' % len(revs)
319
self.assertContainsRe(err, self._default_additional_warning)
320
self.assertEndsWith(err, bundling_revs)
322
self.assertEquals(bundling_revs, err)
323
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())
324
329
self.assertEqual('parent', md.base_revision_id)
325
330
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
326
331
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
354
359
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
355
TestSendStrictMixin):
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
362
dict(_changes_type='_uncommitted_changes')),
364
dict(_changes_type='_pending_merges')),
365
('out-of-sync-trees',
366
dict(_changes_type='_out_of_sync_trees')),
360
TestSendStrictMixin):
369
362
_changes_type = None # Set by load_tests
405
398
self._default_sent_revs = ['modified-in-local', 'local']
407
400
def test_send_default(self):
408
self.assertSendSucceeds([], with_warning=True)
401
self.assertSendFails([])
410
403
def test_send_with_revision(self):
411
404
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
421
414
self.assertSendFails([])
422
415
self.assertSendSucceeds(['--no-strict'])
424
418
def test_send_bogus_config_var_ignored(self):
425
419
self.set_config_send_strict("I'm unsure")
426
self.assertSendSucceeds([], with_warning=True)
420
self.assertSendFails([])
428
423
def test_send_no_strict_command_line_override_config(self):
429
424
self.set_config_send_strict('true')
430
425
self.assertSendFails([])
431
426
self.assertSendSucceeds(['--no-strict'])
433
def test_send_strict_command_line_override_config(self):
428
def test_push_strict_command_line_override_config(self):
434
429
self.set_config_send_strict('false')
435
430
self.assertSendSucceeds([])
436
431
self.assertSendFails(['--strict'])