~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
27
    osutils,
27
28
    tests,
34
35
from bzrlib.tests import (
35
36
    blackbox,
36
37
    http_server,
 
38
    scenarios,
 
39
    script,
37
40
    test_foreign,
38
41
    test_server,
39
42
    )
40
43
from bzrlib.transport import memory
41
44
 
42
45
 
43
 
def load_tests(standard_tests, module, loader):
44
 
    """Multiply tests for the push command."""
45
 
    result = loader.suiteClass()
46
 
 
47
 
    # one for each king of change
48
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
49
 
        standard_tests, tests.condition_isinstance((
50
 
                TestPushStrictWithChanges,
51
 
                )))
52
 
    changes_scenarios = [
53
 
        ('uncommitted',
54
 
         dict(_changes_type= '_uncommitted_changes')),
55
 
        ('pending-merges',
56
 
         dict(_changes_type= '_pending_merges')),
57
 
        ('out-of-sync-trees',
58
 
         dict(_changes_type= '_out_of_sync_trees')),
59
 
        ]
60
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
61
 
    # No parametrization for the remaining tests
62
 
    result.addTests(remaining_tests)
63
 
 
64
 
    return result
 
46
load_tests = scenarios.load_tests_apply_scenarios
65
47
 
66
48
 
67
49
class TestPush(tests.TestCaseWithTransport):
124
106
        transport.delete('branch_b/c')
125
107
        out, err = self.run_bzr('push', working_dir='branch_a')
126
108
        path = branch_a.get_push_location()
127
 
        self.assertEquals(out,
128
 
                          'Using saved push location: %s\n'
129
 
                          % urlutils.local_path_from_url(path))
130
109
        self.assertEqual(err,
 
110
                         'Using saved push location: %s\n'
131
111
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
112
                         'Pushed up to revision 2.\n'
 
113
                         % urlutils.local_path_from_url(path))
133
114
        self.assertEqual(path,
134
115
                         branch_b.bzrdir.root_transport.base)
135
116
        # test explicit --remember
155
136
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
156
137
        self.assertEqual('', out)
157
138
        self.assertEqual('Created new branch.\n', err)
158
 
        self.failIfExists('push-to/file')
 
139
        self.assertPathDoesNotExist('push-to/file')
159
140
 
160
141
    def test_push_new_branch_revision_count(self):
161
142
        # bzr push of a branch with revisions to a new location
169
150
        self.assertEqual('', out)
170
151
        self.assertEqual('Created new branch.\n', err)
171
152
 
 
153
    def test_push_quiet(self):
 
154
        # test that using -q makes output quiet
 
155
        t = self.make_branch_and_tree('tree')
 
156
        self.build_tree(['tree/file'])
 
157
        t.add('file')
 
158
        t.commit('commit 1')
 
159
        self.run_bzr('push -d tree pushed-to')
 
160
        path = t.branch.get_push_location()
 
161
        out, err = self.run_bzr('push', working_dir="tree")
 
162
        self.assertEqual('Using saved push location: %s\n'
 
163
                         'No new revisions or tags to push.\n' %
 
164
                         urlutils.local_path_from_url(path), err)
 
165
        out, err = self.run_bzr('push -q', working_dir="tree")
 
166
        self.assertEqual('', out)
 
167
        self.assertEqual('', err)
 
168
 
172
169
    def test_push_only_pushes_history(self):
173
170
        # Knit branches should only push the history for the current revision.
174
171
        format = bzrdir.BzrDirMetaFormat1()
178
175
 
179
176
        def make_shared_tree(path):
180
177
            shared_repo.bzrdir.root_transport.mkdir(path)
181
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
178
            controldir.ControlDir.create_branch_convenience('repo/' + path)
182
179
            return workingtree.WorkingTree.open('repo/' + path)
183
180
        tree_a = make_shared_tree('a')
184
181
        self.build_tree(['repo/a/file'])
219
216
        t.commit(allow_pointless=True,
220
217
                message='first commit')
221
218
        self.run_bzr('push -d from to-one')
222
 
        self.failUnlessExists('to-one')
 
219
        self.assertPathExists('to-one')
