/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository_reference/__init__.py

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 Canonical Ltd
 
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
 
 
18
"""Repository implementation tests for external reference repositories.
 
19
 
 
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.
 
23
"""
 
24
 
 
25
from bzrlib import (
 
26
    repository,
 
27
    remote,
 
28
    )
 
29
from bzrlib.bzrdir import BzrDir
 
30
from bzrlib.tests import (
 
31
                          adapt_modules,
 
32
                          adapt_tests,
 
33
                          TestScenarioApplier,
 
34
                          TestSuite,
 
35
                          )
 
36
from bzrlib.tests.repository_implementations import (
 
37
    all_repository_format_scenarios,
 
38
    TestCaseWithRepository,
 
39
    )
 
40
 
 
41
 
 
42
class TestCaseWithExternalReferenceRepository(TestCaseWithRepository):
 
43
 
 
44
    def make_referring(self, relpath, target_path):
 
45
        """Get a new repository that refers to a_repository.
 
46
        
 
47
        :param relpath: The path to create the repository at.
 
48
        :param a_repository: A repository to refer to.
 
49
        """
 
50
        repo = self.make_repository(relpath)
 
51
        repo.add_fallback_repository(self.readonly_repository(target_path))
 
52
        return repo
 
53
 
 
54
    def readonly_repository(self, relpath):
 
55
        return BzrDir.open_from_transport(
 
56
            self.get_readonly_transport(relpath)).open_repository()
 
57
 
 
58
 
 
59
class TestCorrectFormat(TestCaseWithExternalReferenceRepository):
 
60
 
 
61
    def test_repository_format(self):
 
62
        # make sure the repository on tree.branch is of the desired format,
 
63
        # because developers use this api to setup the tree, branch and 
 
64
        # repository for their tests: having it not give the right repository
 
65
        # type would invalidate the tests.
 
66
        self.make_branch_and_tree('repo')
 
67
        repo = self.make_referring('referring', 'repo')
 
68
        self.assertIsInstance(repo._format,
 
69
            self.repository_format.__class__)
 
70
 
 
71
 
 
72
def external_reference_test_scenarios():
 
73
    """Generate test scenarios for repositories supporting external references.
 
74
    """
 
75
    result = []
 
76
    for test_name, scenario_info in all_repository_format_scenarios():
 
77
        # For remote repositories, we need at least one external reference
 
78
        # capable format to test it: defer this until landing such a format.
 
79
        # if isinstance(format, remote.RemoteRepositoryFormat):
 
80
        #     scenario[1]['bzrdir_format'].repository_format = 
 
81
        if scenario_info['repository_format'].supports_external_lookups:
 
82
            result.append((test_name, scenario_info))
 
83
    return result
 
84
 
 
85
 
 
86
def load_tests(standard_tests, module, loader):
 
87
    adapter = TestScenarioApplier()
 
88
    adapter.scenarios = external_reference_test_scenarios()
 
89
 
 
90
    module_list = [
 
91
        'bzrlib.tests.per_repository_reference.test_add_inventory',
 
92
        'bzrlib.tests.per_repository_reference.test_add_revision',
 
93
        'bzrlib.tests.per_repository_reference.test_add_signature_text',
 
94
        'bzrlib.tests.per_repository_reference.test_all_revision_ids',
 
95
        'bzrlib.tests.per_repository_reference.test_break_lock',
 
96
        'bzrlib.tests.per_repository_reference.test_check',
 
97
        ]
 
98
    # Parameterize repository_implementations test modules by format.
 
99
    result = TestSuite()
 
100
    adapt_tests(standard_tests, adapter, result)
 
101
    adapt_modules(module_list, adapter, loader, result)
 
102
    return result