~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: 2010-02-11 06:15:33 UTC
  • mfrom: (5025.1.6 331095-malloc)
  • Revision ID: pqm@pqm.ubuntu.com-20100211061533-5glf4faoutadhql9
(mbp) avoid malloc(0)

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
34
34
from bzrlib.tests import (
35
35
    blackbox,
36
36
    http_server,
37
 
    scenarios,
38
37
    test_foreign,
39
 
    test_server,
40
38
    )
41
39
from bzrlib.transport import memory
42
40
 
43
41
 
44
 
load_tests = scenarios.load_tests_apply_scenarios
 
42
def load_tests(standard_tests, module, loader):
 
43
    """Multiply tests for the push command."""
 
44
    result = loader.suiteClass()
 
45
 
 
46
    # one for each king of change
 
47
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
48
        standard_tests, tests.condition_isinstance((
 
49
                TestPushStrictWithChanges,
 
50
                )))
 
51
    changes_scenarios = [
 
52
        ('uncommitted',
 
53
         dict(_changes_type= '_uncommitted_changes')),
 
54
        ('pending-merges',
 
55
         dict(_changes_type= '_pending_merges')),
 
56
        ('out-of-sync-trees',
 
57
         dict(_changes_type= '_out_of_sync_trees')),
 
58
        ]
 
59
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
60
    # No parametrization for the remaining tests
 
61
    result.addTests(remaining_tests)
 
62
 
 
63
    return result
45
64
 
46
65
 
47
66
class TestPush(tests.TestCaseWithTransport):
126
145
        b2 = branch.Branch.open('pushed-location')
127
146
        self.assertEndsWith(b2.base, 'pushed-location/')
128
147
 
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
 
 
140
148
    def test_push_new_branch_revision_count(self):
141
149
        # bzr push of a branch with revisions to a new location
142
150
        # should print the number of revisions equal to the length of the
199
207
        t.commit(allow_pointless=True,
200
208
                message='first commit')
201
209
        self.run_bzr('push -d from to-one')
202
 
        self.assertPathExists('to-one')
 
210
        self.failUnlessExists('to-one')
203
211
        self.run_bzr('push -d %s %s'
204
212
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
205
 
        self.assertPathExists('to-two')
206
 
 
207
 
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
208
 
        # See https://bugs.launchpad.net/bzr/+bug/465517
209
 
        target_repo = self.make_repository('target')
210
 
        source = self.make_branch_builder('source')
211
 
        source.start_series()
212
 
        source.build_snapshot('A', None, [
213
 
            ('add', ('', 'root-id', 'directory', None))])
214
 
        source.build_snapshot('B', ['A'], [])
215
 
        source.build_snapshot('C', ['A'], [])
216
 
        source.finish_series()
217
 
        self.run_bzr('push target -d source')
218
 
        self.addCleanup(target_repo.lock_read().unlock)
219
 
        # We should have pushed 'C', but not 'B', since it isn't in the
220
 
        # ancestry
221
 
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
 
213
        self.failUnlessExists('to-two')
222
214
 
223
215
    def test_push_smart_non_stacked_streaming_acceptance(self):
224
216
        self.setup_smart_server_with_call_log()
247
239
        # being too low. If rpc_count increases, more network roundtrips have
248
240
        # become necessary for this use case. Please do not adjust this number
249
241
        # upwards without agreement from bzr's network support maintainers.
250
 
        self.assertLength(13, self.hpss_calls)
 
242
        self.assertLength(14, self.hpss_calls)
251
243
        remote = branch.Branch.open('public')
252
244
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
253
245
 
324
316
                     working_dir='tree')
325
317
        new_tree = workingtree.WorkingTree.open('new/tree')
326
318
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
327
 
        self.assertPathExists('new/tree/a')
 
319
        self.failUnlessExists('new/tree/a')
328
320
 
329
321
    def test_push_use_existing(self):
