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

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
"""Tests for branch implementations - test check() functionality"""
18
18
 
19
 
from bzrlib import errors
20
 
from bzrlib.tests.branch_implementations import TestCaseWithBranch
 
19
from StringIO import StringIO
 
20
 
 
21
from bzrlib import errors, tests, ui
 
22
from bzrlib.tests.per_branch import TestCaseWithBranch
21
23
 
22
24
 
23
25
class TestBranchCheck(TestCaseWithBranch):
54
56
            # with set_last_revision_info
55
57
            tree.branch.set_last_revision_info(3, r5)
56
58
 
57
 
        e = self.assertRaises(errors.BzrCheckError,
58
 
                              tree.branch.check)
59
 
        self.assertEqual('Internal check failed:'
60
 
                         ' revno does not match len(mainline) 3 != 5', str(e))
 
59
        tree.lock_read()
 
60
        self.addCleanup(tree.unlock)
 
61
        refs = self.make_refs(tree.branch)
 
62
        result = tree.branch.check(refs)
 
63
        ui.ui_factory = tests.TestUIFactory(stdout=StringIO())
 
64
        result.report_results(True)
 
65
        self.assertContainsRe('revno does not match len',
 
66
            ui.ui_factory.stdout.getvalue())
61
67
 
62
68
    def test_check_branch_report_results(self):
63
69
        """Checking a branch produces results which can be printed"""
64
70
        branch = self.make_branch('.')
65
 
        result = branch.check()
 
71
        branch.lock_read()
 
72
        self.addCleanup(branch.unlock)
 
73
        result = branch.check(self.make_refs(branch))
66
74
        # reports results through logging
67
75
        result.report_results(verbose=True)
68
76
        result.report_results(verbose=False)
69
77
 
 
78
    def test__get_check_refs(self):
 
79
        tree = self.make_branch_and_tree('.')
 
80
        revid = tree.commit('foo')
 
81
        self.assertEqual(
 
82
            set([('revision-existence', revid), ('lefthand-distance', revid)]),
 
83
            set(tree.branch._get_check_refs()))
70
84
 
 
85
    def make_refs(self, branch):
 
86
        needed_refs = branch._get_check_refs()
 
87
        refs = {}
 
88
        distances = set()
 
89
        existences = set()
 
90
        for ref in needed_refs:
 
91
            kind, value = ref
 
92
            if kind == 'lefthand-distance':
 
93
                distances.add(value)
 
94
            elif kind == 'revision-existence':
 
95
                existences.add(value)
 
96
            else:
 
97
                raise AssertionError(
 
98
                    'unknown ref kind for ref %s' % ref)
 
99
        node_distances = branch.repository.get_graph().find_lefthand_distances(
 
100
            distances)
 
101
        for key, distance in node_distances.iteritems():
 
102
            refs[('lefthand-distance', key)] = distance
 
103
            if key in existences and distance > 0:
 
104
                refs[('revision-existence', key)] = True
 
105
                existences.remove(key)
 
106
        parent_map = branch.repository.get_graph().get_parent_map(existences)
 
107
        for key in parent_map:
 
108
            refs[('revision-existence', key)] = True
 
109
            existences.remove(key)
 
110
        for key in existences:
 
111
            refs[('revision-existence', key)] = False
 
112
        return refs