/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/per_branch/test_branch.py

  • Committer: Martin
  • Date: 2010-05-25 17:27:52 UTC
  • mfrom: (5254 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5257.
  • Revision ID: gzlist@googlemail.com-20100525172752-amm089xcikv968sw
Merge bzr.dev to unite with similar changes already made

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
16
16
 
17
17
"""Tests for branch implementations - tests a branch format."""
18
18
 
19
 
import os
20
 
import sys
21
 
 
22
19
from bzrlib import (
23
 
    branch,
 
20
    branch as _mod_branch,
24
21
    bzrdir,
 
22
    delta as _mod_delta,
25
23
    errors,
26
24
    gpg,
27
25
    merge,
28
26
    urlutils,
29
27
    transactions,
 
28
    transport,
30
29
    remote,
31
30
    repository,
 
31
    revision,
32
32
    tests,
33
33
    )
34
 
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
35
 
from bzrlib.delta import TreeDelta
36
 
from bzrlib.errors import (FileExists,
37
 
                           NoSuchRevision,
38
 
                           NoSuchFile,
39
 
                           UninitializableFormat,
40
 
                           NotBranchError,
41
 
                           )
42
 
from bzrlib.osutils import getcwd
43
 
import bzrlib.revision
44
34
from bzrlib.symbol_versioning import deprecated_in
45
 
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
35
from bzrlib.tests import (
 
36
    http_server,
 
37
    per_branch,
 
38
    )
46
39
from bzrlib.tests.http_server import HttpServer
47
 
from bzrlib.tests.per_branch import TestCaseWithBranch
48
 
from bzrlib.trace import mutter
49
 
from bzrlib.transport import get_transport
50
 
from bzrlib.transport.memory import MemoryServer
51
 
from bzrlib.upgrade import upgrade
52
 
from bzrlib.workingtree import WorkingTree
53
 
 
54
 
 
55
 
class TestTestCaseWithBranch(TestCaseWithBranch):
 
40
from bzrlib.transport import memory
 
41
 
 
42
 
 
43
class TestTestCaseWithBranch(per_branch.TestCaseWithBranch):
56
44
 
57
45
    def test_branch_format_matches_bzrdir_branch_format(self):
58
46
        bzrdir_branch_format = self.bzrdir_format.get_branch_format()
65
53
            branch._format.__class__)
66
54
 
67
55
 
68
 
class TestBranch(TestCaseWithBranch):
 
56
class TestBranch(per_branch.TestCaseWithBranch):
69
57
 
70
58
    def test_create_tree_with_merge(self):
71
59
        tree = self.create_tree_with_merge()
128
116
        tree_a.commit('rev2', rev_id='rev2')
129
117
 
130
118
        delta = tree_a.branch.get_revision_delta(1)
131
 
        self.assertIsInstance(delta, TreeDelta)
 
119
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
132
120
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
133
121
        delta = tree_a.branch.get_revision_delta(2)
134
 
        self.assertIsInstance(delta, TreeDelta)
 
122
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
135
123
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
136
124
 
137
125
    def get_unbalanced_tree_pair(self):
186
174
 
187
175
    def test_clone_branch_nickname(self):
188
176
        # test the nick name is preserved always
189
 
        raise TestSkipped('XXX branch cloning is not yet tested.')
 
177
        raise tests.TestSkipped('XXX branch cloning is not yet tested.')
190
178
 
191
179
    def test_clone_branch_parent(self):
192
180
        # test the parent is preserved always
358
346
        explicit nickname is set.  That is, an explicit nickname always
359
347
        overrides the implicit one.
