/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5802.2.2 by Jelmer Vernooij
Move vf check tests to bt.per_repository_vf.test_check.
1
# Copyright (C) 2007-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Test operations that check the repository for corruption"""
18
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
5802.2.2 by Jelmer Vernooij
Move vf check tests to bt.per_repository_vf.test_check.
21
    errors,
22
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests import (
5802.2.2 by Jelmer Vernooij
Move vf check tests to bt.per_repository_vf.test_check.
24
    TestNotApplicable,
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.tests.scenarios import load_tests_apply_scenarios
27
from breezy.tests.per_repository_vf import (
5858.2.1 by Jelmer Vernooij
Move a test that use Tree._get_check_refs to per_repository_vf.
28
    TestCaseWithRepository,
5802.2.2 by Jelmer Vernooij
Move vf check tests to bt.per_repository_vf.test_check.
29
    all_repository_vf_format_scenarios,
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.tests.per_repository_vf.helpers import (
5802.2.2 by Jelmer Vernooij
Move vf check tests to bt.per_repository_vf.test_check.
32
    TestCaseWithBrokenRevisionIndex,
33
    )
34
35
36
load_tests = load_tests_apply_scenarios
37
38
39
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
40
41
    scenarios = all_repository_vf_format_scenarios()
42
43
    def test__find_inconsistent_revision_parents(self):
44
        """_find_inconsistent_revision_parents finds revisions with broken
45
        parents.
46
        """
47
        repo = self.make_repo_with_extra_ghost_index()
48
        self.assertEqual(
49
            [('revision-id', ('incorrect-parent',), ())],
50
            list(repo._find_inconsistent_revision_parents()))
51
52
    def test__check_for_inconsistent_revision_parents(self):
53
        """_check_for_inconsistent_revision_parents raises BzrCheckError if
54
        there are any revisions with inconsistent parents.
55
        """
56
        repo = self.make_repo_with_extra_ghost_index()
57
        self.assertRaises(
58
            errors.BzrCheckError,
59
            repo._check_for_inconsistent_revision_parents)
60
61
    def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
62
        """_check_for_inconsistent_revision_parents does nothing if there are
63
        no broken revisions.
64
        """
65
        repo = self.make_repository('empty-repo')
66
        if not repo._format.revision_graph_can_have_wrong_parents:
67
            raise TestNotApplicable(
68
                '%r cannot have corrupt revision index.' % repo)
69
        repo.lock_read()
70
        try:
71
            repo._check_for_inconsistent_revision_parents()  # nothing happens
72
        finally:
73
            repo.unlock()
74
75
    def test_check_reports_bad_ancestor(self):
76
        repo = self.make_repo_with_extra_ghost_index()
77
        # XXX: check requires a non-empty revision IDs list, but it ignores the
78
        # contents of it!
79
        check_object = repo.check(['ignored'])
80
        check_object.report_results(verbose=False)
81
        self.assertContainsRe(self.get_log(),
82
            '1 revisions have incorrect parents in the revision index')
83
        check_object.report_results(verbose=True)
84
        self.assertContainsRe(
85
            self.get_log(),
86
            "revision-id has wrong parents in index: "
87
            r"\('incorrect-parent',\) should be \(\)")
5858.2.1 by Jelmer Vernooij
Move a test that use Tree._get_check_refs to per_repository_vf.
88
89
90
class TestCallbacks(TestCaseWithRepository):
91
5858.2.2 by Jelmer Vernooij
Set scenarios.
92
    scenarios = all_repository_vf_format_scenarios()
93
5858.2.1 by Jelmer Vernooij
Move a test that use Tree._get_check_refs to per_repository_vf.
94
    def test_callback_tree_and_branch(self):
95
        # use a real tree to get actual refs that will work
96
        tree = self.make_branch_and_tree('foo')
97
        revid = tree.commit('foo')
98
        tree.lock_read()
99
        self.addCleanup(tree.unlock)
100
        needed_refs = {}
101
        for ref in tree._get_check_refs():
102
            needed_refs.setdefault(ref, []).append(tree)
103
        for ref in tree.branch._get_check_refs():
104
            needed_refs.setdefault(ref, []).append(tree.branch)
105
        self.tree_check = tree._check
106
        self.branch_check = tree.branch.check
5340.15.1 by John Arbash Meinel
supersede exc-info branch
107
        self.overrideAttr(tree, "_check", self.tree_callback)
108
        self.overrideAttr(tree.branch, "check", self.branch_callback)
5858.2.1 by Jelmer Vernooij
Move a test that use Tree._get_check_refs to per_repository_vf.
109
        self.callbacks = []
110
        tree.branch.repository.check([revid], callback_refs=needed_refs)
111
        self.assertNotEqual([], self.callbacks)
112
113
    def tree_callback(self, refs):
114
        self.callbacks.append(('tree', refs))
115
        return self.tree_check(refs)
116
117
    def branch_callback(self, refs):
118
        self.callbacks.append(('branch', refs))
119
        return self.branch_check(refs)
6217.3.2 by Jelmer Vernooij
Move vf-specific test to bt.per_repository_vf.
120
121
122
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository):
123
124
    scenarios = all_repository_vf_format_scenarios()
125
126
    def test_two_files_different_versions_no_inconsistencies_bug_165071(self):
127
        """Two files, with different versions can be clean."""
128
        tree = self.make_branch_and_tree('.')
129
        self.build_tree(['foo'])
130
        tree.smart_add(['.'])
131
        revid1 = tree.commit('1')
132
        self.build_tree(['bar'])
133
        tree.smart_add(['.'])
134
        revid2 = tree.commit('2')
135
        check_object = tree.branch.repository.check([revid1, revid2])
136
        check_object.report_results(verbose=True)
137
        self.assertContainsRe(self.get_log(), "0 unreferenced text versions")
138
139
140