/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.8 by John Arbash Meinel
Switch the per-repository-reference code to use the default format for the repository.
1
# Copyright (C) 2008-2011 Canonical Ltd
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
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
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
16
17
18
"""Repository implementation tests for external reference repositories.
19
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
20
These tests check the conformance of repositories which refer to other
21
repositories for some data, and are run for each repository format supporting
22
this.
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
23
"""
24
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy import (
5158.4.1 by Andrew Bennetts
Don't allow RemoteRepository to stack on incompatible formats.
26
    errors,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
27
    urlutils,
28
    )
29
from breezy.bzr import (
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
30
    remote,
31
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
32
from breezy.controldir import ControlDir
33
from breezy.tests import multiply_tests
34
from breezy.tests.per_repository import (
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
35
    all_repository_format_scenarios,
36
    TestCaseWithRepository,
37
    )
38
39
40
class TestCaseWithExternalReferenceRepository(TestCaseWithRepository):
41
6182.1.5 by Jelmer Vernooij
Fix more tests.
42
    def make_referring(self, relpath, a_repository):
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
43
        """Get a new repository that refers to a_repository.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
44
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
45
        :param relpath: The path to create the repository at.
46
        :param a_repository: A repository to refer to.
47
        """
48
        repo = self.make_repository(relpath)
6182.1.5 by Jelmer Vernooij
Fix more tests.
49
        repo.add_fallback_repository(self.readonly_repository(a_repository))
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
50
        return repo
51
6182.1.5 by Jelmer Vernooij
Fix more tests.
52
    def readonly_repository(self, repo):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
53
        relpath = urlutils.basename(repo.controldir.user_url.rstrip('/'))
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
54
        return ControlDir.open_from_transport(
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
55
            self.get_readonly_transport(relpath)).open_repository()
56
57
58
class TestCorrectFormat(TestCaseWithExternalReferenceRepository):
59
60
    def test_repository_format(self):
61
        # make sure the repository on tree.branch is of the desired format,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
62
        # because developers use this api to setup the tree, branch and
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
63
        # repository for their tests: having it not give the right repository
64
        # type would invalidate the tests.
6182.1.5 by Jelmer Vernooij
Fix more tests.
65
        tree = self.make_branch_and_tree('repo')
66
        repo = self.make_referring('referring', tree.branch.repository)
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
67
        self.assertIsInstance(repo._format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
                              self.repository_format.__class__)
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
69
70
5158.4.1 by Andrew Bennetts
Don't allow RemoteRepository to stack on incompatible formats.
71
class TestIncompatibleStacking(TestCaseWithRepository):
72
5609.55.2 by John Arbash Meinel
Tweak the tests a bit more.
73
    def make_repo_and_incompatible_fallback(self):
5609.55.1 by John Arbash Meinel
Merge Gary's update, tweak the test a little bit.
74
        referring = self.make_repository('referring')
75
        if referring._format.supports_chks:
5158.4.1 by Andrew Bennetts
Don't allow RemoteRepository to stack on incompatible formats.
76
            different_fmt = '1.9'
77
        else:
78
            different_fmt = '2a'
5609.55.2 by John Arbash Meinel
Tweak the tests a bit more.
79
        fallback = self.make_repository('fallback', format=different_fmt)
80
        return referring, fallback
81
82
    def test_add_fallback_repository_rejects_incompatible(self):
83
        # Repository.add_fallback_repository raises IncompatibleRepositories
84
        # if you take two repositories in different serializations and try to
85
        # stack them.
86
        referring, fallback = self.make_repo_and_incompatible_fallback()
87
        self.assertRaises(errors.IncompatibleRepositories,
7143.15.2 by Jelmer Vernooij
Run autopep8.
88
                          referring.add_fallback_repository, fallback)
5609.55.2 by John Arbash Meinel
Tweak the tests a bit more.
89
90
    def test_add_fallback_doesnt_leave_fallback_locked(self):
91
        # Bug #835035. If the referring repository is locked, it wants to lock
92
        # the fallback repository. But if they are incompatible, the referring
93
        # repository won't take ownership of the fallback, and thus should not
94
        # leave the repository in a locked state.
95
        referring, fallback = self.make_repo_and_incompatible_fallback()
96
        self.addCleanup(referring.lock_read().unlock)
5609.54.2 by Gary Poster
update previous commit to use existing test, which does not run the tests too many times
97
        # Assert precondition.
5609.55.2 by John Arbash Meinel
Tweak the tests a bit more.
98
        self.assertFalse(fallback.is_locked())
5609.54.2 by Gary Poster
update previous commit to use existing test, which does not run the tests too many times
99
        # Assert action.
5158.4.1 by Andrew Bennetts
Don't allow RemoteRepository to stack on incompatible formats.
100
        self.assertRaises(errors.IncompatibleRepositories,
7143.15.2 by Jelmer Vernooij
Run autopep8.
101
                          referring.add_fallback_repository, fallback)
5609.54.2 by Gary Poster
update previous commit to use existing test, which does not run the tests too many times
102
        # Assert postcondition.
5609.55.2 by John Arbash Meinel
Tweak the tests a bit more.
103
        self.assertFalse(fallback.is_locked())
5158.4.1 by Andrew Bennetts
Don't allow RemoteRepository to stack on incompatible formats.
104
105
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
106
def external_reference_test_scenarios():
107
    """Generate test scenarios for repositories supporting external references.
108
    """
109
    result = []
110
    for test_name, scenario_info in all_repository_format_scenarios():
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
111
        format = scenario_info['repository_format']
5557.1.8 by John Arbash Meinel
Switch the per-repository-reference code to use the default format for the repository.
112
        if (isinstance(format, remote.RemoteRepositoryFormat)
7143.15.2 by Jelmer Vernooij
Run autopep8.
113
                or format.supports_external_lookups):
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
114
            result.append((test_name, scenario_info))
115
    return result
116
117
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
118
def load_tests(loader, standard_tests, pattern):
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
119
    module_list = [
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
120
        'breezy.tests.per_repository_reference.test_add_inventory',
121
        'breezy.tests.per_repository_reference.test_add_revision',
122
        'breezy.tests.per_repository_reference.test_add_signature_text',
123
        'breezy.tests.per_repository_reference.test_all_revision_ids',
124
        'breezy.tests.per_repository_reference.test_break_lock',
125
        'breezy.tests.per_repository_reference.test_check',
126
        'breezy.tests.per_repository_reference.test_commit_with_stacking',
127
        'breezy.tests.per_repository_reference.test_default_stacking',
128
        'breezy.tests.per_repository_reference.test_fetch',
129
        'breezy.tests.per_repository_reference.test_get_record_stream',
130
        'breezy.tests.per_repository_reference.test_get_rev_id_for_revno',
131
        'breezy.tests.per_repository_reference.test_graph',
132
        'breezy.tests.per_repository_reference.test_initialize',
133
        'breezy.tests.per_repository_reference.test__make_parents_provider',
134
        'breezy.tests.per_repository_reference.test_unlock',
3221.10.1 by Robert Collins
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
135
        ]
3689.1.4 by John Arbash Meinel
Doc strings that reference repository_implementations
136
    # Parameterize per_repository_reference test modules by format.
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
137
    standard_tests.addTests(loader.loadTestsFromModuleNames(module_list))
138
    return multiply_tests(standard_tests, external_reference_test_scenarios(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
139
                          loader.suiteClass())