/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
1
# Copyright (C) 2007, 2008 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for implementations of Repository.has_same_location."""
18
19
from bzrlib import bzrdir
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
20
from bzrlib.tests import (
21
    TestNotApplicable,
22
    )
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
23
from bzrlib.tests.repository_implementations import TestCaseWithRepository
24
from bzrlib.transport import get_transport
25
26
27
class TestHasSameLocation(TestCaseWithRepository):
28
    """Tests for Repository.has_same_location method."""
29
30
    def assertSameRepo(self, a, b):
31
        """Asserts that two objects are the same repository.
32
33
        This method does the comparison both ways (`a.has_same_location(b)` as
34
        well as `b.has_same_location(a)`) to make sure both objects'
35
        `has_same_location` methods give the same results.
36
        """
37
        self.assertTrue(a.has_same_location(b),
38
                        "%r is not the same repository as %r" % (a, b))
39
        self.assertTrue(b.has_same_location(a),
40
                        "%r is the same as %r, but not vice versa" % (a, b))
41
42
    def assertDifferentRepo(self, a, b):
43
        """Asserts that two objects are the not same repository.
44
45
        This method does the comparison both ways (`a.has_same_location(b)` as
46
        well as `b.has_same_location(a)`) to make sure both objects'
47
        `has_same_location` methods give the same results.
48
49
        :seealso: assertDifferentRepo
50
        """
51
        self.assertFalse(a.has_same_location(b),
52
                         "%r is not the same repository as %r" % (a, b))
53
        self.assertFalse(b.has_same_location(a),
54
                         "%r is the same as %r, but not vice versa" % (a, b))
55
56
    def test_same_repo_instance(self):
57
        """A repository object is the same repository as itself."""
58
        repo = self.make_repository('.')
59
        self.assertSameRepo(repo, repo)
60
61
    def test_same_repo_location(self):
62
        """Different repository objects for the same location are the same."""
63
        repo = self.make_repository('.')
64
        reopened_repo = repo.bzrdir.open_repository()
65
        self.failIf(
66
            repo is reopened_repo,
67
            "This test depends on reopened_repo being a different instance of "
68
            "the same repo.")
69
        self.assertSameRepo(repo, reopened_repo)
70
71
    def test_different_repos_not_equal(self):
72
        """Repositories at different locations are not the same."""
73
        repo_one = self.make_repository('one')
74
        repo_two = self.make_repository('two')
75
        self.assertDifferentRepo(repo_one, repo_two)
76
77
    def test_same_bzrdir_different_control_files_not_equal(self):
78
        """Repositories in the same bzrdir, but with different control files,
79
        are not the same.
80
81
        This can happens e.g. when upgrading a repository.  This test mimics how
82
        CopyConverter creates a second repository in one bzrdir.
83
        """
84
        repo = self.make_repository('repo')
85
        try:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
86
            control_transport = repo._transport
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
87
        except AttributeError:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
88
            raise TestNotApplicable(
89
                "%r has no transport" % (repo,))
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
90
        if control_transport.base == repo.bzrdir.transport.base:
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
91
            raise TestNotApplicable(
92
                "%r has repository files directly in the bzrdir"
93
                % (repo,))
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
94
            # This test only applies to repository formats where the repo
95
            # control_files are separate from other bzrdir files, i.e. metadir
96
            # formats.
97
        control_transport.copy_tree('.', '../repository.backup')
98
        backup_transport = control_transport.clone('../repository.backup')
99
        backup_repo = repo._format.open(repo.bzrdir, _found=True,
100
                                        _override_transport=backup_transport)
101
        self.assertDifferentRepo(repo, backup_repo)
102
103
    def test_different_format_not_equal(self):
104
        """Different format repositories are comparable and not the same.
105
106
        Comparing different format repository objects should give a negative
107
        result, rather than trigger an exception (which could happen with a
108
        naive __eq__ implementation, e.g. due to missing attributes).
109
        """
110
        repo = self.make_repository('repo')
111
        other_repo = self.make_repository('other', format='default')
112
        if repo._format == other_repo._format:
113
            # We're testing the default format!  So we have to use a non-default
114
            # format for other_repo.
115
            get_transport(self.get_vfs_only_url()).delete_tree('other')
116
            other_repo = self.make_repository('other', format='metaweave')
117
        # Make sure the other_repo is not a RemoteRepository.
118
        other_bzrdir = bzrdir.BzrDir.open(self.get_vfs_only_url('other'))
119
        other_repo = other_bzrdir.open_repository()
120
        self.assertDifferentRepo(repo, other_repo)
121
122