/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

  • Committer: John Arbash Meinel
  • Date: 2009-06-18 18:18:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4461.
  • Revision ID: john@arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
Which is completely valid, but 'broke' one of the tests.
So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
has to check the root keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
 
    test_foreign,
38
 
    test_server,
39
 
    )
 
34
from bzrlib.tests import http_server
40
35
from bzrlib.transport import memory
41
36
 
42
37
 
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
65
 
 
66
 
 
67
38
class TestPush(tests.TestCaseWithTransport):
68
39
 
69
40
    def test_push_error_on_vfs_http(self):
244
215
        remote = branch.Branch.open('public')
245
216
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
217
 
247
 
    def test_push_smart_tags_streaming_acceptance(self):
248
 
        self.setup_smart_server_with_call_log()
249
 
        t = self.make_branch_and_tree('from')
250
 
        rev_id = t.commit(allow_pointless=True, message='first commit')
251
 
        t.branch.tags.set_tag('new-tag', rev_id)
252
 
        self.reset_smart_call_log()
253
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
254
 
        # This figure represent the amount of work to perform this use case. It
255
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
256
 
        # being too low. If rpc_count increases, more network roundtrips have
257
 
        # become necessary for this use case. Please do not adjust this number
258
 
        # upwards without agreement from bzr's network support maintainers.
259
 
        self.assertLength(11, self.hpss_calls)
260
 
 
261
 
    def test_push_smart_incremental_acceptance(self):
262
 
        self.setup_smart_server_with_call_log()
263
 
        t = self.make_branch_and_tree('from')
