/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib.branch import (
24
 
    Branch,
25
 
    InterBranch,
26
 
    )
27
 
from bzrlib.bzrdir import (
28
 
    BzrDirFormat,
29
 
    )
30
 
from bzrlib.foreign import (
31
 
    ForeignBranch,
32
 
    ForeignRepository,
33
 
    )
34
 
from bzrlib.repository import (
35
 
    Repository,
36
 
    )
37
 
from bzrlib.tests.blackbox import (
38
 
    ExternalBase,
39
 
    )
40
 
from bzrlib.tests.test_foreign import (
41
 
    DummyForeignVcsDirFormat,
42
 
    InterToDummyVcsBranch,
43
 
    )
44
 
 
45
 
 
46
 
class TestDpush(ExternalBase):
 
23
from bzrlib import (
 
24
    branch,
 
25
    bzrdir,
 
26
    foreign,
 
27
    tests,
 
28
    workingtree,
 
29
    )
 
30
from bzrlib.tests import (
 
31
    blackbox,
 
32
    test_foreign,
 
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
 
 
60
 
 
61
class TestDpush(blackbox.ExternalBase):
47
62
 
48
63
    def setUp(self):
49
 
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
50
 
        InterBranch.register_optimiser(InterToDummyVcsBranch)
51
 
        self.addCleanup(self.unregister_format)
52
64
        super(TestDpush, self).setUp()
53
 
 
54
 
    def unregister_format(self):
55
 
        try:
56
 
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
57
 
        except ValueError:
58
 
            pass
59
 
        InterBranch.unregister_optimiser(InterToDummyVcsBranch)
 
65
        test_foreign.register_dummy_foreign_for_test(self)
60
66
 
61
67
    def make_dummy_builder(self, relpath):
62
 
        builder = self.make_branch_builder(relpath, 
63
 
                format=DummyForeignVcsDirFormat())
64
 
        builder.build_snapshot('revid', None, 
 
68
        builder = self.make_branch_builder(
 
69
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
 
70
        builder.build_snapshot('revid', None,
65
71
            [('add', ('', 'TREE_ROOT', 'directory', None)),
66
72
             ('add', ('foo', 'fooid', 'file', 'bar'))])
67
73
        return builder
85
91
        self.check_output("", "status dc")
86
92
 
87
93
    def test_dpush_new(self):
88
 
        branch = self.make_dummy_builder('d').get_branch()
 
94
        b = self.make_dummy_builder('d').get_branch()
89
95
 
90
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
96
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
91
97
        self.build_tree_contents([("dc/foofile", "blaaaa")])
92
98
        dc_tree = dc.open_workingtree()
93
99
        dc_tree.add("foofile")
98
104
        self.check_output("", "status dc")
99
105
 
100
106
    def test_dpush_wt_diff(self):
101
 
        branch = self.make_dummy_builder('d').get_branch()
 
107
        b = self.make_dummy_builder('d').get_branch()
102
108
 
103
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
109
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
104
110
        self.build_tree_contents([("dc/foofile", "blaaaa")])
105
111
        dc_tree = dc.open_workingtree()
106
112
        dc_tree.add("foofile")
107
113
        newrevid = dc_tree.commit('msg')
108
114
 
109
115
        self.build_tree_contents([("dc/foofile", "blaaaal")])
110
 
        self.check_output("", "dpush -d dc d")
 
116
        self.check_output("", "dpush -d dc d --no-strict")
111
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")
112
120
        self.check_output('modified:\n  foofile\n', "status dc")
113
121
 
114
122
    def test_diverged(self):
115
123
        builder = self.make_dummy_builder('d')
116
124
 
117
 
        branch = builder.get_branch()
 
125
        b = builder.get_branch()
118
126
 
119
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
127
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
120
128
        dc_tree = dc.open_workingtree()
121
129
 
122
130
        self.build_tree_contents([("dc/foo", "bar")])
128
136
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
129
137
        self.assertEquals(output, "")
130
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