~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-09 02:53:42 UTC
  • mfrom: (4873.2.3 2.1.0b4-win32-test-imports)
  • Revision ID: pqm@pqm.ubuntu.com-20091209025342-sidvxfcqdgxmuz59
(jam) Get the test suite running again on Windows, (bug #492561)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008 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
31
31
    workingtree
32
32
    )
33
33
from bzrlib.repofmt import knitrepo
34
 
from bzrlib.tests import (
35
 
    blackbox,
36
 
    http_server,
37
 
    scenarios,
38
 
    test_foreign,
39
 
    test_server,
40
 
    )
 
34
from bzrlib.tests import http_server
41
35
from bzrlib.transport import memory
42
36
 
43
37
 
44
 
load_tests = scenarios.load_tests_apply_scenarios
 
38
def load_tests(standard_tests, module, loader):
 
39
    """Multiply tests for the push command."""
 
40
    result = loader.suiteClass()
 
41
 
 
42
    # one for each king of change
 
43
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
44
        standard_tests, tests.condition_isinstance((
 
45
                TestPushStrictWithChanges,
 
46
                )))
 
47
    changes_scenarios = [
 
48
        ('uncommitted',
 
49
         dict(_changes_type= '_uncommitted_changes')),
 
50
        ('pending-merges',
 
51
         dict(_changes_type= '_pending_merges')),
 
52
        ('out-of-sync-trees',
 
53
         dict(_changes_type= '_out_of_sync_trees')),
 
54
        ]
 
55
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
56
    # No parametrization for the remaining tests
 
57
    result.addTests(remaining_tests)
 
58
 
 
59
    return result
45
60
 
46
61
 
47
62
class TestPush(tests.TestCaseWithTransport):
104
119
        transport.delete('branch_b/c')
105
120
        out, err = self.run_bzr('push', working_dir='branch_a')
106
121
        path = branch_a.get_push_location()
 
122
        self.assertEquals(out,
 
123
                          'Using saved push location: %s\n'
 
124
                          % urlutils.local_path_from_url(path))
107
125
        self.assertEqual(err,
108
 
                         'Using saved push location: %s\n'
109
126
                         'All changes applied successfully.\n'
110
 
                         'Pushed up to revision 2.\n'
111
 
                         % urlutils.local_path_from_url(path))
 
127
                         'Pushed up to revision 2.\n')
112
128
        self.assertEqual(path,
113
129
                         branch_b.bzrdir.root_transport.base)
114
130
        # test explicit --remember
125
141
        b2 = branch.Branch.open('pushed-location')
126
142
        self.assertEndsWith(b2.base, 'pushed-location/')
127
143
 
128
 
    def test_push_no_tree(self):
129
 
        # bzr push --no-tree of a branch with working trees
130
 
        b = self.make_branch_and_tree('push-from')
131
 
        self.build_tree(['push-from/file'])
132
 
        b.add('file')
133
 
        b.commit('commit 1')
134
 
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
135
 
        self.assertEqual('', out)
136
 
        self.assertEqual('Created new branch.\n', err)
137
 
        self.assertPathDoesNotExist('push-to/file')
138
 
 
139
144
    def test_push_new_branch_revision_count(self):
140
145
        # bzr push of a branch with revisions to a new location
141
146
        # should print the number of revisions equal to the length of the
148
153
        self.assertEqual('', out)
149
154
        self.assertEqual('Created new branch.\n', err)
150
155
 
151
 
    def test_push_quiet(self):
152
 
        # test that using -q makes output quiet
153
 
        t = self.make_branch_and_tree('tree')
154
 
        self.build_tree(['tree/file'])
155
 
        t.add('file')
156
 
        t.commit('commit 1')
157
 
        self.run_bzr('push -d tree pushed-to')
158
 
        path = t.branch.get_push_location()
159
 
        out, err = self.run_bzr('push', working_dir="tree")
160
 
        self.assertEqual('Using saved push location: %s\n'
161
 
                         'No new revisions or tags to push.\n' %
162
 
                         urlutils.local_path_from_url(path), err)
