~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2009-08-13 21:54:04 UTC
  • mto: This revision was merged to the branch mainline in revision 4629.
  • Revision ID: john@arbash-meinel.com-20090813215404-f1e6vemv7vxyivoe
Create the crude merge_sort implementation that just thunks over to the old implementation.
The main win here is that we get to copy across all the tests so far, and they all pass. :)

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):
126
141
        b2 = branch.Branch.open('pushed-location')
127
142
        self.assertEndsWith(b2.base, 'pushed-location/')
128
143
 
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
144
    def test_push_new_branch_revision_count(self):
141
145
        # bzr push of a branch with revisions to a new location
142
146
        # should print the number of revisions equal to the length of the
199
203
        t.commit(allow_pointless=True,
200
204
                message='first commit')
201
205
        self.run_bzr('push -d from to-one')
202
 
        self.assertPathExists('to-one')
 
206
        self.failUnlessExists('to-one')
203
207
        self.run_bzr('push -d %s %s'
204
208
            % 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()))
 
209
        self.failUnlessExists('to-two')
222
210
 
223
211
    def test_push_smart_non_stacked_streaming_acceptance(self):
224
212
        self.setup_smart_server_with_call_log()
247
235
        # being too low. If rpc_count increases, more network roundtrips have
248
236
        # become necessary for this use case. Please do not adjust this number
249
237
        # upwards without agreement from bzr's network support maintainers.
250
 
        self.assertLength(13, self.hpss_calls)
 
238
        self.assertLength(14, self.hpss_calls)
251
239
        remote = branch.Branch.open('public')
252
240
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
253
241
 
265
253
        # upwards without agreement from bzr's network support maintainers.
266
254
        self.assertLength(11, self.hpss_calls)
267
255
 
268
 
    def test_push_smart_incremental_acceptance(self):
269
 
        self.setup_smart_server_with_call_log()
270
 
        t = self.make_branch_and_tree('from')
271
 
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
272
 
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
273
 
        self.run_bzr(
274
 
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
275
 
        self.reset_smart_call_log()
276
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
277
 
        # This figure represent the amount of work to perform this use case. It
278
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
279
 
        # being too low. If rpc_count increases, more network roundtrips have
280
 
        # become necessary for this use case. Please do not adjust this number
281
 
        # upwards without agreement from bzr's network support maintainers.
282
 
        self.assertLength(11, self.hpss_calls)
283
 
 
284
256
    def test_push_smart_with_default_stacking_url_path_segment(self):
285
257
        # If the default stacked-on location is a path element then branches
286
258
        # we push there over the smart server are stacked and their
324
296
                     working_dir='tree')
325
297
        new_tree = workingtree.WorkingTree.open('new/tree')
326
298
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
327
 
        self.assertPathExists('new/tree/a')
 
299
        self.failUnlessExists('new/tree/a')
328
300
 
329
301
    def test_push_use_existing(self):
330
302
        """'bzr push --use-existing-dir' can push into an existing dir.
345
317
        new_tree = workingtree.WorkingTree.open('target')
346
318
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
347
319
        # The push should have created target/a
348
 
        self.assertPathExists('target/a')
349
 
 
350
 
    def test_push_use_existing_into_empty_bzrdir(self):
351
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
352
 
        fails.
353
 
        """
354
 
        tree = self.create_simple_tree()
355
 
        self.build_tree(['target/', 'target/.bzr/'])
356
 
        self.run_bzr_error(
357
 
            ['Target directory ../target already contains a .bzr directory, '
358
 
             'but it is not valid.'],
359
 
            'push ../target --use-existing-dir', working_dir='tree')
 
320
        self.failUnlessExists('target/a')
360
321
 
361
322
    def test_push_onto_repo(self):
362
323
        """We should be able to 'bzr push' into an existing bzrdir."""
592
553
 
593
554
class RedirectingMemoryServer(memory.MemoryServer):
594
555
 
595
 
    def start_server(self):
 
556
    def setUp(self):
596
557
        self._dirs = {'/': None}
597
558
        self._files = {}
598
559
        self._locks = {}
606
567
        result._locks = self._locks
