~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-02 18:01:05 UTC
  • mfrom: (4724.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091002180105-oeomf71t7l9gpv6g
(vila) Add a --strict option to dpush

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    bzrdir,
26
26
    foreign,
27
27
    tests,
28
 
    )
29
 
from bzrlib.tests.test_foreign import (
30
 
    DummyForeignVcsDirFormat,
31
 
    InterToDummyVcsBranch,
 
28
    workingtree,
32
29
    )
33
30
from bzrlib.tests import (
34
31
    blackbox,
35
32
    test_foreign,
36
33
    )
 
34
from bzrlib.tests.blackbox import test_push
 
35
 
 
36
 
 
37
def load_tests(standard_tests, module, loader):
 
38
    """Multiply tests for the dpush command."""
 
39
    result = loader.suiteClass()
 
40
 
 
41
    # one for each king of change
 
42
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
43
        standard_tests, tests.condition_isinstance((
 
44
                TestDpushStrictWithChanges,
 
45
                )))
 
46
    changes_scenarios = [
 
47
        ('uncommitted',
 
48
         dict(_changes_type= '_uncommitted_changes')),
 
49
        ('pending-merges',
 
50
         dict(_changes_type= '_pending_merges')),
 
51
        ('out-of-sync-trees',
 
52
         dict(_changes_type= '_out_of_sync_trees')),
 
53
        ]
 
54
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
55
    # No parametrization for the remaining tests
 
56
    result.addTests(remaining_tests)
 
57
 
 
58
    return result
 
59
 
37
60
 
38
61
class TestDpush(blackbox.ExternalBase):
39
62
 
40
63
    def setUp(self):
41
 
        bzrdir.BzrDirFormat.register_control_format(
42
 
            test_foreign.DummyForeignVcsDirFormat)
43
 
        branch.InterBranch.register_optimiser(
44
 
            test_foreign.InterToDummyVcsBranch)
45
 
        self.addCleanup(self.unregister_format)
46
64
        super(TestDpush, self).setUp()
47
 
 
48
 
    def unregister_format(self):
49
 
        try:
50
 
            bzrdir.BzrDirFormat.unregister_control_format(
51
 
                test_foreign.DummyForeignVcsDirFormat)
52
 
        except ValueError:
53
 
            pass
54
 
        branch.InterBranch.unregister_optimiser(
55
 
            test_foreign.InterToDummyVcsBranch)
 
65
        test_foreign.register_dummy_foreign_for_test(self)
56
66
 
57
67
    def make_dummy_builder(self, relpath):
58
68
        builder = self.make_branch_builder(
103
113
        newrevid = dc_tree.commit('msg')
104
114
 
105
115
        self.build_tree_contents([("dc/foofile", "blaaaal")])
106
 
        self.check_output("", "dpush -d dc d")
 
116
        self.check_output("", "dpush -d dc d --no-strict")
107
117
        self.assertFileEqual("blaaaal", "dc/foofile")
 
118
        # if the dummy vcs wasn't that dummy we could uncomment the line below
 
119
        # self.assertFileEqual("blaaaa", "d/foofile")
108
120
        self.check_output('modified:\n  foofile\n', "status dc")
109
121
 
110
122
    def test_diverged(self):
124
136
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
125
137
        self.assertEquals(output, "")
126
138
        self.assertContainsRe(error, "have diverged")
 
139
 
 
140
 
 
141
class TestDpushStrictMixin(object):
 
142
 
 
143
    def setUp(self):
 
144
        test_foreign.register_dummy_foreign_for_test(self)
 
145
        # Create an empty branch where we will be able to push
 
146
        self.foreign = self.make_branch(
 
147
            'to', format=test_foreign.DummyForeignVcsDirFormat())
 
148
 
 
149
    def set_config_push_strict(self, value):
 
150
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
151
        # should do)
 
152
        conf = self.tree.branch.get_config()
 
153
        conf.set_user_option('dpush_strict', value)
 
154
 
 
155
    _default_command = ['dpush', '../to']
 
156
    _default_pushed_revid = False # Doesn't aplly for dpush
 
157
 
 
158
    def assertPushSucceeds(self, args, pushed_revid=None):
 
159
        self.run_bzr(self._default_command + args,
 
160
                     working_dir=self._default_wd)
 
161
        if pushed_revid is None:
 
162
            # dpush change the revids, so we need to get back to it
 
163
            branch_from = branch.Branch.open(self._default_wd)
 
164
            pushed_revid = branch_from.last_revision()
 
165
        branch_to = branch.Branch.open('to')
 
166
        repo_to = branch_to.repository
 
167
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
168
        self.assertEqual(branch_to.last_revision(), pushed_revid)
 
169
 
 
170
 
 
171
 
 
172
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
 
173
                                    test_push.TestPushStrictWithoutChanges):
 
174
 
 
175
    def setUp(self):
 
176
        test_push.TestPushStrictWithoutChanges.setUp(self)
 
177
        TestDpushStrictMixin.setUp(self)
 
178
 
 
179
 
 
180
class TestDpushStrictWithChanges(TestDpushStrictMixin,
 
181
                                 test_push.TestPushStrictWithChanges):
 
182
 
 
183
    _changes_type = None # Set by load_tests
 
184
 
 
185
    def setUp(self):
 
186
        test_push.TestPushStrictWithChanges.setUp(self)
 
187
        TestDpushStrictMixin.setUp(self)
 
188
 
 
189
    def test_push_with_revision(self):
 
190
        raise tests.TestNotApplicable('dpush does not handle --revision')
 
191