264
 
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
265
 
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
266
 
        self.run_bzr(
267
 
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
268
 
        self.reset_smart_call_log()
269
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
270
 
        # This figure represent the amount of work to perform this use case. It
271
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
272
 
        # being too low. If rpc_count increases, more network roundtrips have
273
 
        # become necessary for this use case. Please do not adjust this number
274
 
        # upwards without agreement from bzr's network support maintainers.
275
 
        self.assertLength(11, self.hpss_calls)
276
 
 
277
218
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
219
        # If the default stacked-on location is a path element then branches
279
220
        # we push there over the smart server are stacked and their
340
281
        # The push should have created target/a
341
282
        self.failUnlessExists('target/a')
342
283
 
343
 
    def test_push_use_existing_into_empty_bzrdir(self):
344
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
345
 
        fails.
346
 
        """
347
 
        tree = self.create_simple_tree()
348
 
        self.build_tree(['target/', 'target/.bzr/'])
349
 
        self.run_bzr_error(
350
 
            ['Target directory ../target already contains a .bzr directory, '
351
 
             'but it is not valid.'],
352
 
            'push ../target --use-existing-dir', working_dir='tree')
353
 
 
354
284
    def test_push_onto_repo(self):
355
285
        """We should be able to 'bzr push' into an existing bzrdir."""
356
286
        tree = self.create_simple_tree()
545
475
        # subsequent log is accurate
546
476
        self.assertNotContainsRe(out, 'rev1')
547
477
 
548
 
    def test_push_from_subdir(self):
549
 
        t = self.make_branch_and_tree('tree')
550
 
        self.build_tree(['tree/dir/', 'tree/dir/file'])
551
 
        t.add('dir', 'dir/file')
552
 
        t.commit('r1')
553
 
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
554
 
        self.assertEqual('', out)
555
 
        self.assertEqual('Created new branch.\n', err)
556
 
 
557
478
 
558
479
class RedirectingMemoryTransport(memory.MemoryTransport):
559
480
 
560
481
    def mkdir(self, relpath, mode=None):
 
482
        from bzrlib.trace import mutter
561
483
        if self._cwd == '/source/':
562
484
            raise errors.RedirectRequested(self.abspath(relpath),
563
485
                                           self.abspath('../target'),
570
492
            return super(RedirectingMemoryTransport, self).mkdir(
571
493
                relpath, mode)
572
494
 
573
 
    def get(self, relpath):
574
 
        if self.clone(relpath)._cwd == '/infinite-loop/':
575
 
            raise errors.RedirectRequested(self.abspath(relpath),
576
 
                                           self.abspath('../infinite-loop'),
577
 
                                           is_permanent=True)
578
 
        else:
579
 
            return super(RedirectingMemoryTransport, self).get(relpath)
580
 
 
581
495
    def _redirected_to(self, source, target):
582
496
        # We do accept redirections
583
497
        return transport.get_transport(target)
585
499
 
586
500
class RedirectingMemoryServer(memory.MemoryServer):
587
501
 
588
 
    def start_server(self):
 
502
    def setUp(self):
589
503
        self._dirs = {'/': None}
590
504
        self._files = {}
591
505
        self._locks = {}
599
513
        result._locks = self._locks
600
514
        return result
601
515
 
602
 
    def stop_server(self):
 
516
    def tearDown(self):
603
517
        transport.unregister_transport(self._scheme, self._memory_factory)
604
518
 
605
519
 
608
522
    def setUp(self):
609
523
        tests.TestCaseWithTransport.setUp(self)
610
524
        self.memory_server = RedirectingMemoryServer()
611
 
        self.start_server(self.memory_server)
 
525
        self.memory_server.setUp()
 
526
        self.addCleanup(self.memory_server.tearDown)
 
527
 
612
528
        # Make the branch and tree that we'll be pushing.
613
529
        t = self.make_branch_and_tree('tree')
614
530
        self.build_tree(['tree/file'])
641
557
        self.assertEqual('', out)
642
558
 
643
559
 
644
 
class TestPushStrictMixin(object):
 
560
class TestPushStrict(tests.TestCaseWithTransport):
645
561
 
646
562
    def make_local_branch_and_tree(self):
647
 
        self.tree = self.make_branch_and_tree('local')
 
563
        tree = self.make_branch_and_tree('local')
648
564
        self.build_tree_contents([('local/file', 'initial')])
649
 
        self.tree.add('file')
650
 
        self.tree.commit('adding file', rev_id='added')
 
565
        tree.add('file')
 
566
        tree.commit('adding file', rev_id='from-1')
 
567
        return tree
 
568
 
 
569
    def make_local_branch_and_tree_with_changes(self):
 
570
        tree = self.make_local_branch_and_tree()
 
571
        # Make some changes
651
572
        self.build_tree_contents([('local/file', 'modified')])
652
 
        self.tree.commit('modify file', rev_id='modified')
 
573
        return tree
653
574
 
654
 
    def set_config_push_strict(self, value):
 
575
    def set_config_push_strict(self, tree, value):
655
576
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
577
        # should do)
657
 
        conf = self.tree.branch.get_config()
 
578
        conf = tree.branch.get_config()
658
579
        conf.set_user_option('push_strict', value)
659
580
 
660
 
    _default_command = ['push', '../to']
661
 
    _default_wd = 'local'
662
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
663
 
                       'changes \(See bzr status\)\.',]
664
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
665
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
666
 
 
667
 
 
668
 
    def assertPushFails(self, args):
669
 
        out, err = self.run_bzr_error(self._default_errors,
670
 
                                      self._default_command + args,
671
 
                                      working_dir=self._default_wd, retcode=3)
672
 
        self.assertContainsRe(err, self._default_additional_error)
673
 
 
674
 
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
675
 
        if with_warning:
676
 
            error_regexes = self._default_errors
677
 
        else:
678
 
            error_regexes = []
679
 
        out, err = self.run_bzr(self._default_command + args,
680
 
                                working_dir=self._default_wd,
681
 
                                error_regexes=error_regexes)
682
 
        if with_warning:
683
 
            self.assertContainsRe(err, self._default_additional_warning)
684
 
        else:
685
 
            self.assertNotContainsRe(err, self._default_additional_warning)
686
 
        branch_from = branch.Branch.open(self._default_wd)
687
 
        if revid_to_push is None:
688
 
            revid_to_push = branch_from.last_revision()
689
 
        branch_to = branch.Branch.open('to')
690
 
        repo_to = branch_to.repository
691
 
        self.assertTrue(repo_to.has_revision(revid_to_push))
692
 
        self.assertEqual(revid_to_push, branch_to.last_revision())
693
 
 
694
 
 
695
 
 
696
 
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
697
 
                                   TestPushStrictMixin):
698
 
 
699
 
    def setUp(self):
700
 
        super(TestPushStrictWithoutChanges, self).setUp()
701
 
        self.make_local_branch_and_tree()
702
 
 
703
 
    def test_push_default(self):
704
 
        self.assertPushSucceeds([])
705
 
 
706
 
    def test_push_strict(self):
707
 
        self.assertPushSucceeds(['--strict'])
708
 
 
709
 
    def test_push_no_strict(self):
710
 
        self.assertPushSucceeds(['--no-strict'])
711
 
 
712
 
    def test_push_config_var_strict(self):
713
 
        self.set_config_push_strict('true')
714
 
        self.assertPushSucceeds([])
715
 
 
716
 
    def test_push_config_var_no_strict(self):
717
 
        self.set_config_push_strict('false')
718
 
        self.assertPushSucceeds([])
719
 
 
720
 
 
721
 
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
 
                                TestPushStrictMixin):
723
 
 
724
 
    _changes_type = None # Set by load_tests
725
 
 
726
 
    def setUp(self):
727
 
        super(TestPushStrictWithChanges, self).setUp()
728
 
        # Apply the changes defined in load_tests: one of _uncommitted_changes,
729
 
        # _pending_merges or _out_of_sync_trees
730
 
        getattr(self, self._changes_type)()
731
 
 
732
 
    def _uncommitted_changes(self):
733
 
        self.make_local_branch_and_tree()
734
 
        # Make a change without committing it
735
 
        self.build_tree_contents([('local/file', 'in progress')])
736
 
 
737
 
    def _pending_merges(self):
738
 
        self.make_local_branch_and_tree()
739
 
        # Create 'other' branch containing a new file
740
 
        other_bzrdir = self.tree.bzrdir.sprout('other')
741
 
        other_tree = other_bzrdir.open_workingtree()
742
 
        self.build_tree_contents([('other/other-file', 'other')])
743
 
        other_tree.add('other-file')
744
 
        other_tree.commit('other commit', rev_id='other')
745
 
        # Merge and revert, leaving a pending merge
746
 
        self.tree.merge_from_branch(other_tree.branch)
747
 
        self.tree.revert(filenames=['other-file'], backups=False)
748
 
 
749
 
    def _out_of_sync_trees(self):
750
 
        self.make_local_branch_and_tree()
751
 
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
752
 
        # Make a change and commit it
753
 
        self.build_tree_contents([('local/file', 'modified in local')])
754
 
        self.tree.commit('modify file', rev_id='modified-in-local')
755
 
        # Exercise commands from the checkout directory
756
 
        self._default_wd = 'checkout'
757
 
        self._default_errors = ["Working tree is out of date, please run"
758
 
                                " 'bzr update'\.",]
759
 
 
760
 
    def test_push_default(self):
761
 
        self.assertPushSucceeds([], with_warning=True)
762
 
 
763
 
    def test_push_with_revision(self):
764
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
765
 
 
766
 
    def test_push_no_strict(self):
767
 
        self.assertPushSucceeds(['--no-strict'])
 
581
    def assertPushFails(self, location, *args):
 
582
        self.run_bzr_error(['Working tree ".*/local/"'
 
583
                            ' has uncommitted changes.$',],
 
584
                           ['push', '../' + location] + list(args),
 
585
                           working_dir='local', retcode=3)
 
586
 
 
587
    def assertPushSucceeds(self, location, *args):
 
588
        self.run_bzr(['push', '../' + location] + list(args),
 
589
                     working_dir='local')
 
590
        tree_to = workingtree.WorkingTree.open(location)
 
591
        repo_to = tree_to.branch.repository
 
592
        self.assertTrue(repo_to.has_revision('from-1'))
 
593
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
594
 
 
595
    def test_push_default(self):
 
596
        tree = self.make_local_branch_and_tree_with_changes()
 
597
        self.assertPushSucceeds('to')
 
598
 
 
599
    def test_push_no_strict_with_changes(self):
 
600
        tree = self.make_local_branch_and_tree_with_changes()
 
601
        self.assertPushSucceeds('to', '--no-strict')
768
602
 
769
603
    def test_push_strict_with_changes(self):
770
 
        self.assertPushFails(['--strict'])
 
604
        tree = self.make_local_branch_and_tree_with_changes()
 
605
        self.assertPushFails('to', '--strict')
 
606
 
 
607
    def test_push_strict_without_changes(self):
 
608
        tree = self.make_local_branch_and_tree()
 
609
        self.assertPushSucceeds('to', '--strict')
771
610
 
772
611
    def test_push_respect_config_var_strict(self):
773
 
        self.set_config_push_strict('true')
774
 
        self.assertPushFails([])
 
612
        tree = self.make_local_branch_and_tree_with_changes()
 
613
        self.set_config_push_strict(tree, 'true')
 
614
        self.assertPushFails('to')
775
615
 
776
616
    def test_push_bogus_config_var_ignored(self):
777
 
        self.set_config_push_strict("I don't want you to be strict")
778
 
        self.assertPushSucceeds([], with_warning=True)
 
617
        tree = self.make_local_branch_and_tree_with_changes()
 
618
        self.set_config_push_strict(tree, "I don't want you to be strict")
 
619
        self.assertPushSucceeds('to')
779
620
 
780
621
    def test_push_no_strict_command_line_override_config(self):
781
 
        self.set_config_push_strict('yES')
782
 
        self.assertPushFails([])
783
 
        self.assertPushSucceeds(['--no-strict'])
 
622
        tree = self.make_local_branch_and_tree_with_changes()
 
623
        self.set_config_push_strict(tree, 'yES')
 
624
        self.assertPushFails('to')
 
625
        self.assertPushSucceeds('to', '--no-strict')
784
626
 
785
627
    def test_push_strict_command_line_override_config(self):
786
 
        self.set_config_push_strict('oFF')
787
 
        self.assertPushFails(['--strict'])
788
 
        self.assertPushSucceeds([])
789
 
 
790
 
 
791
 
class TestPushForeign(blackbox.ExternalBase):
792
 
 
793
 
    def setUp(self):
794
 
        super(TestPushForeign, self).setUp()
795
 
        test_foreign.register_dummy_foreign_for_test(self)
796
 
 
797
 
    def make_dummy_builder(self, relpath):
798
 
        builder = self.make_branch_builder(
799
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
 
        builder.build_snapshot('revid', None,
801
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
802
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
803
 
        return builder
804
 
 
805
 
    def test_no_roundtripping(self):
806
 
        target_branch = self.make_dummy_builder('dp').get_branch()
807
 
        source_tree = self.make_branch_and_tree("dc")
808
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
809
 
        self.assertEquals("", output)
810
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
 
            " push to dummy. You may want to use dpush instead.\n")
 
628
        tree = self.make_local_branch_and_tree_with_changes()
 
629
        self.set_config_push_strict(tree, 'oFF')
 
630
        self.assertPushFails('to', '--strict')
 
631
        self.assertPushSucceeds('to')