/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1
# Copyright (C) 2007-2010 Canonical Ltd
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
16
17
"""Tests for implementations of Repository.has_same_location."""
18
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
19
from bzrlib import (
20
    bzrdir,
21
    transport,
22
    )
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
23
from bzrlib.tests import (
24
    TestNotApplicable,
25
    )
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
26
from bzrlib.tests.per_repository import TestCaseWithRepository
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
27
28
29
class TestHasSameLocation(TestCaseWithRepository):
30
    """Tests for Repository.has_same_location method."""
31
32
    def assertSameRepo(self, a, b):
33
        """Asserts that two objects are the same repository.
34
35
        This method does the comparison both ways (`a.has_same_location(b)` as
36
        well as `b.has_same_location(a)`) to make sure both objects'
37
        `has_same_location` methods give the same results.
38
        """
39
        self.assertTrue(a.has_same_location(b),
40
                        "%r is not the same repository as %r" % (a, b))
41
        self.assertTrue(b.has_same_location(a),
42
                        "%r is the same as %r, but not vice versa" % (a, b))
43
44
    def assertDifferentRepo(self, a, b):
45
        """Asserts that two objects are the not same repository.
46
47
        This method does the comparison both ways (`a.has_same_location(b)` as
48
        well as `b.has_same_location(a)`) to make sure both objects'
49
        `has_same_location` methods give the same results.
50
51
        :seealso: assertDifferentRepo
52
        """
53
        self.assertFalse(a.has_same_location(b),
54
                         "%r is not the same repository as %r" % (a, b))
55
        self.assertFalse(b.has_same_location(a),
56
                         "%r is the same as %r, but not vice versa" % (a, b))
57
58
    def test_same_repo_instance(self):
59
        """A repository object is the same repository as itself."""
60
        repo = self.make_repository('.')
61
        self.assertSameRepo(repo, repo)
62
63
    def test_same_repo_location(self):
64
        """Different repository objects for the same location are the same."""
65
        repo = self.make_repository('.')
66
        reopened_repo = repo.bzrdir.open_repository()
67
        self.failIf(
68
            repo is reopened_repo,
69
            "This test depends on reopened_repo being a different instance of "
70
            "the same repo.")
71
        self.assertSameRepo(repo, reopened_repo)
72
73
    def test_different_repos_not_equal(self):
74
        """Repositories at different locations are not the same."""
75
        repo_one = self.make_repository('one')
76
        repo_two = self.make_repository('two')
77
        self.assertDifferentRepo(repo_one, repo_two)
78
79
    def test_same_bzrdir_different_control_files_not_equal(self):
80
        """Repositories in the same bzrdir, but with different control files,
81
        are not the same.
82
83
        This can happens e.g. when upgrading a repository.  This test mimics how
84
        CopyConverter creates a second repository in one bzrdir.
85
        """
86
        repo = self.make_repository('repo')
87
        try:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
88
            control_transport = repo._transport
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
89
        except AttributeError:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
90
            raise TestNotApplicable(
91
                "%r has no transport" % (repo,))
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
92
        if control_transport.base == repo.bzrdir.transport.base:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
93
            raise TestNotApplicable(
94
                "%r has repository files directly in the bzrdir"
95
                % (repo,))
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
96
            # This test only applies to repository formats where the repo
97
            # control_files are separate from other bzrdir files, i.e. metadir
98
            # formats.
99
        control_transport.copy_tree('.', '../repository.backup')
100
        backup_transport = control_transport.clone('../repository.backup')
101
        backup_repo = repo._format.open(repo.bzrdir, _found=True,
102
                                        _override_transport=backup_transport)
103
        self.assertDifferentRepo(repo, backup_repo)
104
105
    def test_different_format_not_equal(self):
106
        """Different format repositories are comparable and not the same.
107
108
        Comparing different format repository objects should give a negative
109
        result, rather than trigger an exception (which could happen with a
110
        naive __eq__ implementation, e.g. due to missing attributes).
111
        """
112
        repo = self.make_repository('repo')
113
        other_repo = self.make_repository('other', format='default')
114
        if repo._format == other_repo._format:
115
            # We're testing the default format!  So we have to use a non-default
116
            # format for other_repo.
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
117
            transport.get_transport(self.get_vfs_only_url()
118
                                    ).delete_tree('other')
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
119
            other_repo = self.make_repository('other', format='metaweave')
120
        # Make sure the other_repo is not a RemoteRepository.
121
        other_bzrdir = bzrdir.BzrDir.open(self.get_vfs_only_url('other'))
122
        other_repo = other_bzrdir.open_repository()
123
        self.assertDifferentRepo(repo, other_repo)
124
125