360
348
        """
361
 
        t = get_transport(self.get_url())
 
349
        t = transport.get_transport(self.get_url())
362
350
        branch = self.make_branch('bzr.dev')
363
351
        # The nick will be 'bzr.dev', because there is no explicit nick set.
364
352
        self.assertEqual(branch.nick, 'bzr.dev')
365
353
        # Move the branch to a different directory, 'bzr.ab'.  Now that branch
366
354
        # will report its nick as 'bzr.ab'.
367
355
        t.move('bzr.dev', 'bzr.ab')
368
 
        branch = Branch.open(self.get_url('bzr.ab'))
 
356
        branch = _mod_branch.Branch.open(self.get_url('bzr.ab'))
369
357
        self.assertEqual(branch.nick, 'bzr.ab')
370
358
        # Set the branch nick explicitly.  This will ensure there's a branch
371
359
        # config file in the branch.
376
364
        # "Aaron's branch", regardless of directory name.
377
365
        self.assertEqual(branch.nick, "Aaron's branch")
378
366
        t.move('bzr.ab', 'integration')
379
 
        branch = Branch.open(self.get_url('integration'))
 
367
        branch = _mod_branch.Branch.open(self.get_url('integration'))
380
368
        self.assertEqual(branch.nick, "Aaron's branch")
381
369
        branch.nick = u"\u1234"
382
370
        self.assertEqual(branch.nick, u"\u1234")
391
379
        self.assertEqual(committed.properties["branch-nick"],
392
380
                         "My happy branch")
393
381
 
 
382
    def test_create_colocated(self):
 
383
        try:
 
384
            repo = self.make_repository('.', shared=True)
 
385
        except errors.IncompatibleFormat:
 
386
            return
 
387
        self.assertEquals(0, len(repo.bzrdir.list_branches()))
 
388
        try:
 
389
            child_branch1 = self.branch_format.initialize(repo.bzrdir, 
 
390
                name='branch1')
 
391
        except (errors.UninitializableFormat, errors.NoColocatedBranchSupport):
 
392
            # branch references are not default init'able and
 
393
            # not all bzrdirs support colocated branches.
 
394
            return
 
395
        self.assertEquals(1, len(repo.bzrdir.list_branches()))
 
396
        self.branch_format.initialize(repo.bzrdir, name='branch2')
 
397
        self.assertEquals(2, len(repo.bzrdir.list_branches()))
 
398
 
394
399
    def test_create_open_branch_uses_repository(self):
395
400
        try:
396
401
            repo = self.make_repository('.', shared=True)
406
411
            return
407
412
        self.assertEqual(repo.bzrdir.root_transport.base,
408
413
                         child_branch.repository.bzrdir.root_transport.base)
409
 
        child_branch = branch.Branch.open(self.get_url('child'))
 
414
        child_branch = _mod_branch.Branch.open(self.get_url('child'))
410
415
        self.assertEqual(repo.bzrdir.root_transport.base,
411
416
                         child_branch.repository.bzrdir.root_transport.base)
412
417
 
435
440
    def test_generate_revision_history_NULL_REVISION(self):
436
441
        tree = self.make_branch_and_tree('.')
437
442
        rev1 = tree.commit('foo')
438
 
        tree.branch.generate_revision_history(bzrlib.revision.NULL_REVISION)
 
443
        tree.branch.generate_revision_history(revision.NULL_REVISION)
439
444
        self.assertEqual([], tree.branch.revision_history())
440
445
 
441
446
    def test_create_checkout(self):
453
458
        self.assertEqual('rev2', branch_a.last_revision())
454
459
        self.assertEqual(checkout_c.branch.base, branch_a.base)
455
460
 
456
 
        os.mkdir('d')
457
461
        checkout_d = branch_a.create_checkout('d', lightweight=True)
458
462
        self.assertEqual('rev2', checkout_d.last_revision())
459
 
        os.mkdir('e')
460
463
        checkout_e = branch_a.create_checkout('e')
461
464
        self.assertEqual('rev2', checkout_e.last_revision())
462
465
 
465
468
        tree_a = self.make_branch_and_tree('a')
466
469
        rev_id = tree_a.commit('put some content in the branch')
467
470
        # open the branch via a readonly transport
468
 
        source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
 
471
        source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
469
472
        # sanity check that the test will be valid
470
473
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
471
474
            source_branch.lock_write)
477
480
        tree_a = self.make_branch_and_tree('a')
478
481
        rev_id = tree_a.commit('put some content in the branch')
479
482
        # open the branch via a readonly transport
480
 
        source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
 
483
        source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
481
484
        # sanity check that the test will be valid
482
485
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
483
486
            source_branch.lock_write)
494
497
        self.assertEquals(br.revision_history(), [])
495
498
 
496
499
 
497
 
class TestBranchFormat(TestCaseWithBranch):
 
500
class TestBranchFormat(per_branch.TestCaseWithBranch):
498
501
 
499
502
    def test_branch_format_network_name(self):
500
503
        br = self.make_branch('.')
511
514
            real_branch = br._real_branch
512
515
            self.assertEqual(real_branch._format.network_name(), network_name)
513
516
        else:
514
 
            registry = branch.network_format_registry
 
517
            registry = _mod_branch.network_format_registry
515
518
            looked_up_format = registry.get(network_name)
516
519
            self.assertEqual(format.__class__, looked_up_format.__class__)
517
520
 
518
521
 
519
 
class ChrootedTests(TestCaseWithBranch):
 
522
class ChrootedTests(per_branch.TestCaseWithBranch):
520
523
    """A support class that provides readonly urls outside the local namespace.