163
 
        out, err = self.run_bzr('push -q', working_dir="tree")
164
 
        self.assertEqual('', out)
165
 
        self.assertEqual('', err)
166
 
 
167
156
    def test_push_only_pushes_history(self):
168
157
        # Knit branches should only push the history for the current revision.
169
158
        format = bzrdir.BzrDirMetaFormat1()
214
203
        t.commit(allow_pointless=True,
215
204
                message='first commit')
216
205
        self.run_bzr('push -d from to-one')
217
 
        self.assertPathExists('to-one')
 
206
        self.failUnlessExists('to-one')
218
207
        self.run_bzr('push -d %s %s'
219
208
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
220
 
        self.assertPathExists('to-two')
221
 
 
222
 
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
223
 
        # See https://bugs.launchpad.net/bzr/+bug/465517
224
 
        target_repo = self.make_repository('target')
225
 
        source = self.make_branch_builder('source')
226
 
        source.start_series()
227
 
        source.build_snapshot('A', None, [
228
 
            ('add', ('', 'root-id', 'directory', None))])
229
 
        source.build_snapshot('B', ['A'], [])
230
 
        source.build_snapshot('C', ['A'], [])
231
 
        source.finish_series()
232
 
        self.run_bzr('push target -d source')
233
 
        self.addCleanup(target_repo.lock_read().unlock)
234
 
        # We should have pushed 'C', but not 'B', since it isn't in the
235
 
        # ancestry
236
 
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
 
209
        self.failUnlessExists('to-two')
237
210
 
238
211
    def test_push_smart_non_stacked_streaming_acceptance(self):
239
212
        self.setup_smart_server_with_call_log()
262
235
        # being too low. If rpc_count increases, more network roundtrips have
263
236
        # become necessary for this use case. Please do not adjust this number
264
237
        # upwards without agreement from bzr's network support maintainers.
265
 
        self.assertLength(13, self.hpss_calls)
 
238
        self.assertLength(14, self.hpss_calls)
266
239
        remote = branch.Branch.open('public')
267
240
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
268
241
 
339
312
                     working_dir='tree')
340
313
        new_tree = workingtree.WorkingTree.open('new/tree')
341
314
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
342
 
        self.assertPathExists('new/tree/a')
 
315
        self.failUnlessExists('new/tree/a')
343
316
 
344
317
    def test_push_use_existing(self):
