/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/repository_implementations/test_check.py

  • Committer: Robert Collins
  • Date: 2007-10-17 09:39:41 UTC
  • mfrom: (2911 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: robertc@robertcollins.net-20071017093941-v7d1djrt2617citb
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 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
"""Test operations that check the repository for corruption"""
 
19
 
 
20
 
 
21
from bzrlib import (
 
22
    errors,
 
23
    inventory,
 
24
    revision as _mod_revision,
 
25
    )
 
26
from bzrlib.repository import _RevisionTextVersionCache
 
27
from bzrlib.tests import TestNotApplicable
 
28
from bzrlib.tests.repository_implementations import TestCaseWithRepository
 
29
from bzrlib.tests.repository_implementations.helpers import (
 
30
    TestCaseWithBrokenRevisionIndex,
 
31
    )
 
32
 
 
33
 
 
34
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
 
35
 
 
36
    def test__find_inconsistent_revision_parents(self):
 
37
        """_find_inconsistent_revision_parents finds revisions with broken
 
38
        parents.
 
39
        """
 
40
        repo = self.make_repo_with_extra_ghost_index()
 
41
        self.assertEqual(
 
42
            [('revision-id', ('incorrect-parent',), ())],
 
43
            list(repo._find_inconsistent_revision_parents()))
 
44
 
 
45
    def test__check_for_inconsistent_revision_parents(self):
 
46
        """_check_for_inconsistent_revision_parents raises BzrCheckError if
 
47
        there are any revisions with inconsistent parents.
 
48
        """
 
49
        repo = self.make_repo_with_extra_ghost_index()
 
50
        self.assertRaises(
 
51
            errors.BzrCheckError,
 
52
            repo._check_for_inconsistent_revision_parents)
 
53
 
 
54
    def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
 
55
        """_check_for_inconsistent_revision_parents does nothing if there are
 
56
        no broken revisions.
 
57
        """
 
58
        repo = self.make_repository('empty-repo')
 
59
        if not repo.revision_graph_can_have_wrong_parents():
 
60
            raise TestNotApplicable(
 
61
                '%r cannot have corrupt revision index.' % repo)
 
62
        repo.lock_read()
 
63
        try:
 
64
            repo._check_for_inconsistent_revision_parents()  # nothing happens
 
65
        finally:
 
66
            repo.unlock()
 
67
 
 
68
    def test_check_reports_bad_ancestor(self):
 
69
        repo = self.make_repo_with_extra_ghost_index()
 
70
        # XXX: check requires a non-empty revision IDs list, but it ignores the
 
71
        # contents of it!
 
72
        check_object = repo.check(['ignored'])
 
73
        check_object.report_results(verbose=False)
 
74
        log = self._get_log(keep_log_file=True)
 
75
        self.assertContainsRe(
 
76
            log, '1 revisions have incorrect parents in the revision index')
 
77
        check_object.report_results(verbose=True)
 
78
        log = self._get_log(keep_log_file=True)
 
79
        self.assertContainsRe(
 
80
            log,
 
81
            "revision-id has wrong parents in index: "
 
82
            r"\('incorrect-parent',\) should be \(\)")
 
83