521
524
 
522
525
    This is done by checking if self.transport_server is a MemoryServer. if it
526
529
 
527
530
    def setUp(self):
528
531
        super(ChrootedTests, self).setUp()
529
 
        if not self.vfs_transport_factory == MemoryServer:
 
532
        if not self.vfs_transport_factory == memory.MemoryServer:
530
533
            self.transport_readonly_server = HttpServer
531
534
 
532
535
    def test_open_containing(self):
533
 
        self.assertRaises(NotBranchError, Branch.open_containing,
 
536
        self.assertRaises(errors.NotBranchError,
 
537
                          _mod_branch.Branch.open_containing,
534
538
                          self.get_readonly_url(''))
535
 
        self.assertRaises(NotBranchError, Branch.open_containing,
 
539
        self.assertRaises(errors.NotBranchError,
 
540
                          _mod_branch.Branch.open_containing,
536
541
                          self.get_readonly_url('g/p/q'))
537
542
        branch = self.make_branch('.')
538
 
        branch, relpath = Branch.open_containing(self.get_readonly_url(''))
 
543
        branch, relpath = _mod_branch.Branch.open_containing(
 
544
            self.get_readonly_url(''))
539
545
        self.assertEqual('', relpath)
540
 
        branch, relpath = Branch.open_containing(self.get_readonly_url('g/p/q'))
 
546
        branch, relpath = _mod_branch.Branch.open_containing(
 
547
            self.get_readonly_url('g/p/q'))
541
548
        self.assertEqual('g/p/q', relpath)
542
549
 
543
550
 
564
571
    def unlock(self):
565
572
        self._calls.append('ul')
566
573
 
567
 
    @needs_read_lock
 
574
    @_mod_branch.needs_read_lock
568
575
    def do_with_read(self):
569
576
        return 1
570
577
 
571
 
    @needs_read_lock
 
578
    @_mod_branch.needs_read_lock
572
579
    def except_with_read(self):
573
580
        raise RuntimeError
574
581
 
575
 
    @needs_write_lock
 
582
    @_mod_branch.needs_write_lock
576
583
    def do_with_write(self):
577
584
        return 2
578
585
 
579
 
    @needs_write_lock
 
586
    @_mod_branch.needs_write_lock
580
587
    def except_with_write(self):
581
588
        raise RuntimeError
582
589
 
583
590
 
584
 
class TestDecorators(TestCase):
 
591
class TestDecorators(tests.TestCase):
585
592
 
586
593
    def test_needs_read_lock(self):
587
594
        branch = TestDecorator()
604
611
        self.assertEqual(['lw', 'ul'], branch._calls)
605
612
 
606
613
 
607
 
class TestBranchPushLocations(TestCaseWithBranch):
 
614
class TestBranchPushLocations(per_branch.TestCaseWithBranch):
608
615
 
609
616
    def test_get_push_location_unset(self):
610
617
        self.assertEqual(None, self.get_branch().get_push_location())
625
632
        self.assertEqual('foo', branch.get_push_location())
626
633
 
627
634
 
628
 
class TestChildSubmitFormats(TestCaseWithBranch):
 
635
class TestChildSubmitFormats(per_branch.TestCaseWithBranch):
629
636
 
630
637
    def test_get_child_submit_format_default(self):
631
638
        self.assertEqual(None, self.get_branch().get_child_submit_format())
637
644
        self.assertEqual('10', branch.get_child_submit_format())
638
645
 
639
646
 
640
 
class TestFormat(TestCaseWithBranch):
 
647
class TestFormat(per_branch.TestCaseWithBranch):
641
648
    """Tests for the format itself."""
642
649
 
643
650
    def test_get_reference(self):
661
668
        this_branch = self.make_branch('this')
662
669
        other_branch = self.make_branch('other')
663
670
        try:
664
 
            this_branch._format.set_reference(this_branch.bzrdir, other_branch)
 
671
            this_branch._format.set_reference(this_branch.bzrdir, None,
 
672
                other_branch)
665
673
        except NotImplementedError:
666
674
            # that's ok
667
675
            pass
677
685
            # they may not be initializable.
678
686
            return
679
687
        # supported formats must be able to init and open
680
 
        t = get_transport(self.get_url())
681
 
        readonly_t = get_transport(self.get_readonly_url())
 
688
        t = transport.get_transport(self.get_url())
 
689
        readonly_t = transport.get_transport(self.get_readonly_url())
682
690
        made_branch = self.make_branch('.')
683
 
        self.failUnless(isinstance(made_branch, branch.Branch))
 
691
        self.failUnless(isinstance(made_branch, _mod_branch.Branch))
684
692
 
685
693
        # find it via bzrdir opening:
686
694
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
691
699
                        self.branch_format.__class__))
