/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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
20
    controldir,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
21
    transport,
22
    )
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
23
from breezy.bzr.remote import (
5741.2.1 by Jelmer Vernooij
Avoid the use of Repository._transport.
24
    RemoteRepositoryFormat,
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.tests import (
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
27
    TestNotApplicable,
28
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
29
from breezy.tests.per_repository import TestCaseWithRepository
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
30
31
32
class TestHasSameLocation(TestCaseWithRepository):
33
    """Tests for Repository.has_same_location method."""
34
35
    def assertSameRepo(self, a, b):
36
        """Asserts that two objects are the same repository.
37
38
        This method does the comparison both ways (`a.has_same_location(b)` as
39
        well as `b.has_same_location(a)`) to make sure both objects'
40
        `has_same_location` methods give the same results.
41
        """
42
        self.assertTrue(a.has_same_location(b),
43
                        "%r is not the same repository as %r" % (a, b))
44
        self.assertTrue(b.has_same_location(a),
45
                        "%r is the same as %r, but not vice versa" % (a, b))
46
47
    def assertDifferentRepo(self, a, b):
48
        """Asserts that two objects are the not same repository.
49
50
        This method does the comparison both ways (`a.has_same_location(b)` as
51
        well as `b.has_same_location(a)`) to make sure both objects'
52
        `has_same_location` methods give the same results.
53
54
        :seealso: assertDifferentRepo
55
        """
56
        self.assertFalse(a.has_same_location(b),
57
                         "%r is not the same repository as %r" % (a, b))
58
        self.assertFalse(b.has_same_location(a),
59
                         "%r is the same as %r, but not vice versa" % (a, b))
60
61
    def test_same_repo_instance(self):
62
        """A repository object is the same repository as itself."""
63
        repo = self.make_repository('.')
64
        self.assertSameRepo(repo, repo)
65
66
    def test_same_repo_location(self):
67
        """Different repository objects for the same location are the same."""
68
        repo = self.make_repository('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
69
        reopened_repo = repo.controldir.open_repository()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
70
        self.assertFalse(
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
71
            repo is reopened_repo,
72
            "This test depends on reopened_repo being a different instance of "
73
            "the same repo.")
74
        self.assertSameRepo(repo, reopened_repo)
75
76
    def test_different_repos_not_equal(self):
77
        """Repositories at different locations are not the same."""
78
        repo_one = self.make_repository('one')
79
        repo_two = self.make_repository('two')
80
        self.assertDifferentRepo(repo_one, repo_two)
81
82
    def test_same_bzrdir_different_control_files_not_equal(self):
83
        """Repositories in the same bzrdir, but with different control files,
84
        are not the same.
85
86
        This can happens e.g. when upgrading a repository.  This test mimics how
87
        CopyConverter creates a second repository in one bzrdir.
88
        """
89
        repo = self.make_repository('repo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
90
        if repo.control_transport.base == repo.controldir.control_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.
5741.2.1 by Jelmer Vernooij
Avoid the use of Repository._transport.
97
        repo.control_transport.copy_tree('.', '../repository.backup')
98
        backup_transport = repo.control_transport.clone('../repository.backup')
99
        if isinstance(repo._format, RemoteRepositoryFormat):
100
            raise TestNotApplicable("remote repositories don't support overriding "
101
                                    "transport")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
102
        backup_repo = repo._format.open(repo.controldir,
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
103
                                        _override_transport=backup_transport)
104
        self.assertDifferentRepo(repo, backup_repo)
105
106
    def test_different_format_not_equal(self):
107
        """Different format repositories are comparable and not the same.
108
109
        Comparing different format repository objects should give a negative
110
        result, rather than trigger an exception (which could happen with a
111
        naive __eq__ implementation, e.g. due to missing attributes).
112
        """
113
        repo = self.make_repository('repo')
114
        other_repo = self.make_repository('other', format='default')
115
        if repo._format == other_repo._format:
116
            # We're testing the default format!  So we have to use a non-default
117
            # format for other_repo.
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
118
            transport.get_transport_from_url(
119
                self.get_vfs_only_url()).delete_tree('other')
5582.10.96 by Jelmer Vernooij
Support running without plugins.
120
            other_repo = self.make_repository('other', format='knit')
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
121
        # Make sure the other_repo is not a RemoteRepository.
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
122
        other_bzrdir = controldir.ControlDir.open(self.get_vfs_only_url('other'))
2671.1.5 by Andrew Bennetts
Move has_same_location tests to a new file.
123
        other_repo = other_bzrdir.open_repository()
124
        self.assertDifferentRepo(repo, other_repo)
125
126