607
568
        return result
608
569
 
609
 
    def stop_server(self):
 
570
    def tearDown(self):
610
571
        transport.unregister_transport(self._scheme, self._memory_factory)
611
572
 
612
573
 
615
576
    def setUp(self):
616
577
        tests.TestCaseWithTransport.setUp(self)
617
578
        self.memory_server = RedirectingMemoryServer()
618
 
        self.start_server(self.memory_server)
 
579
        self.memory_server.setUp()
 
580
        self.addCleanup(self.memory_server.tearDown)
 
581
 
619
582
        # Make the branch and tree that we'll be pushing.
620
583
        t = self.make_branch_and_tree('tree')
621
584
        self.build_tree(['tree/file'])
668
631
    _default_wd = 'local'
669
632
    _default_errors = ['Working tree ".*/local/" has uncommitted '
670
633
                       '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
 
 
 
634
    _default_pushed_revid = 'modified'
674
635
 
675
636
    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)
 
637
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
638
                           working_dir=self._default_wd, retcode=3)
680
639
 
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())
 
640
    def assertPushSucceeds(self, args, pushed_revid=None):
 
641
        self.run_bzr(self._default_command + args,
 
642
                     working_dir=self._default_wd)
 
643
        if pushed_revid is None:
 
644
            pushed_revid = self._default_pushed_revid
 
645
        tree_to = workingtree.WorkingTree.open('to')
 
646
        repo_to = tree_to.branch.repository
 
647
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
648
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
700
649
 
701
650
 
702
651
 
725
674
        self.assertPushSucceeds([])
726
675
 
727
676
 
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
677
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
739
678
                                TestPushStrictMixin):
740
679
 
741
 
    scenarios = strict_push_change_scenarios 
742
680
    _changes_type = None # Set by load_tests
743
681
 
744
682
    def setUp(self):
745
683
        super(TestPushStrictWithChanges, self).setUp()
746
 
        # Apply the changes defined in load_tests: one of _uncommitted_changes,
747
 
        # _pending_merges or _out_of_sync_trees
748
684
        getattr(self, self._changes_type)()
749
685
 
750
686
    def _uncommitted_changes(self):
774
710
        self._default_wd = 'checkout'
775
711
        self._default_errors = ["Working tree is out of date, please run"
776
712
                                " 'bzr update'\.",]
 
713
        self._default_pushed_revid = 'modified-in-local'
777
714
 
778
715
    def test_push_default(self):
779
 
        self.assertPushSucceeds([], with_warning=True)
 
716
        self.assertPushFails([])
780
717
 
781
718
    def test_push_with_revision(self):
782
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
719
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
783
720
 
784
721
    def test_push_no_strict(self):
785
722
        self.assertPushSucceeds(['--no-strict'])
793
730
 
794
731
    def test_push_bogus_config_var_ignored(self):
795
732
        self.set_config_push_strict("I don't want you to be strict")
796
 
        self.assertPushSucceeds([], with_warning=True)
 
733
        self.assertPushFails([])
797
734
 
798
735
    def test_push_no_strict_command_line_override_config(self):
799
736
        self.set_config_push_strict('yES')
804
741
        self.set_config_push_strict('oFF')
805
742
        self.assertPushFails(['--strict'])
806
743
        self.assertPushSucceeds([])
807
 
 
808
 
 
809
 
class TestPushForeign(tests.TestCaseWithTransport):
810
 
 
811
 
    def setUp(self):
812
 
        super(TestPushForeign, self).setUp()
813
 
        test_foreign.register_dummy_foreign_for_test(self)
814
 
 
815
 
    def make_dummy_builder(self, relpath):
816
 
        builder = self.make_branch_builder(
817
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
818
 
        builder.build_snapshot('revid', None,
819
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
820
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
821
 
        return builder
822
 
 
823
 
    def test_no_roundtripping(self):
824
 
        target_branch = self.make_dummy_builder('dp').get_branch()
825
 
        source_tree = self.make_branch_and_tree("dc")
826
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
827
 
        self.assertEquals("", output)
828
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
829
 
            " push to dummy. You may want to use dpush instead.\n")