~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository_vf/test_check.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

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