bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
1 |
# Copyright (C) 2008 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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
16 |
|
|
3389.2.6
by John Arbash Meinel
minor fix to test file comment |
17 |
"""Tests for branch implementations - test check() functionality"""
|
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
18 |
|
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
19 |
from io import BytesIO |
|
4332.3.3
by Robert Collins
Alter Branch.check to log errors rather than raising. |
20 |
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
21 |
from ... import ( |
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
22 |
errors, |
23 |
tests, |
|
24 |
ui, |
|
25 |
)
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
26 |
from . import TestCaseWithBranch |
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
27 |
|
28 |
||
29 |
class TestBranchCheck(TestCaseWithBranch): |
|
30 |
||
31 |
def test_check_detects_invalid_revhistory(self): |
|
32 |
# Different formats have different ways of handling invalid revision
|
|
33 |
# histories, so the setup portion is customized
|
|
34 |
tree = self.make_branch_and_tree('test') |
|
35 |
r1 = tree.commit('one') |
|
36 |
r2 = tree.commit('two') |
|
37 |
r3 = tree.commit('three') |
|
38 |
r4 = tree.commit('four') |
|
39 |
# create an alternate branch
|
|
40 |
tree.set_parent_ids([r1]) |
|
41 |
tree.branch.set_last_revision_info(1, r1) |
|
42 |
r2b = tree.commit('two-b') |
|
43 |
||
44 |
# now go back and merge the commit
|
|
45 |
tree.set_parent_ids([r4, r2b]) |
|
46 |
tree.branch.set_last_revision_info(4, r4) |
|
47 |
||
48 |
r5 = tree.commit('five') |
|
49 |
# Now, try to set an invalid history
|
|
|
6498.3.4
by Jelmer Vernooij
Remove more .set_revision_history / .revision_history references. |
50 |
if getattr(tree.branch, "_set_revision_history", None) is not None: |
51 |
tree.branch._set_revision_history([r1, r2b, r5]) |
|
52 |
else: |
|
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
53 |
tree.branch.set_last_revision_info(3, r5) |
54 |
||
|
4332.3.7
by Robert Collins
Convert Branch.check to take a refs dict as well. |
55 |
tree.lock_read() |
56 |
self.addCleanup(tree.unlock) |
|
57 |
refs = self.make_refs(tree.branch) |
|
58 |
result = tree.branch.check(refs) |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
59 |
ui.ui_factory = tests.TestUIFactory(stdout=BytesIO()) |
|
4332.3.3
by Robert Collins
Alter Branch.check to log errors rather than raising. |
60 |
result.report_results(True) |
|
6973.6.2
by Jelmer Vernooij
Fix more tests. |
61 |
self.assertContainsRe(b'revno does not match len', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
62 |
ui.ui_factory.stdout.getvalue()) |
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
63 |
|
64 |
def test_check_branch_report_results(self): |
|
65 |
"""Checking a branch produces results which can be printed""" |
|
66 |
branch = self.make_branch('.') |
|
|
4332.3.7
by Robert Collins
Convert Branch.check to take a refs dict as well. |
67 |
branch.lock_read() |
68 |
self.addCleanup(branch.unlock) |
|
69 |
result = branch.check(self.make_refs(branch)) |
|
|
3389.2.5
by John Arbash Meinel
Fix the line endings on test_check and test_reconcile |
70 |
# reports results through logging
|
71 |
result.report_results(verbose=True) |
|
72 |
result.report_results(verbose=False) |
|
73 |
||
|
4332.3.5
by Robert Collins
Add Branch._get_check_refs. |
74 |
def test__get_check_refs(self): |
75 |
tree = self.make_branch_and_tree('.') |
|
76 |
revid = tree.commit('foo') |
|
77 |
self.assertEqual( |
|
|
6619.3.12
by Jelmer Vernooij
Use 2to3 set_literal fixer. |
78 |
{('revision-existence', revid), ('lefthand-distance', revid)}, |
|
4332.3.5
by Robert Collins
Add Branch._get_check_refs. |
79 |
set(tree.branch._get_check_refs())) |
|
4332.3.7
by Robert Collins
Convert Branch.check to take a refs dict as well. |
80 |
|
81 |
def make_refs(self, branch): |
|
82 |
needed_refs = branch._get_check_refs() |
|
83 |
refs = {} |
|
84 |
distances = set() |
|
85 |
existences = set() |
|
86 |
for ref in needed_refs: |
|
87 |
kind, value = ref |
|
88 |
if kind == 'lefthand-distance': |
|
89 |
distances.add(value) |
|
90 |
elif kind == 'revision-existence': |
|
91 |
existences.add(value) |
|
92 |
else: |
|
93 |
raise AssertionError( |
|
94 |
'unknown ref kind for ref %s' % ref) |
|
95 |
node_distances = branch.repository.get_graph().find_lefthand_distances( |
|
96 |
distances) |
|
|
6656.1.1
by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers |
97 |
for key, distance in node_distances.items(): |
|
4332.3.7
by Robert Collins
Convert Branch.check to take a refs dict as well. |
98 |
refs[('lefthand-distance', key)] = distance |
99 |
if key in existences and distance > 0: |
|
100 |
refs[('revision-existence', key)] = True |
|
101 |
existences.remove(key) |
|
102 |
parent_map = branch.repository.get_graph().get_parent_map(existences) |
|
103 |
for key in parent_map: |
|
104 |
refs[('revision-existence', key)] = True |
|
105 |
existences.remove(key) |
|
106 |
for key in existences: |
|
107 |
refs[('revision-existence', key)] = False |
|
108 |
return refs |