692
700
 
693
701
        # find it via Branch.open
694
 
        opened_branch = branch.Branch.open(readonly_t.base)
 
702
        opened_branch = _mod_branch.Branch.open(readonly_t.base)
695
703
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
696
704
        self.assertEqual(made_branch._format.__class__,
697
705
                         opened_branch._format.__class__)
704
712
                         opened_control.find_branch_format())
705
713
 
706
714
 
707
 
class TestBound(TestCaseWithBranch):
 
715
class TestBound(per_branch.TestCaseWithBranch):
708
716
 
709
717
    def test_bind_unbind(self):
710
718
        branch = self.make_branch('1')
742
750
            raise tests.TestNotApplicable('Format does not support binding')
743
751
 
744
752
 
745
 
class TestStrict(TestCaseWithBranch):
 
753
class TestStrict(per_branch.TestCaseWithBranch):
746
754
 
747
755
    def test_strict_history(self):
748
756
        tree1 = self.make_branch_and_tree('tree1')
749
757
        try:
750
758
            tree1.branch.set_append_revisions_only(True)
751
759
        except errors.UpgradeRequired:
752
 
            raise TestSkipped('Format does not support strict history')
 
760
            raise tests.TestSkipped('Format does not support strict history')
753
761
        tree1.commit('empty commit')
754
762
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
755
763
        tree2.commit('empty commit 2')
767
775
        tree2.pull(tree3.branch)
768
776
 
769
777
 
770
 
class TestIgnoreFallbacksParameter(TestCaseWithBranch):
 
778
class TestIgnoreFallbacksParameter(per_branch.TestCaseWithBranch):
771
779
 
772
780
    def make_branch_with_fallback(self):
773
781
        fallback = self.make_branch('fallback')
789
797
        self.assertLength(1, reopened.repository._fallback_repositories)
790
798
 
791
799
 
792
 
class TestReferenceLocation(TestCaseWithBranch):
 
800
class TestReferenceLocation(per_branch.TestCaseWithBranch):
793
801
 
794
802
    def test_reference_parent(self):
795
803
        tree = self.make_branch_and_tree('tree')
797
805
        subtree.set_root_id('subtree-id')
798
806
        try:
799
807
            tree.add_reference(subtree)
800
 
        except bzrlib.errors.UnsupportedOperation:
 
808
        except errors.UnsupportedOperation:
801
809
            raise tests.TestNotApplicable('Tree cannot hold references.')
802
810
        reference_parent = tree.branch.reference_parent('subtree-id',
803
811
                                                        'subtree')
809
817
        subtree.set_root_id('subtree-id')
810
818
        try:
811
819
            tree.add_reference(subtree)
812
 
        except bzrlib.errors.UnsupportedOperation:
 
820
        except errors.UnsupportedOperation:
813
821
            raise tests.TestNotApplicable('Tree cannot hold references.')
814
822
        reference_parent = tree.branch.reference_parent('subtree-id',
815
823
            'subtree', possible_transports=[subtree.bzrdir.root_transport])
818
826
        branch = self.make_branch('branch')
819
827
        try:
820
828
            path, loc = branch.get_reference_info('file-id')