330
322
        """'bzr push --use-existing-dir' can push into an existing dir.
345
337
        new_tree = workingtree.WorkingTree.open('target')
346
338
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
347
339
        # The push should have created target/a
348
 
        self.assertPathExists('target/a')
 
340
        self.failUnlessExists('target/a')
349
341
 
350
342
    def test_push_use_existing_into_empty_bzrdir(self):
351
343
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
668
660
    _default_wd = 'local'
669
661
    _default_errors = ['Working tree ".*/local/" has uncommitted '
670
662
                       'changes \(See bzr status\)\.',]
671
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
672
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
673
 
 
 
663
    _default_pushed_revid = 'modified'
674
664
 
675
665
    def assertPushFails(self, args):
676
 
        out, err = self.run_bzr_error(self._default_errors,
677
 
                                      self._default_command + args,
678
 
                                      working_dir=self._default_wd, retcode=3)
679
 
        self.assertContainsRe(err, self._default_additional_error)
 
666
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
667
                           working_dir=self._default_wd, retcode=3)
680
668
 
681
 
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
682
 
        if with_warning:
683
 
            error_regexes = self._default_errors
684
 
        else:
685
 
            error_regexes = []
686
 
        out, err = self.run_bzr(self._default_command + args,
687
 
                                working_dir=self._default_wd,
688
 
                                error_regexes=error_regexes)
689
 
        if with_warning:
690
 
            self.assertContainsRe(err, self._default_additional_warning)
691
 
        else:
692
 
            self.assertNotContainsRe(err, self._default_additional_warning)
693
 
        branch_from = branch.Branch.open(self._default_wd)
694
 
        if revid_to_push is None:
695
 
            revid_to_push = branch_from.last_revision()
696
 
        branch_to = branch.Branch.open('to')
697
 
        repo_to = branch_to.repository
698
 
        self.assertTrue(repo_to.has_revision(revid_to_push))
699
 
        self.assertEqual(revid_to_push, branch_to.last_revision())
 
669
    def assertPushSucceeds(self, args, pushed_revid=None):
 
670
        self.run_bzr(self._default_command + args,
 
671
                     working_dir=self._default_wd)
 
672
        if pushed_revid is None:
 
673
            pushed_revid = self._default_pushed_revid
 
674
        tree_to = workingtree.WorkingTree.open('to')
 
675
        repo_to = tree_to.branch.repository
 
676
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
677
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
700
678
 
701
679
 
702
680
 
725
703
        self.assertPushSucceeds([])
726
704
 
727
705
 
728
 
strict_push_change_scenarios = [
729
 
    ('uncommitted',
730
 
        dict(_changes_type= '_uncommitted_changes')),
731
 
    ('pending-merges',
732
 
        dict(_changes_type= '_pending_merges')),
733
 
    ('out-of-sync-trees',
734
 
        dict(_changes_type= '_out_of_sync_trees')),
735
 
    ]
736
 
 
737
 
 
738
706
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
739
707
                                TestPushStrictMixin):
740
708
 
741
 
    scenarios = strict_push_change_scenarios 
742
709
    _changes_type = None # Set by load_tests
743
710
 
744
711
    def setUp(self):
774
741
        self._default_wd = 'checkout'
775
742
        self._default_errors = ["Working tree is out of date, please run"
776
743
                                " 'bzr update'\.",]
 
744
        self._default_pushed_revid = 'modified-in-local'
777
745
 
778
746
    def test_push_default(self):
779
 
        self.assertPushSucceeds([], with_warning=True)
 
747
        self.assertPushFails([])
780
748
 
781
749
    def test_push_with_revision(self):
782
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
750
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
783
751
 
784
752
    def test_push_no_strict(self):
785
753
        self.assertPushSucceeds(['--no-strict'])
793
761
 
794
762
    def test_push_bogus_config_var_ignored(self):
795
763
        self.set_config_push_strict("I don't want you to be strict")
796
 
        self.assertPushSucceeds([], with_warning=True)
 
764
        self.assertPushFails([])
797
765
 
798
766
    def test_push_no_strict_command_line_override_config(self):
799
767
        self.set_config_push_strict('yES')
806
774
        self.assertPushSucceeds([])
807
775
 
808
776
 
809
 
class TestPushForeign(tests.TestCaseWithTransport):
 
777
class TestPushForeign(blackbox.ExternalBase):
810
778
 
811
779
    def setUp(self):
812
780
        super(TestPushForeign, self).setUp()