~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

More agressive test sharing between push and dpush.

* bzrlib/tests/blackbox/test_push.py:
(TestPushStrictWithChanges.setUp): I'm pretty sure some review
asked for that comment...

* bzrlib/tests/blackbox/test_dpush.py:
(TestDpushStrictMixin): Minimize differences against
TestPushStrict* test.
(TestDpushStrictWithChanges, TestDpushStrictWithoutChanges):
Remove duplication from the TestPush counterparts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    blackbox,
32
32
    test_foreign,
33
33
    )
 
34
from bzrlib.tests.blackbox import test_push
34
35
 
35
36
 
36
37
def load_tests(standard_tests, module, loader):
139
140
 
140
141
class TestDpushStrictMixin(object):
141
142
 
142
 
    def make_local_branch_and_tree(self):
143
 
        self.tree = self.make_branch_and_tree('local')
144
 
        self.build_tree_contents([('local/file', 'initial')])
145
 
        self.tree.add('file')
146
 
        self.tree.commit('adding file', rev_id='added')
147
 
        self.build_tree_contents([('local/file', 'modified')])
148
 
        self.tree.commit('modify file', rev_id='modified')
149
 
 
150
143
    def make_foreign_branch(self, relpath='to'):
151
144
        # Create an empty branch where we will be able to push
152
145
        self.foreign = self.make_branch(
153
146
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
154
147
 
155
 
    def set_config_dpush_strict(self, value):
 
148
    def set_config_push_strict(self, value):
156
149
        # set config var (any of bazaar.conf, locations.conf, branch.conf
157
150
        # should do)
158
151
        conf = self.tree.branch.get_config()
159
152
        conf.set_user_option('dpush_strict', value)
160
153
 
161
154
    _default_command = ['dpush', '../to']
162
 
    _default_wd = 'local'
163
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
164
 
                       'changes \(See bzr status\)\.',]
165
 
    _default_dpushed_revid = 'modified'
166
 
 
167
 
    def assertDpushFails(self, args):
168
 
        self.run_bzr_error(self._default_errors, self._default_command + args,
169
 
                           working_dir=self._default_wd, retcode=3)
170
 
 
171
 
    def assertDpushSucceeds(self, args, pushed_revid=None):
 
155
    _default_pushed_revid = False # Doesn't aplly for dpush
 
156
 
 
157
    def assertPushSucceeds(self, args, pushed_revid=None):
172
158
        self.run_bzr(self._default_command + args,
173
159
                     working_dir=self._default_wd)
174
160
        if pushed_revid is None:
182
168
 
183
169
 
184
170
 
185
 
class TestDpushStrictWithoutChanges(tests.TestCaseWithTransport,
186
 
                                    TestDpushStrictMixin):
 
171
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
 
172
                                    test_push.TestPushStrictWithoutChanges):
187
173
 
188
174
    def setUp(self):
189
175
        super(TestDpushStrictWithoutChanges, self).setUp()
190
176
        test_foreign.register_dummy_foreign_for_test(self)
191
 
        self.make_local_branch_and_tree()
192
177
        self.make_foreign_branch()
193
178
 
194
 
    def test_dpush_default(self):
195
 
        self.assertDpushSucceeds([])
196
 
 
197
 
    def test_dpush_strict(self):
198
 
        self.assertDpushSucceeds(['--strict'])
199
 
 
200
 
    def test_dpush_no_strict(self):
201
 
        self.assertDpushSucceeds(['--no-strict'])
202
 
 
203
 
    def test_dpush_config_var_strict(self):
204
 
        self.set_config_dpush_strict('true')
205
 
        self.assertDpushSucceeds([])
206
 
 
207
 
    def test_dpush_config_var_no_strict(self):
208
 
        self.set_config_dpush_strict('false')
209
 
        self.assertDpushSucceeds([])
210
 
 
211
 
 
212
 
class TestDpushStrictWithChanges(tests.TestCaseWithTransport,
213
 
                                 TestDpushStrictMixin):
 
179
 
 
180
class TestDpushStrictWithChanges(TestDpushStrictMixin,
 
181
                                 test_push.TestPushStrictWithChanges):
214
182
 
215
183
    _changes_type = None # Set by load_tests
216
184
 
217
185
    def setUp(self):
218
186
        super(TestDpushStrictWithChanges, self).setUp()
219
187
        test_foreign.register_dummy_foreign_for_test(self)
220
 
        # Apply the changes defined in load_tests: one of _uncommitted_changes,
221
 
        # _pending_merges or _out_of_sync_trees
222
 
        getattr(self, self._changes_type)()
223
188
        self.make_foreign_branch()
224
189
 
225
 
    def _uncommitted_changes(self):
226
 
        self.make_local_branch_and_tree()
227
 
        # Make a change without committing it
228
 
        self.build_tree_contents([('local/file', 'in progress')])
229
 
 
230
 
    def _pending_merges(self):
231
 
        self.make_local_branch_and_tree()
232
 
        # Create 'other' branch containing a new file
233
 
        other_bzrdir = self.tree.bzrdir.sprout('other')
234
 
        other_tree = other_bzrdir.open_workingtree()
235
 
        self.build_tree_contents([('other/other-file', 'other')])
236
 
        other_tree.add('other-file')
237
 
        other_tree.commit('other commit', rev_id='other')
238
 
        # Merge and revert, leaving a pending merge
239
 
        self.tree.merge_from_branch(other_tree.branch)
240
 
        self.tree.revert(filenames=['other-file'], backups=False)
241
 
 
242
 
    def _out_of_sync_trees(self):
243
 
        self.make_local_branch_and_tree()
244
 
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
245
 
        # Make a change and commit it
246
 
        self.build_tree_contents([('local/file', 'modified in local')])
247
 
        self.tree.commit('modify file', rev_id='modified-in-local')
248
 
        # Exercise commands from the checkout directory
249
 
        self._default_wd = 'checkout'
250
 
        self._default_errors = ["Working tree is out of date, please run"
251
 
                                " 'bzr update'\.",]
252
 
        self._default_dpushed_revid = 'modified-in-local'
253
 
 
254
 
    def test_dpush_default(self):
255
 
        self.assertDpushFails([])
256
 
 
257
 
    def test_dpush_no_strict(self):
258
 
        self.assertDpushSucceeds(['--no-strict'])
259
 
 
260
 
    def test_dpush_strict_with_changes(self):
261
 
        self.assertDpushFails(['--strict'])
262
 
 
263
 
    def test_dpush_respect_config_var_strict(self):
264
 
        self.set_config_dpush_strict('true')
265
 
        self.assertDpushFails([])
266
 
 
267
 
    def test_dpush_bogus_config_var_ignored(self):
268
 
        self.set_config_dpush_strict("I don't want you to be strict")
269
 
        self.assertDpushFails([])
270
 
 
271
 
    def test_dpush_no_strict_command_line_override_config(self):
272
 
        self.set_config_dpush_strict('yES')
273
 
        self.assertDpushFails([])
274
 
        self.assertDpushSucceeds(['--no-strict'])
275
 
 
276
 
    def test_dpush_strict_command_line_override_config(self):
277
 
        self.set_config_dpush_strict('oFF')
278
 
        self.assertDpushFails(['--strict'])
279
 
        self.assertDpushSucceeds([])
 
190
    def test_push_with_revision(self):
 
191
        raise tests.TestNotApplicable('dpush does not handle --revision')
 
192