~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
 
25
25
from bzrlib import (
26
26
    errors,
 
27
    repository,
27
28
    remote,
28
 
    urlutils,
29
29
    )
30
 
from bzrlib.controldir import ControlDir
 
30
from bzrlib.branch import BzrBranchFormat7
 
31
from bzrlib.bzrdir import BzrDir
 
32
from bzrlib.repofmt.pack_repo import RepositoryFormatKnitPack6
31
33
from bzrlib.tests import multiply_tests
32
34
from bzrlib.tests.per_repository import (
33
35
    all_repository_format_scenarios,
37
39
 
38
40
class TestCaseWithExternalReferenceRepository(TestCaseWithRepository):
39
41
 
40
 
    def make_referring(self, relpath, a_repository):
 
42
    def make_referring(self, relpath, target_path):
41
43
        """Get a new repository that refers to a_repository.
42
44
 
43
45
        :param relpath: The path to create the repository at.
44
46
        :param a_repository: A repository to refer to.
45
47
        """
46
48
        repo = self.make_repository(relpath)
47
 
        repo.add_fallback_repository(self.readonly_repository(a_repository))
 
49
        repo.add_fallback_repository(self.readonly_repository(target_path))
48
50
        return repo
49
51
 
50
 
    def readonly_repository(self, repo):
51
 
        relpath = urlutils.basename(repo.bzrdir.user_url.rstrip('/'))
52
 
        return ControlDir.open_from_transport(
 
52
    def readonly_repository(self, relpath):
 
53
        return BzrDir.open_from_transport(
53
54
            self.get_readonly_transport(relpath)).open_repository()
54
55
 
55
56
 
60
61
        # because developers use this api to setup the tree, branch and
61
62
        # repository for their tests: having it not give the right repository
62
63
        # type would invalidate the tests.
63
 
        tree = self.make_branch_and_tree('repo')
64
 
        repo = self.make_referring('referring', tree.branch.repository)
 
64
        self.make_branch_and_tree('repo')
 
65
        repo = self.make_referring('referring', 'repo')
65
66
        self.assertIsInstance(repo._format,
66
67
            self.repository_format.__class__)
67
68
 
68
69
 
69
70
class TestIncompatibleStacking(TestCaseWithRepository):
70
71
 
71
 
    def make_repo_and_incompatible_fallback(self):
72
 
        referring = self.make_repository('referring')
73
 
        if referring._format.supports_chks:
 
72
    def test_add_fallback_repository_rejects_incompatible(self):
 
73
        # Repository.add_fallback_repository raises IncompatibleRepositories if
 
74
        # you take two repositories in different serializations and try to
 
75
        # stack them.
 
76
        if self.make_repository('test')._format.supports_chks:
74
77
            different_fmt = '1.9'
75
78
        else:
76
79
            different_fmt = '2a'
77
 
        fallback = self.make_repository('fallback', format=different_fmt)
78
 
        return referring, fallback
79
 
 
80
 
    def test_add_fallback_repository_rejects_incompatible(self):
81
 
        # Repository.add_fallback_repository raises IncompatibleRepositories
82
 
        # if you take two repositories in different serializations and try to
83
 
        # stack them.
84
 
        referring, fallback = self.make_repo_and_incompatible_fallback()
85
 
        self.assertRaises(errors.IncompatibleRepositories,
86
 
                referring.add_fallback_repository, fallback)
87
 
 
88
 
    def test_add_fallback_doesnt_leave_fallback_locked(self):
89
 
        # Bug #835035. If the referring repository is locked, it wants to lock
90
 
        # the fallback repository. But if they are incompatible, the referring
91
 
        # repository won't take ownership of the fallback, and thus should not
92
 
        # leave the repository in a locked state.
93
 
        referring, fallback = self.make_repo_and_incompatible_fallback()
94
 
        self.addCleanup(referring.lock_read().unlock)
95
 
        # Assert precondition.
96
 
        self.assertFalse(fallback.is_locked())
97
 
        # Assert action.
98
 
        self.assertRaises(errors.IncompatibleRepositories,
99
 
                referring.add_fallback_repository, fallback)
100
 
        # Assert postcondition.
101
 
        self.assertFalse(fallback.is_locked())
 
80
        repo = self.make_repository('repo', format=different_fmt)
 
81
        referring = self.make_repository('referring')
 
82
        self.assertRaises(errors.IncompatibleRepositories,
 
83
                referring.add_fallback_repository, repo)
102
84
 
103
85
 
104
86
def external_reference_test_scenarios():
107
89
    result = []
108
90
    for test_name, scenario_info in all_repository_format_scenarios():
109
91
        format = scenario_info['repository_format']
110
 
        if (isinstance(format, remote.RemoteRepositoryFormat)
111
 
            or format.supports_external_lookups):
 
92
        if isinstance(format, remote.RemoteRepositoryFormat):
 
93
            # This is a RemoteRepositoryFormat scenario.  Force the scenario to
 
94
            # use real branch and repository formats that support references.
 
95
            scenario_info = dict(scenario_info)
 
96
            format = remote.RemoteRepositoryFormat()
 
97
            format._custom_format = RepositoryFormatKnitPack6()
 
98
            scenario_info['repository_format'] = format
 
99
            bzrdir_format = remote.RemoteBzrDirFormat()
 
100
            bzrdir_format.repository_format = format
 
101
            bzrdir_format.set_branch_format(BzrBranchFormat7())
 
102
            scenario_info['bzrdir_format'] = bzrdir_format
 
103
        if format.supports_external_lookups:
112
104
            result.append((test_name, scenario_info))
113
105
    return result
114
106
 
121
113
        'bzrlib.tests.per_repository_reference.test_all_revision_ids',
122
114
        'bzrlib.tests.per_repository_reference.test_break_lock',
123
115
        'bzrlib.tests.per_repository_reference.test_check',
124
 
        'bzrlib.tests.per_repository_reference.test_commit_with_stacking',
125
116
        'bzrlib.tests.per_repository_reference.test_default_stacking',
126
117
        'bzrlib.tests.per_repository_reference.test_fetch',
127
118
        'bzrlib.tests.per_repository_reference.test_get_record_stream',
128
119
        'bzrlib.tests.per_repository_reference.test_get_rev_id_for_revno',
129
 
        'bzrlib.tests.per_repository_reference.test_graph',
130
120
        'bzrlib.tests.per_repository_reference.test_initialize',
131
 
        'bzrlib.tests.per_repository_reference.test__make_parents_provider',
132
121
        'bzrlib.tests.per_repository_reference.test_unlock',
133
122
        ]
134
123
    # Parameterize per_repository_reference test modules by format.