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

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Test operations that check the repository for corruption"""
19
19
 
 
20
import os
20
21
 
21
22
from bzrlib import (
 
23
    check,
 
24
    config as _mod_config,
22
25
    errors,
 
26
    inventory,
23
27
    revision as _mod_revision,
24
28
    )
25
29
from bzrlib.tests import TestNotApplicable
36
40
        tree = self.make_branch_and_tree('.')
37
41
        self.build_tree(['foo'])
38
42
        tree.smart_add(['.'])
39
 
        tree.commit('1')
 
43
        revid1 = tree.commit('1')
40
44
        self.build_tree(['bar'])
41
45
        tree.smart_add(['.'])
42
 
        tree.commit('2')
43
 
        # XXX: check requires a non-empty revision IDs list, but it ignores the
44
 
        # contents of it!
45
 
        check_object = tree.branch.repository.check(['ignored'])
46
 
        check_object.report_results(verbose=False)
47
 
        log = self._get_log(keep_log_file=True)
48
 
        self.assertContainsRe(
49
 
            log,
50
 
            "0 unreferenced text versions")
 
46
        revid2 = tree.commit('2')
 
47
        check_object = tree.branch.repository.check([revid1, revid2])
 
48
        check_object.report_results(verbose=True)
 
49
        self.assertContainsRe(self.get_log(), "0 unreferenced text versions")
51
50
 
52
51
 
53
52
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
90
89
        # contents of it!
91
90
        check_object = repo.check(['ignored'])
92
91
        check_object.report_results(verbose=False)
93
 
        log = self._get_log(keep_log_file=True)
94
 
        self.assertContainsRe(
95
 
            log, '1 revisions have incorrect parents in the revision index')
 
92
        self.assertContainsRe(self.get_log(),
 
93
            '1 revisions have incorrect parents in the revision index')
96
94
        check_object.report_results(verbose=True)
97
 
        log = self._get_log(keep_log_file=True)
98
95
        self.assertContainsRe(
99
 
            log,
 
96
            self.get_log(),
100
97
            "revision-id has wrong parents in index: "
101
98
            r"\('incorrect-parent',\) should be \(\)")
102
99
 
 
100
 
 
101
class TestCallbacks(TestCaseWithRepository):
 
102
 
 
103
    def test_callback_tree_and_branch(self):
 
104
        # use a real tree to get actual refs that will work
 
105
        tree = self.make_branch_and_tree('foo')
 
106
        revid = tree.commit('foo')
 
107
        tree.lock_read()
 
108
        self.addCleanup(tree.unlock)
 
109
        needed_refs = {}
 
110
        for ref in tree._get_check_refs():
 
111
            needed_refs.setdefault(ref, []).append(tree)
 
112
        for ref in tree.branch._get_check_refs():
 
113
            needed_refs.setdefault(ref, []).append(tree.branch)
 
114
        self.tree_check = tree._check
 
115
        self.branch_check = tree.branch.check
 
116
        tree._check = self.tree_callback
 
117
        tree.branch.check = self.branch_callback
 
118
        self.callbacks = []
 
119
        tree.branch.repository.check([revid], callback_refs=needed_refs)
 
120
        self.assertNotEqual([], self.callbacks)
 
121
 
 
122
    def tree_callback(self, refs):
 
123
        self.callbacks.append(('tree', refs))
 
124
        return self.tree_check(refs)
 
125
 
 
126
    def branch_callback(self, refs):
 
127
        self.callbacks.append(('branch', refs))
 
128
        return self.branch_check(refs)
 
129
 
 
130
 
 
131
class TestCleanRepository(TestCaseWithRepository):
 
132
 
 
133
    def test_new_repo(self):
 
134
        repo = self.make_repository('foo')
 
135
        repo.lock_write()
 
136
        self.addCleanup(repo.unlock)
 
137
        config = _mod_config.Config()
 
138
        os.environ['BZR_EMAIL'] = 'foo@sample.com'
 
139
        builder = repo.get_commit_builder(None, [], config)
 
140
        list(builder.record_iter_changes(None, _mod_revision.NULL_REVISION, [
 
141
            ('TREE_ROOT', (None, ''), True, (False, True), (None, None),
 
142
            (None, ''), (None, 'directory'), (None, False))]))
 
143
        builder.finish_inventory()
 
144
        rev_id = builder.commit('first post')
 
145
        result = repo.check(None, check_repo=True)
 
146
        result.report_results(True)
 
147
        log = self.get_log()
 
148
        self.assertFalse('Missing' in log, "Something was missing in %r" % log)