/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_push.py

(gz) Bug #613247, cleanup test cases when they are finished running,
 lowering peak memory during selftest. (Martin Packman)

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
34
34
from bzrlib.tests import (
35
35
    blackbox,
36
36
    http_server,
 
37
    scenarios,
 
38
    script,
37
39
    test_foreign,
38
40
    test_server,
39
41
    )
40
42
from bzrlib.transport import memory
41
43
 
42
44
 
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
 
45
load_tests = scenarios.load_tests_apply_scenarios
65
46
 
66
47
 
67
48
class TestPush(tests.TestCaseWithTransport):
124
105
        transport.delete('branch_b/c')
125
106
        out, err = self.run_bzr('push', working_dir='branch_a')
126
107
        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
108
        self.assertEqual(err,
 
109
                         'Using saved push location: %s\n'
131
110
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
111
                         'Pushed up to revision 2.\n'
 
112
                         % urlutils.local_path_from_url(path))
133
113
        self.assertEqual(path,
134
114
                         branch_b.bzrdir.root_transport.base)
135
115
        # test explicit --remember
146
126
        b2 = branch.Branch.open('pushed-location')
147
127
        self.assertEndsWith(b2.base, 'pushed-location/')
148
128
 
 
129
    def test_push_no_tree(self):
 
130
        # bzr push --no-tree of a branch with working trees
 
131
        b = self.make_branch_and_tree('push-from')
 
132
        self.build_tree(['push-from/file'])
 
133
        b.add('file')
 
134
        b.commit('commit 1')
 
135
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
136
        self.assertEqual('', out)
 
137
        self.assertEqual('Created new branch.\n', err)
 
138
        self.assertPathDoesNotExist('push-to/file')
 
139
 
149
140
    def test_push_new_branch_revision_count(self):
150
141
        # bzr push of a branch with revisions to a new location
151
142
        # should print the number of revisions equal to the length of the
158
149
        self.assertEqual('', out)
159
150
        self.assertEqual('Created new branch.\n', err)
160
151
 
 
152
    def test_push_quiet(self):
 
153
        # test that using -q makes output quiet
 
154
        t = self.make_branch_and_tree('tree')
 
155
        self.build_tree(['tree/file'])
 
156
        t.add('file')
 
157
        t.commit('commit 1')
 
158
        self.run_bzr('push -d tree pushed-to')
 
159
        path = t.branch.get_push_location()
 
160
        out, err = self.run_bzr('push', working_dir="tree")
 
161
        self.assertEqual('Using saved push location: %s\n'
 
162
                         'No new revisions or tags to push.\n' %
 
163
                         urlutils.local_path_from_url(path), err)
 
164
        out, err = self.run_bzr('push -q', working_dir="tree")
 
165
        self.assertEqual('', out)
 
166
        self.assertEqual('', err)
 
167
 
161
168
    def test_push_only_pushes_history(self):
162
169
        # Knit branches should only push the history for the current revision.
163
170
        format = bzrdir.BzrDirMetaFormat1()
208
215
        t.commit(allow_pointless=True,
209
216
                message='first commit')
210
217
        self.run_bzr('push -d from to-one')
211
 
        self.failUnlessExists('to-one')
 
218
        self.assertPathExists('to-one')
212
219
        self.run_bzr('push -d %s %s'
213
220
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('to-two')
 
221
        self.assertPathExists('to-two')
 
222
 
 
223
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
224
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
225
        target_repo = self.make_repository('target')
 
226
        source = self.make_branch_builder('source')
 
227
        source.start_series()
 
228
        source.build_snapshot('A', None, [
 
229
            ('add', ('', 'root-id', 'directory', None))])
 
230
        source.build_snapshot('B', ['A'], [])
 
231
        source.build_snapshot('C', ['A'], [])
 
232
        source.finish_series()
 
233
        self.run_bzr('push target -d source')
 
234
        self.addCleanup(target_repo.lock_read().unlock)
 
235
        # We should have pushed 'C', but not 'B', since it isn't in the
 
236
        # ancestry
 
237
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
215
238
 
216
239
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
240
        self.setup_smart_server_with_call_log()
240
263
        # being too low. If rpc_count increases, more network roundtrips have
241
264
        # become necessary for this use case. Please do not adjust this number
242
265
        # upwards without agreement from bzr's network support maintainers.
243
 
        self.assertLength(14, self.hpss_calls)
 
266
        self.assertLength(13, self.hpss_calls)
244
267
        remote = branch.Branch.open('public')
245
268
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
269
 
317
340
                     working_dir='tree')
318
341
        new_tree = workingtree.WorkingTree.open('new/tree')
319
342
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
343
        self.assertPathExists('new/tree/a')
321
344
 
322
345
    def test_push_use_existing(self):
323
346
        """'bzr push --use-existing-dir' can push into an existing dir.
338
361
        new_tree = workingtree.WorkingTree.open('target')
339
362
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
363
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
364
        self.assertPathExists('target/a')
342
365
 
343
366
    def test_push_use_existing_into_empty_bzrdir(self):
344
367
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
654
677
    def set_config_push_strict(self, value):
655
678
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
679
        # should do)
657
 
        conf = self.tree.branch.get_config()
658
 
        conf.set_user_option('push_strict', value)
 
680
        conf = self.tree.branch.get_config_stack()
 
681
        conf.set('push_strict', value)
659
682
 
660
683
    _default_command = ['push', '../to']
661
684
    _default_wd = 'local'
718
741
        self.assertPushSucceeds([])
719
742
 
720
743
 
 
744
strict_push_change_scenarios = [
 
745
    ('uncommitted',
 
746
        dict(_changes_type= '_uncommitted_changes')),
 
747
    ('pending-merges',
 
748
        dict(_changes_type= '_pending_merges')),
 
749
    ('out-of-sync-trees',
 
750
        dict(_changes_type= '_out_of_sync_trees')),
 
751
    ]
 
752
 
 
753
 
721
754
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
755
                                TestPushStrictMixin):
723
756
 
 
757
    scenarios = strict_push_change_scenarios 
724
758
    _changes_type = None # Set by load_tests
725
759
 
726
760
    def setUp(self):
788
822
        self.assertPushSucceeds([])
789
823
 
790
824
 
791
 
class TestPushForeign(blackbox.ExternalBase):
 
825
class TestPushForeign(tests.TestCaseWithTransport):
792
826
 
793
827
    def setUp(self):
794
828
        super(TestPushForeign, self).setUp()
809
843
        self.assertEquals("", output)
810
844
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
845
            " push to dummy. You may want to use dpush instead.\n")
 
846
 
 
847
 
 
848
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
849
 
 
850
    def test_push_log_format(self):
 
851
        self.run_script("""
 
852
            $ bzr init trunk
 
853
            Created a standalone tree (format: 2a)
 
854
            $ cd trunk
 
855
            $ echo foo > file
 
856
            $ bzr add
 
857
            adding file
 
858
            $ bzr commit -m 'we need some foo'
 
859
            2>Committing to:...trunk/
 
860
            2>added file
 
861
            2>Committed revision 1.
 
862
            $ bzr init ../feature
 
863
            Created a standalone tree (format: 2a)
 
864
            $ bzr push -v ../feature -Olog_format=line
 
865
            Added Revisions:
 
866
            1: jrandom@example.com ...we need some foo
 
867
            2>All changes applied successfully.
 
868
            2>Pushed up to revision 1.
 
869
            """)