821
 
        except bzrlib.errors.UnsupportedOperation:
 
829
        except errors.UnsupportedOperation:
822
830
            raise tests.TestNotApplicable('Branch cannot hold references.')
823
831
        self.assertIs(None, path)
824
832
        self.assertIs(None, loc)
828
836
        try:
829
837
            branch.set_reference_info('file-id', 'path/to/location',
830
838
                                      'path/to/file')
831
 
        except bzrlib.errors.UnsupportedOperation:
 
839
        except errors.UnsupportedOperation:
832
840
            raise tests.TestNotApplicable('Branch cannot hold references.')
833
841
 
834
842
    def test_set_get_reference_info(self):
836
844
        try:
837
845
            branch.set_reference_info('file-id', 'path/to/file',
838
846
                                      'path/to/location')
839
 
        except bzrlib.errors.UnsupportedOperation:
 
847
        except errors.UnsupportedOperation:
840
848
            raise tests.TestNotApplicable('Branch cannot hold references.')
841
849
        # Create a new instance to ensure storage is permanent
842
 
        branch = Branch.open('branch')
 
850
        branch = _mod_branch.Branch.open('branch')
843
851
        tree_path, branch_location = branch.get_reference_info('file-id')
844
852
        self.assertEqual('path/to/location', branch_location)
845
853
 
848
856
        try:
849
857
            branch.set_reference_info('file-id', 'path/to/file',
850
858
                                      'path/to/location')
851
 
        except bzrlib.errors.UnsupportedOperation:
 
859
        except errors.UnsupportedOperation:
852
860
            raise tests.TestNotApplicable('Branch cannot hold references.')
853
861
        branch.set_reference_info('file-id', None, None)
854
862
        tree_path, branch_location = branch.get_reference_info('file-id')
859
867
        branch = self.make_branch('branch')
860
868
        try:
861
869
            tree_path, branch_location = branch.get_reference_info('file-id')
862
 
        except bzrlib.errors.UnsupportedOperation:
 
870
        except errors.UnsupportedOperation:
863
871
            raise tests.TestNotApplicable('Branch cannot hold references.')
864
872
        self.assertIs(None, tree_path)
865
873
        self.assertIs(None, branch_location)
870
878
        try:
871
879
            e = self.assertRaises(ValueError, branch.set_reference_info,
872
880
                                  'file-id', 'path', None)
873
 
        except bzrlib.errors.UnsupportedOperation:
 
881
        except errors.UnsupportedOperation:
874
882
            raise tests.TestNotApplicable('Branch cannot hold references.')
875
883
        self.assertEqual('tree_path must be None when branch_location is'
876
884
                         ' None.', str(e))
885
893
        try:
886
894
            branch.set_reference_info(file_id, 'path/to/file',
887
895
                                      reference_location)
888
 
        except bzrlib.errors.UnsupportedOperation:
 
896
        except errors.UnsupportedOperation:
889
897
            raise tests.TestNotApplicable('Branch cannot hold references.')
890
898
        return branch
891
899
 
901
909
        try:
902
910
            branch.set_reference_info('file-id', 'path/to/file',
903
911
            '../reference_branch')
904
 
        except bzrlib.errors.UnsupportedOperation:
 
912
        except errors.UnsupportedOperation:
905
913
            raise tests.TestNotApplicable('Branch cannot hold references.')
906
914
        referenced_branch = self.make_branch('reference_branch')
907
915
        parent = branch.reference_parent('file-id', 'path/to/file')
981
989
        merger.do_merge()
982
990
        self.assertEqual('../branch/reference',
983
991
                         tree.branch.get_reference_info('file-id')[1])
 
992
 
 
993
 
 
994
class TestBranchControlComponent(per_branch.TestCaseWithBranch):
 
995
    """Branch implementations adequately implement ControlComponent."""
 
996
    
 
997
    def test_urls(self):
 
998
        br = self.make_branch('branch')
 
999
        self.assertIsInstance(br.user_url, str)
 
1000
        self.assertEqual(br.user_url, br.user_transport.base)
 
1001
        # for all current bzrdir implementations the user dir must be 
 
1002
        # above the control dir but we might need to relax that?
 
1003
        self.assertEqual(br.control_url.find(br.user_url), 0)
 
1004
        self.assertEqual(br.control_url, br.control_transport.base)