345
318
        """'bzr push --use-existing-dir' can push into an existing dir.
360
333
        new_tree = workingtree.WorkingTree.open('target')
361
334
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
362
335
        # The push should have created target/a
363
 
        self.assertPathExists('target/a')
 
336
        self.failUnlessExists('target/a')
364
337
 
365
338
    def test_push_use_existing_into_empty_bzrdir(self):
366
339
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
607
580
 
608
581
class RedirectingMemoryServer(memory.MemoryServer):
609
582
 
610
 
    def start_server(self):
 
583
    def setUp(self):
611
584
        self._dirs = {'/': None}
612
585
        self._files = {}
613
586
        self._locks = {}
621
594
        result._locks = self._locks
622
595
        return result
623
596
 
624
 
    def stop_server(self):
 
597
    def tearDown(self):
625
598
        transport.unregister_transport(self._scheme, self._memory_factory)
626
599
 
627
600
 
683
656
    _default_wd = 'local'
684
657
    _default_errors = ['Working tree ".*/local/" has uncommitted '
685
658
                       'changes \(See bzr status\)\.',]
686
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
687
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
688
 
 
 
659
    _default_pushed_revid = 'modified'
689
660
 
690
661
    def assertPushFails(self, args):
691
 
        out, err = self.run_bzr_error(self._default_errors,
692
 
                                      self._default_command + args,
693
 
                                      working_dir=self._default_wd, retcode=3)
694
 
        self.assertContainsRe(err, self._default_additional_error)
 
662
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
663
                           working_dir=self._default_wd, retcode=3)
695
664
 
696
 
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
697
 
        if with_warning:
698
 
            error_regexes = self._default_errors
699
 
        else:
700
 
            error_regexes = []
701
 
        out, err = self.run_bzr(self._default_command + args,
702
 
                                working_dir=self._default_wd,
703
 
                                error_regexes=error_regexes)
704
 
        if with_warning:
705
 
            self.assertContainsRe(err, self._default_additional_warning)
706
 
        else:
707
 
            self.assertNotContainsRe(err, self._default_additional_warning)
708
 
        branch_from = branch.Branch.open(self._default_wd)
709
 
        if revid_to_push is None:
710
 
            revid_to_push = branch_from.last_revision()
711
 
        branch_to = branch.Branch.open('to')
712
 
        repo_to = branch_to.repository
713
 
        self.assertTrue(repo_to.has_revision(revid_to_push))
714
 
        self.assertEqual(revid_to_push, branch_to.last_revision())
 
665
    def assertPushSucceeds(self, args, pushed_revid=None):
 
666
        self.run_bzr(self._default_command + args,
 
667
                     working_dir=self._default_wd)
 
668
        if pushed_revid is None:
 
669
            pushed_revid = self._default_pushed_revid
 
670
        tree_to = workingtree.WorkingTree.open('to')
 
671
        repo_to = tree_to.branch.repository
 
672
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
673
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
715
674
 
716
675
 
717
676
 
740
699
        self.assertPushSucceeds([])
741
700
 
742
701
 
743
 
strict_push_change_scenarios = [
744
 
    ('uncommitted',
745
 
        dict(_changes_type= '_uncommitted_changes')),
746
 
    ('pending-merges',
747
 
        dict(_changes_type= '_pending_merges')),
748
 
    ('out-of-sync-trees',
749
 
        dict(_changes_type= '_out_of_sync_trees')),
750
 
    ]
751
 
 
752
 
 
753
702
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
754
703
                                TestPushStrictMixin):
755
704
 
756
 
    scenarios = strict_push_change_scenarios 
757
705
    _changes_type = None # Set by load_tests
758
706
 
759
707
    def setUp(self):
789
737
        self._default_wd = 'checkout'
790
738
        self._default_errors = ["Working tree is out of date, please run"
791
739
                                " 'bzr update'\.",]
 
740
        self._default_pushed_revid = 'modified-in-local'
792
741
 
793
742
    def test_push_default(self):
794
 
        self.assertPushSucceeds([], with_warning=True)
 
743
        self.assertPushFails([])
795
744
 
796
745
    def test_push_with_revision(self):
797
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
746
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
798
747
 
799
748
    def test_push_no_strict(self):
800
749
        self.assertPushSucceeds(['--no-strict'])
808
757
 
809
758
    def test_push_bogus_config_var_ignored(self):
810
759
        self.set_config_push_strict("I don't want you to be strict")
811
 
        self.assertPushSucceeds([], with_warning=True)
 
760
        self.assertPushFails([])
812
761
 
813
762
    def test_push_no_strict_command_line_override_config(self):
814
763
        self.set_config_push_strict('yES')
819
768
        self.set_config_push_strict('oFF')
820
769
        self.assertPushFails(['--strict'])
821
770
        self.assertPushSucceeds([])
822
 
 
823
 
 
824
 
class TestPushForeign(tests.TestCaseWithTransport):
825
 
 
826
 
    def setUp(self):
827
 
        super(TestPushForeign, self).setUp()
828
 
        test_foreign.register_dummy_foreign_for_test(self)
829
 
 
830
 
    def make_dummy_builder(self, relpath):
831
 
        builder = self.make_branch_builder(
832
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
833
 
        builder.build_snapshot('revid', None,
834
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
835
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
836
 
        return builder
837
 
 
838
 
    def test_no_roundtripping(self):
839
 
        target_branch = self.make_dummy_builder('dp').get_branch()
840
 
        source_tree = self.make_branch_and_tree("dc")
841
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
842
 
        self.assertEquals("", output)
843
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
844
 
            " push to dummy. You may want to use dpush instead.\n")