~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

  • Committer: Aaron Bentley
  • Date: 2009-04-08 20:46:27 UTC
  • mto: This revision was merged to the branch mainline in revision 4302.
  • Revision ID: aaron@aaronbentley.com-20090408204627-m4gbzrc255mhtjtu
Implement branch format for tree references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
769
769
        self.get_transport('').rename('fallback', 'moved')
770
770
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
771
771
        self.assertEqual([], reopened.repository._fallback_repositories)
772
 
        
 
772
 
773
773
    def test_fallbacks_are_opened(self):
774
774
        stacked = self.make_branch_with_fallback()
775
775
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
776
776
        self.assertLength(1, reopened.repository._fallback_repositories)
 
777
 
 
778
 
 
779
class TestReferenceLocation(TestCaseWithBranch):
 
780
 
 
781
    def test_reference_parent(self):
 
782
        tree = self.make_branch_and_tree('tree')
 
783
        subtree = self.make_branch_and_tree('tree/subtree')
 
784
        subtree.set_root_id('subtree-id')
 
785
        try:
 
786
            tree.add_reference(subtree)
 
787
        except bzrlib.errors.UnsupportedOperation:
 
788
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
789
        reference_parent = tree.branch.reference_parent('subtree-id',
 
790
                                                        'subtree')
 
791
        self.assertEqual(subtree.branch.base, reference_parent.base)
 
792
 
 
793
    def test_get_reference_info(self):
 
794
        branch = self.make_branch('branch')
 
795
        try:
 
796
            path, loc = branch.get_reference_info('file-id')
 
797
        except bzrlib.errors.UnsupportedOperation:
 
798
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
799
        self.assertIs(None, path)
 
800
        self.assertIs(None, loc)
 
801
 
 
802
    def test_set_reference_info(self):
 
803
        branch = self.make_branch('branch')
 
804
        try:
 
805
            branch.set_reference_info('file-id', 'path/to/location',
 
806
                                      'path/to/file')
 
807
        except bzrlib.errors.UnsupportedOperation:
 
808
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
809
 
 
810
    def test_set_get_reference_info(self):
 
811
        branch = self.make_branch('branch')
 
812
        try:
 
813
            branch.set_reference_info('file-id', 'path/to/file',
 
814
                                      'path/to/location')
 
815
        except bzrlib.errors.UnsupportedOperation:
 
816
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
817
        # Create a new instance to ensure storage is permanent
 
818
        branch = Branch.open('branch')
 
819
        tree_path, branch_location = branch.get_reference_info('file-id')
 
820
        self.assertEqual('path/to/location', branch_location)
 
821
 
 
822
    def test_set_null_reference_info(self):
 
823
        branch = self.make_branch('branch')
 
824
        try:
 
825
            branch.set_reference_info('file-id', 'path/to/file',
 
826
                                      'path/to/location')
 
827
        except bzrlib.errors.UnsupportedOperation:
 
828
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
829
        branch.set_reference_info('file-id', None, None)
 
830
        tree_path, branch_location = branch.get_reference_info('file-id')
 
831
        self.assertIs(None, tree_path)
 
832
        self.assertIs(None, branch_location)
 
833
 
 
834
    def test_set_null_reference_info_when_null(self):
 
835
        branch = self.make_branch('branch')
 
836
        try:
 
837
            tree_path, branch_location = branch.get_reference_info('file-id')
 
838
        except bzrlib.errors.UnsupportedOperation:
 
839
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
840
        self.assertIs(None, tree_path)
 
841
        self.assertIs(None, branch_location)
 
842
        branch.set_reference_info('file-id', None, None)
 
843
 
 
844
    def test_set_null_requires_two_nones(self):
 
845
        branch = self.make_branch('branch')
 
846
        try:
 
847
            e = self.assertRaises(ValueError, branch.set_reference_info,
 
848
                                  'file-id', 'path', None)
 
849
        except bzrlib.errors.UnsupportedOperation:
 
850
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
851
        self.assertEqual('tree_path must be None when branch_location is'
 
852
                         ' None.', str(e))
 
853
        e = self.assertRaises(ValueError, branch.set_reference_info,
 
854
                              'file-id', None, 'location')
 
855
        self.assertEqual('branch_location must be None when tree_path is'
 
856
                         ' None.', str(e))