~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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,
28
27
    remote,
 
28
    urlutils,
29
29
    )
30
 
from bzrlib.branch import BzrBranchFormat7
31
 
from bzrlib.bzrdir import BzrDir
32
 
from bzrlib.repofmt.pack_repo import RepositoryFormatKnitPack6
 
30
from bzrlib.controldir import ControlDir
33
31
from bzrlib.tests import multiply_tests
34
32
from bzrlib.tests.per_repository import (
35
33
    all_repository_format_scenarios,
39
37
 
40
38
class TestCaseWithExternalReferenceRepository(TestCaseWithRepository):
41
39
 
42
 
    def make_referring(self, relpath, target_path):
 
40
    def make_referring(self, relpath, a_repository):
43
41
        """Get a new repository that refers to a_repository.
44
42
 
45
43
        :param relpath: The path to create the repository at.
46
44
        :param a_repository: A repository to refer to.
47
45
        """
48
46
        repo = self.make_repository(relpath)
49
 
        repo.add_fallback_repository(self.readonly_repository(target_path))
 
47
        repo.add_fallback_repository(self.readonly_repository(a_repository))
50
48
        return repo
51
49
 
52
 
    def readonly_repository(self, relpath):
53
 
        return BzrDir.open_from_transport(
 
50
    def readonly_repository(self, repo):
 
51
        relpath = urlutils.basename(repo.bzrdir.user_url.rstrip('/'))
 
52
        return ControlDir.open_from_transport(
54
53
            self.get_readonly_transport(relpath)).open_repository()
55
54
 
56
55
 
61
60
        # because developers use this api to setup the tree, branch and
62
61
        # repository for their tests: having it not give the right repository
63
62
        # type would invalidate the tests.
64
 
        self.make_branch_and_tree('repo')
65
 
        repo = self.make_referring('referring', 'repo')
 
63
        tree = self.make_branch_and_tree('repo')
 
64
        repo = self.make_referring('referring', tree.branch.repository)
66
65
        self.assertIsInstance(repo._format,
67
66
            self.repository_format.__class__)
68
67
 
69
68
 
70
69
class TestIncompatibleStacking(TestCaseWithRepository):
71
70
 
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:
 
71
    def make_repo_and_incompatible_fallback(self):
 
72
        referring = self.make_repository('referring')
 
73
        if referring._format.supports_chks:
77
74
            different_fmt = '1.9'
78
75
        else:
79
76
            different_fmt = '2a'
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)
 
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())
84
102
 
85
103
 
86
104
def external_reference_test_scenarios():
89
107
    result = []
90
108
    for test_name, scenario_info in all_repository_format_scenarios():
91
109
        format = scenario_info['repository_format']
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:
 
110
        if (isinstance(format, remote.RemoteRepositoryFormat)
 
111
            or format.supports_external_lookups):
104
112
            result.append((test_name, scenario_info))
105
113
    return result
106
114
 
113
121
        'bzrlib.tests.per_repository_reference.test_all_revision_ids',
114
122
        'bzrlib.tests.per_repository_reference.test_break_lock',
115
123
        'bzrlib.tests.per_repository_reference.test_check',
 
124
        'bzrlib.tests.per_repository_reference.test_commit_with_stacking',
116
125
        'bzrlib.tests.per_repository_reference.test_default_stacking',
117
126
        'bzrlib.tests.per_repository_reference.test_fetch',
118
127
        'bzrlib.tests.per_repository_reference.test_get_record_stream',
119
128
        'bzrlib.tests.per_repository_reference.test_get_rev_id_for_revno',
 
129
        'bzrlib.tests.per_repository_reference.test_graph',
120
130
        'bzrlib.tests.per_repository_reference.test_initialize',
 
131
        'bzrlib.tests.per_repository_reference.test__make_parents_provider',
121
132
        'bzrlib.tests.per_repository_reference.test_unlock',
122
133
        ]
123
134
    # Parameterize per_repository_reference test modules by format.