1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
# Authors: Aaron Bentley
4
4
# This program is free software; you can redistribute it and/or modify
28
28
from bzrlib.bundle import serializer
29
29
from bzrlib.transport import memory
30
from bzrlib.tests import (
36
load_tests = scenarios.load_tests_apply_scenarios
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)
39
56
class TestSendMixin(object):
290
307
_default_sent_revs = ['local']
291
308
_default_errors = ['Working tree ".*/local/" has uncommitted '
292
309
'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
311
def set_config_send_strict(self, value):
297
312
# set config var (any of bazaar.conf, locations.conf, branch.conf
300
315
conf.set_user_option('send_strict', value)
302
317
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)
318
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
320
def assertSendSucceeds(self, args, revs=None):
312
322
revs = self._default_sent_revs
313
out, err = self.run_send(args, err_re=err_re)
314
bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
316
self.assertContainsRe(err, self._default_additional_warning)
317
self.assertEndsWith(err, bundling_revs)
319
self.assertEquals(bundling_revs, err)
323
out, err = self.run_send(args)
325
'Bundling %d revision(s).\n' % len(revs), err)
320
326
md = merge_directive.MergeDirective.from_lines(StringIO(out))
321
327
self.assertEqual('parent', md.base_revision_id)
322
328
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
351
357
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
352
TestSendStrictMixin):
354
# These are textually the same as test_push.strict_push_change_scenarios,
355
# but since the functions are reimplemented here, the definitions are left
359
dict(_changes_type='_uncommitted_changes')),
361
dict(_changes_type='_pending_merges')),
362
('out-of-sync-trees',
363
dict(_changes_type='_out_of_sync_trees')),
358
TestSendStrictMixin):
366
360
_changes_type = None # Set by load_tests
402
396
self._default_sent_revs = ['modified-in-local', 'local']
404
398
def test_send_default(self):
405
self.assertSendSucceeds([], with_warning=True)
399
self.assertSendFails([])
407
401
def test_send_with_revision(self):
408
402
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
418
412
self.assertSendFails([])
419
413
self.assertSendSucceeds(['--no-strict'])
421
416
def test_send_bogus_config_var_ignored(self):
422
417
self.set_config_send_strict("I'm unsure")
423
self.assertSendSucceeds([], with_warning=True)
418
self.assertSendFails([])
425
421
def test_send_no_strict_command_line_override_config(self):
426
422
self.set_config_send_strict('true')