1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# Copyright (C) 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for the python and pyrex extensions of groupcompress"""
from bzrlib import (
errors,
graph as _mod_graph,
_known_graph_py,
tests,
)
from bzrlib.tests import test_graph
from bzrlib.revision import NULL_REVISION
def load_tests(standard_tests, module, loader):
"""Parameterize tests for all versions of groupcompress."""
scenarios = [
('python', {'module': _known_graph_py, 'do_cache': True}),
('python-nocache', {'module': _known_graph_py, 'do_cache': False}),
]
suite = loader.suiteClass()
if CompiledKnownGraphFeature.available():
from bzrlib import _known_graph_pyx
scenarios.append(('C', {'module': _known_graph_pyx, 'do_cache': True}))
scenarios.append(('C-nocache',
{'module': _known_graph_pyx, 'do_cache': False}))
else:
# the compiled module isn't available, so we add a failing test
class FailWithoutFeature(tests.TestCase):
def test_fail(self):
self.requireFeature(CompiledKnownGraphFeature)
suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
result = tests.multiply_tests(standard_tests, scenarios, suite)
return result
class _CompiledKnownGraphFeature(tests.Feature):
def _probe(self):
try:
import bzrlib._known_graph_pyx
except ImportError:
return False
return True
def feature_name(self):
return 'bzrlib._known_graph_pyx'
CompiledKnownGraphFeature = _CompiledKnownGraphFeature()
class TestKnownGraph(tests.TestCase):
module = None # Set by load_tests
do_cache = None # Set by load_tests
def make_known_graph(self, ancestry):
return self.module.KnownGraph(ancestry, do_cache=self.do_cache)
def assertGDFO(self, graph, rev, gdfo):
node = graph._nodes[rev]
self.assertEqual(gdfo, node.gdfo)
def test_children_ancestry1(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual(['rev1'], graph._nodes[NULL_REVISION].child_keys)
self.assertEqual(['rev2a', 'rev2b'],
sorted(graph._nodes['rev1'].child_keys))
self.assertEqual(['rev3'], sorted(graph._nodes['rev2a'].child_keys))
self.assertEqual(['rev4'], sorted(graph._nodes['rev3'].child_keys))
self.assertEqual(['rev4'], sorted(graph._nodes['rev2b'].child_keys))
def test_gdfo_ancestry_1(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertGDFO(graph, 'rev1', 2)
self.assertGDFO(graph, 'rev2b', 3)
self.assertGDFO(graph, 'rev2a', 3)
self.assertGDFO(graph, 'rev3', 4)
self.assertGDFO(graph, 'rev4', 5)
def test_gdfo_feature_branch(self):
graph = self.make_known_graph(test_graph.feature_branch)
self.assertGDFO(graph, 'rev1', 2)
self.assertGDFO(graph, 'rev2b', 3)
self.assertGDFO(graph, 'rev3b', 4)
def test_gdfo_extended_history_shortcut(self):
graph = self.make_known_graph(test_graph.extended_history_shortcut)
self.assertGDFO(graph, 'a', 2)
self.assertGDFO(graph, 'b', 3)
self.assertGDFO(graph, 'c', 4)
self.assertGDFO(graph, 'd', 5)
self.assertGDFO(graph, 'e', 6)
self.assertGDFO(graph, 'f', 6)
def test_gdfo_with_ghost(self):
graph = self.make_known_graph(test_graph.with_ghost)
self.assertGDFO(graph, 'f', 2)
self.assertGDFO(graph, 'e', 3)
self.assertGDFO(graph, 'g', 1)
self.assertGDFO(graph, 'b', 4)
self.assertGDFO(graph, 'd', 4)
self.assertGDFO(graph, 'a', 5)
self.assertGDFO(graph, 'c', 5)
def test_heads_null(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual(set(['null:']), graph.heads(['null:']))
self.assertEqual(set(['rev1']), graph.heads(['null:', 'rev1']))
self.assertEqual(set(['rev1']), graph.heads(['rev1', 'null:']))
self.assertEqual(set(['rev1']), graph.heads(set(['rev1', 'null:'])))
self.assertEqual(set(['rev1']), graph.heads(('rev1', 'null:')))
def test_heads_one(self):
# A single node will always be a head
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual(set(['null:']), graph.heads(['null:']))
self.assertEqual(set(['rev1']), graph.heads(['rev1']))
self.assertEqual(set(['rev2a']), graph.heads(['rev2a']))
self.assertEqual(set(['rev2b']), graph.heads(['rev2b']))
self.assertEqual(set(['rev3']), graph.heads(['rev3']))
self.assertEqual(set(['rev4']), graph.heads(['rev4']))
def test_heads_single(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual(set(['rev4']), graph.heads(['null:', 'rev4']))
self.assertEqual(set(['rev2a']), graph.heads(['rev1', 'rev2a']))
self.assertEqual(set(['rev2b']), graph.heads(['rev1', 'rev2b']))
self.assertEqual(set(['rev3']), graph.heads(['rev1', 'rev3']))
self.assertEqual(set(['rev3']), graph.heads(['rev3', 'rev2a']))
self.assertEqual(set(['rev4']), graph.heads(['rev1', 'rev4']))
self.assertEqual(set(['rev4']), graph.heads(['rev2a', 'rev4']))
self.assertEqual(set(['rev4']), graph.heads(['rev2b', 'rev4']))
self.assertEqual(set(['rev4']), graph.heads(['rev3', 'rev4']))
def test_heads_two_heads(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual(set(['rev2a', 'rev2b']),
graph.heads(['rev2a', 'rev2b']))
self.assertEqual(set(['rev3', 'rev2b']),
graph.heads(['rev3', 'rev2b']))
def test_heads_criss_cross(self):
graph = self.make_known_graph(test_graph.criss_cross)
self.assertEqual(set(['rev2a']),
graph.heads(['rev2a', 'rev1']))
self.assertEqual(set(['rev2b']),
graph.heads(['rev2b', 'rev1']))
self.assertEqual(set(['rev3a']),
graph.heads(['rev3a', 'rev1']))
self.assertEqual(set(['rev3b']),
graph.heads(['rev3b', 'rev1']))
self.assertEqual(set(['rev2a', 'rev2b']),
graph.heads(['rev2a', 'rev2b']))
self.assertEqual(set(['rev3a']),
graph.heads(['rev3a', 'rev2a']))
self.assertEqual(set(['rev3a']),
graph.heads(['rev3a', 'rev2b']))
self.assertEqual(set(['rev3a']),
graph.heads(['rev3a', 'rev2a', 'rev2b']))
self.assertEqual(set(['rev3b']),
graph.heads(['rev3b', 'rev2a']))
self.assertEqual(set(['rev3b']),
graph.heads(['rev3b', 'rev2b']))
self.assertEqual(set(['rev3b']),
graph.heads(['rev3b', 'rev2a', 'rev2b']))
self.assertEqual(set(['rev3a', 'rev3b']),
graph.heads(['rev3a', 'rev3b']))
self.assertEqual(set(['rev3a', 'rev3b']),
graph.heads(['rev3a', 'rev3b', 'rev2a', 'rev2b']))
def test_heads_shortcut(self):
graph = self.make_known_graph(test_graph.history_shortcut)
self.assertEqual(set(['rev2a', 'rev2b', 'rev2c']),
graph.heads(['rev2a', 'rev2b', 'rev2c']))
self.assertEqual(set(['rev3a', 'rev3b']),
graph.heads(['rev3a', 'rev3b']))
self.assertEqual(set(['rev3a', 'rev3b']),
graph.heads(['rev2a', 'rev3a', 'rev3b']))
self.assertEqual(set(['rev2a', 'rev3b']),
graph.heads(['rev2a', 'rev3b']))
self.assertEqual(set(['rev2c', 'rev3a']),
graph.heads(['rev2c', 'rev3a']))
def test_heads_linear(self):
graph = self.make_known_graph(test_graph.racing_shortcuts)
self.assertEqual(set(['w']), graph.heads(['w', 's']))
self.assertEqual(set(['z']), graph.heads(['w', 's', 'z']))
self.assertEqual(set(['w', 'q']), graph.heads(['w', 's', 'q']))
self.assertEqual(set(['z']), graph.heads(['s', 'z']))
def test_heads_with_ghost(self):
graph = self.make_known_graph(test_graph.with_ghost)
self.assertEqual(set(['e', 'g']), graph.heads(['e', 'g']))
self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c']))
self.assertEqual(set(['a', 'g']), graph.heads(['a', 'g']))
self.assertEqual(set(['f', 'g']), graph.heads(['f', 'g']))
self.assertEqual(set(['c']), graph.heads(['c', 'g']))
self.assertEqual(set(['c']), graph.heads(['c', 'b', 'd', 'g']))
self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
|