223
220
        self.run_bzr('push -d %s %s'
224
221
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
225
 
        self.failUnlessExists('to-two')
 
222
        self.assertPathExists('to-two')
 
223
 
 
224
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
225
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
226
        target_repo = self.make_repository('target')
 
227
        source = self.make_branch_builder('source')
 
228
        source.start_series()
 
229
        source.build_snapshot('A', None, [
 
230
            ('add', ('', 'root-id', 'directory', None))])
 
231
        source.build_snapshot('B', ['A'], [])
 
232
        source.build_snapshot('C', ['A'], [])
 
233
        source.finish_series()
 
234
        self.run_bzr('push target -d source')
 
235
        self.addCleanup(target_repo.lock_read().unlock)
 
236
        # We should have pushed 'C', but not 'B', since it isn't in the
 
237
        # ancestry
 
238
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
226
239
 
227
240
    def test_push_smart_non_stacked_streaming_acceptance(self):
228
241
        self.setup_smart_server_with_call_log()
251
264
        # being too low. If rpc_count increases, more network roundtrips have
252
265
        # become necessary for this use case. Please do not adjust this number
253
266
        # upwards without agreement from bzr's network support maintainers.
254
 
        self.assertLength(14, self.hpss_calls)
 
267
        self.assertLength(13, self.hpss_calls)
255
268
        remote = branch.Branch.open('public')
256
269
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
257
270
 
328
341
                     working_dir='tree')
329
342
        new_tree = workingtree.WorkingTree.open('new/tree')
330
343
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
331
 
        self.failUnlessExists('new/tree/a')
 
344
        self.assertPathExists('new/tree/a')
332
345
 
333
346
    def test_push_use_existing(self):
334
347
        """'bzr push --use-existing-dir' can push into an existing dir.
349
362
        new_tree = workingtree.WorkingTree.open('target')
350
363
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
351
364
        # The push should have created target/a
352
 
        self.failUnlessExists('target/a')
 
365
        self.assertPathExists('target/a')
353
366
 
354
367
    def test_push_use_existing_into_empty_bzrdir(self):
355
368
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
665
678
    def set_config_push_strict(self, value):
666
679
        # set config var (any of bazaar.conf, locations.conf, branch.conf
667
680
        # should do)
668
 
        conf = self.tree.branch.get_config()
669
 
        conf.set_user_option('push_strict', value)
 
681
        conf = self.tree.branch.get_config_stack()
 
682
        conf.set('push_strict', value)
670
683
 
671
684
    _default_command = ['push', '../to']
672
685
    _default_wd = 'local'
729
742
        self.assertPushSucceeds([])
730
743
 
731
744
 
 
745
strict_push_change_scenarios = [
 
746
    ('uncommitted',
 
747
        dict(_changes_type= '_uncommitted_changes')),
 
748
    ('pending-merges',
 
749
        dict(_changes_type= '_pending_merges')),
 
750
    ('out-of-sync-trees',
 
751
        dict(_changes_type= '_out_of_sync_trees')),
 
752
    ]
 
753
 
 
754
 
732
755
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
733
756
                                TestPushStrictMixin):
734
757
 
 
758
    scenarios = strict_push_change_scenarios 
735
759
    _changes_type = None # Set by load_tests
736
760
 
737
761
    def setUp(self):
820
844
        self.assertEquals("", output)
821
845
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
822
846
            " push to dummy. You may want to use dpush instead.\n")
 
847
 
 
848
 
 
849
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
850
 
 
851
    def test_push_log_format(self):
 
852
        self.run_script("""
 
853
            $ bzr init trunk
 
854
            Created a standalone tree (format: 2a)
 
855
            $ cd trunk
 
856
            $ echo foo > file
 
857
            $ bzr add
 
858
            adding file
 
859
            $ bzr commit -m 'we need some foo'
 
860
            2>Committing to:...trunk/
 
861
            2>added file
 
862
            2>Committed revision 1.
 
863
            $ bzr init ../feature
 
864
            Created a standalone tree (format: 2a)
 
865
            $ bzr push -v ../feature -Olog_format=line
 
866
            Added Revisions:
 
867
            1: jrandom@example.com ...we need some foo
 
868
            2>All changes applied successfully.
 
869
            2>Pushed up to revision 1.
 
870
            """)