Merge lp:~jelmer/brz/python3-graph into lp:brz
- python3-graph
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | no longer in the source branch. |
Merged at revision: | 6981 |
Proposed branch: | lp:~jelmer/brz/python3-graph |
Merge into: | lp:brz |
Diff against target: |
1886 lines (+575/-563) 3 files modified
breezy/graph.py (+1/-1) breezy/tests/test_graph.py (+562/-562) python3.passing (+12/-0) |
To merge this branch: | bzr merge lp:~jelmer/brz/python3-graph |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+346430@code.launchpad.net |
Commit message
Port breezy.graph to Python3.
Description of the change
Port breezy.graph to Python3.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/graph.py' |
2 | --- breezy/graph.py 2018-05-14 20:32:14 +0000 |
3 | +++ breezy/graph.py 2018-05-22 01:21:07 +0000 |
4 | @@ -1149,7 +1149,7 @@ |
5 | ancestor_all_unique = ancestor_all_unique.intersection( |
6 | searcher.seen) |
7 | |
8 | - trace.mutter('Started %s unique searchers for %s unique revisions', |
9 | + trace.mutter('Started %d unique searchers for %d unique revisions', |
10 | simple_unique, total_unique) |
11 | |
12 | while True: # If we have no more nodes we have nothing to do |
13 | |
14 | === modified file 'breezy/tests/test_graph.py' |
15 | --- breezy/tests/test_graph.py 2017-11-12 13:53:51 +0000 |
16 | +++ breezy/tests/test_graph.py 2018-05-22 01:21:07 +0000 |
17 | @@ -34,8 +34,8 @@ |
18 | # rev3 / |
19 | # | / |
20 | # rev4 |
21 | -ancestry_1 = {'rev1': [NULL_REVISION], 'rev2a': ['rev1'], 'rev2b': ['rev1'], |
22 | - 'rev3': ['rev2a'], 'rev4': ['rev3', 'rev2b']} |
23 | +ancestry_1 = {b'rev1': [NULL_REVISION], b'rev2a': [b'rev1'], b'rev2b': [b'rev1'], |
24 | + b'rev3': [b'rev2a'], b'rev4': [b'rev3', b'rev2b']} |
25 | |
26 | |
27 | # Ancestry 2: |
28 | @@ -49,8 +49,8 @@ |
29 | # rev3a |
30 | # | |
31 | # rev4a |
32 | -ancestry_2 = {'rev1a': [NULL_REVISION], 'rev2a': ['rev1a'], |
33 | - 'rev1b': [NULL_REVISION], 'rev3a': ['rev2a'], 'rev4a': ['rev3a']} |
34 | +ancestry_2 = {b'rev1a': [NULL_REVISION], b'rev2a': [b'rev1a'], |
35 | + b'rev1b': [NULL_REVISION], b'rev3a': [b'rev2a'], b'rev4a': [b'rev3a']} |
36 | |
37 | |
38 | # Criss cross ancestry |
39 | @@ -64,8 +64,8 @@ |
40 | # | X | |
41 | # |/ \| |
42 | # rev3a rev3b |
43 | -criss_cross = {'rev1': [NULL_REVISION], 'rev2a': ['rev1'], 'rev2b': ['rev1'], |
44 | - 'rev3a': ['rev2a', 'rev2b'], 'rev3b': ['rev2b', 'rev2a']} |
45 | +criss_cross = {b'rev1': [NULL_REVISION], b'rev2a': [b'rev1'], b'rev2b': [b'rev1'], |
46 | + b'rev3a': [b'rev2a', b'rev2b'], b'rev3b': [b'rev2b', b'rev2a']} |
47 | |
48 | |
49 | # Criss-cross 2 |
50 | @@ -79,8 +79,8 @@ |
51 | # | / \ | |
52 | # |/ \| |
53 | # rev2a rev2b |
54 | -criss_cross2 = {'rev1a': [NULL_REVISION], 'rev1b': [NULL_REVISION], |
55 | - 'rev2a': ['rev1a', 'rev1b'], 'rev2b': ['rev1b', 'rev1a']} |
56 | +criss_cross2 = {b'rev1a': [NULL_REVISION], b'rev1b': [NULL_REVISION], |
57 | + b'rev2a': [b'rev1a', b'rev1b'], b'rev2b': [b'rev1b', b'rev1a']} |
58 | |
59 | |
60 | # Mainline: |
61 | @@ -92,8 +92,8 @@ |
62 | # | rev2b |
63 | # | / |
64 | # rev2a |
65 | -mainline = {'rev1': [NULL_REVISION], 'rev2a': ['rev1', 'rev2b'], |
66 | - 'rev2b': ['rev1']} |
67 | +mainline = {b'rev1': [NULL_REVISION], b'rev2a': [b'rev1', b'rev2b'], |
68 | + b'rev2b': [b'rev1']} |
69 | |
70 | |
71 | # feature branch: |
72 | @@ -105,8 +105,8 @@ |
73 | # rev2b |
74 | # | |
75 | # rev3b |
76 | -feature_branch = {'rev1': [NULL_REVISION], |
77 | - 'rev2b': ['rev1'], 'rev3b': ['rev2b']} |
78 | +feature_branch = {b'rev1': [NULL_REVISION], |
79 | + b'rev2b': [b'rev1'], b'rev3b': [b'rev2b']} |
80 | |
81 | |
82 | # History shortcut |
83 | @@ -117,9 +117,9 @@ |
84 | # rev2a rev2b rev2c |
85 | # | / \ / |
86 | # rev3a rev3b |
87 | -history_shortcut = {'rev1': [NULL_REVISION], 'rev2a': ['rev1'], |
88 | - 'rev2b': ['rev1'], 'rev2c': ['rev1'], |
89 | - 'rev3a': ['rev2a', 'rev2b'], 'rev3b': ['rev2b', 'rev2c']} |
90 | +history_shortcut = {b'rev1': [NULL_REVISION], b'rev2a': [b'rev1'], |
91 | + b'rev2b': [b'rev1'], b'rev2c': [b'rev1'], |
92 | + b'rev3a': [b'rev2a', b'rev2b'], b'rev3b': [b'rev2b', b'rev2c']} |
93 | |
94 | # Extended history shortcut |
95 | # NULL_REVISION |
96 | @@ -133,16 +133,16 @@ |
97 | # d | |
98 | # |\| |
99 | # e f |
100 | -extended_history_shortcut = {'a': [NULL_REVISION], |
101 | - 'b': ['a'], |
102 | - 'c': ['b'], |
103 | - 'd': ['c'], |
104 | - 'e': ['d'], |
105 | - 'f': ['a', 'd'], |
106 | +extended_history_shortcut = {b'a': [NULL_REVISION], |
107 | + b'b': [b'a'], |
108 | + b'c': [b'b'], |
109 | + b'd': [b'c'], |
110 | + b'e': [b'd'], |
111 | + b'f': [b'a', b'd'], |
112 | } |
113 | |
114 | # Double shortcut |
115 | -# Both sides will see 'A' first, even though it is actually a decendent of a |
116 | +# Both sides will see b'A' first, even though it is actually a decendent of a |
117 | # different common revision. |
118 | # |
119 | # NULL_REVISION |
120 | @@ -157,9 +157,9 @@ |
121 | # |/ \| |
122 | # f g |
123 | |
124 | -double_shortcut = {'a':[NULL_REVISION], 'b':['a'], 'c':['b'], |
125 | - 'd':['c'], 'e':['c'], 'f':['a', 'd'], |
126 | - 'g':['a', 'e']} |
127 | +double_shortcut = {b'a':[NULL_REVISION], b'b':[b'a'], b'c':[b'b'], |
128 | + b'd':[b'c'], b'e':[b'c'], b'f':[b'a', b'd'], |
129 | + b'g':[b'a', b'e']} |
130 | |
131 | # Complex shortcut |
132 | # This has a failure mode in that a shortcut will find some nodes in common, |
133 | @@ -189,10 +189,10 @@ |
134 | # | l | |
135 | # |/|/ |
136 | # m n |
137 | -complex_shortcut = {'a':[NULL_REVISION], 'b':['a'], 'c':['b'], 'd':['c'], |
138 | - 'e':['d'], 'f':['d'], 'g':['f'], 'h':['f'], |
139 | - 'i':['e', 'g'], 'j':['g'], 'k':['j'], |
140 | - 'l':['k'], 'm':['i', 'l'], 'n':['l', 'h']} |
141 | +complex_shortcut = {b'a':[NULL_REVISION], b'b':[b'a'], b'c':[b'b'], b'd':[b'c'], |
142 | + b'e':[b'd'], b'f':[b'd'], b'g':[b'f'], b'h':[b'f'], |
143 | + b'i':[b'e', b'g'], b'j':[b'g'], b'k':[b'j'], |
144 | + b'l':[b'k'], b'm':[b'i', b'l'], b'n':[b'l', b'h']} |
145 | |
146 | # NULL_REVISION |
147 | # | |
148 | @@ -232,11 +232,11 @@ |
149 | # | | | |
150 | # |/|/ |
151 | # t u |
152 | -complex_shortcut2 = {'a': [NULL_REVISION], 'b': ['a'], 'c': ['b'], 'd': ['c'], |
153 | - 'e': ['d'], 'f': ['e'], 'g': ['f'], 'h': ['d'], 'i': ['g'], |
154 | - 'j': ['h'], 'k': ['h', 'i'], 'l': ['k'], 'm': ['l'], 'n': ['m'], |
155 | - 'o': ['n'], 'p': ['o'], 'q': ['p'], 'r': ['q'], 's': ['r'], |
156 | - 't': ['i', 's'], 'u': ['s', 'j'], |
157 | +complex_shortcut2 = {b'a': [NULL_REVISION], b'b': [b'a'], b'c': [b'b'], b'd': [b'c'], |
158 | + b'e': [b'd'], b'f': [b'e'], b'g': [b'f'], b'h': [b'd'], b'i': [b'g'], |
159 | + b'j': [b'h'], b'k': [b'h', b'i'], b'l': [b'k'], b'm': [b'l'], b'n': [b'm'], |
160 | + b'o': [b'n'], b'p': [b'o'], b'q': [b'p'], b'r': [b'q'], b's': [b'r'], |
161 | + b't': [b'i', b's'], b'u': [b's', b'j'], |
162 | } |
163 | |
164 | # Graph where different walkers will race to find the common and uncommon |
165 | @@ -290,11 +290,11 @@ |
166 | # k-n exists so that the second pass still has nodes that are worth searching, |
167 | # rather than instantly cancelling the extra walker. |
168 | |
169 | -racing_shortcuts = {'a':[NULL_REVISION], 'b':['a'], 'c':['b'], 'd':['c'], |
170 | - 'e':['d'], 'f':['e'], 'g':['f'], 'h':['g'], 'i':['h', 'o'], 'j':['i', 'y'], |
171 | - 'k':['d'], 'l':['k'], 'm':['l'], 'n':['m'], 'o':['n', 'g'], 'p':['f'], |
172 | - 'q':['p', 'm'], 'r':['o'], 's':['r'], 't':['s'], 'u':['t'], 'v':['u'], |
173 | - 'w':['v'], 'x':['w'], 'y':['x'], 'z':['x', 'q']} |
174 | +racing_shortcuts = {b'a':[NULL_REVISION], b'b':[b'a'], b'c':[b'b'], b'd':[b'c'], |
175 | + b'e':[b'd'], b'f':[b'e'], b'g':[b'f'], b'h':[b'g'], b'i':[b'h', b'o'], b'j':[b'i', b'y'], |
176 | + b'k':[b'd'], b'l':[b'k'], b'm':[b'l'], b'n':[b'm'], b'o':[b'n', b'g'], b'p':[b'f'], |
177 | + b'q':[b'p', b'm'], b'r':[b'o'], b's':[b'r'], b't':[b's'], b'u':[b't'], b'v':[b'u'], |
178 | + b'w':[b'v'], b'x':[b'w'], b'y':[b'x'], b'z':[b'x', b'q']} |
179 | |
180 | |
181 | # A graph with multiple nodes unique to one side. |
182 | @@ -336,12 +336,12 @@ |
183 | # y z |
184 | # |
185 | |
186 | -multiple_interesting_unique = {'a':[NULL_REVISION], 'b':['a'], 'c':['b'], |
187 | - 'd':['c'], 'e':['d'], 'f':['d'], 'g':['e'], 'h':['e'], 'i':['f'], |
188 | - 'j':['g'], 'k':['g'], 'l':['h'], 'm':['i'], 'n':['k', 'l'], |
189 | - 'o':['m'], 'p':['m', 'l'], 'q':['n', 'o'], 'r':['q'], 's':['r'], |
190 | - 't':['s'], 'u':['t'], 'v':['u'], 'w':['v'], 'x':['w'], |
191 | - 'y':['j', 'x'], 'z':['x', 'p']} |
192 | +multiple_interesting_unique = {b'a':[NULL_REVISION], b'b':[b'a'], b'c':[b'b'], |
193 | + b'd':[b'c'], b'e':[b'd'], b'f':[b'd'], b'g':[b'e'], b'h':[b'e'], b'i':[b'f'], |
194 | + b'j':[b'g'], b'k':[b'g'], b'l':[b'h'], b'm':[b'i'], b'n':[b'k', b'l'], |
195 | + b'o':[b'm'], b'p':[b'm', b'l'], b'q':[b'n', b'o'], b'r':[b'q'], b's':[b'r'], |
196 | + b't':[b's'], b'u':[b't'], b'v':[b'u'], b'w':[b'v'], b'x':[b'w'], |
197 | + b'y':[b'j', b'x'], b'z':[b'x', b'p']} |
198 | |
199 | |
200 | # Shortcut with extra root |
201 | @@ -358,13 +358,13 @@ |
202 | # d | g |
203 | # |\|/ |
204 | # e f |
205 | -shortcut_extra_root = {'a': [NULL_REVISION], |
206 | - 'b': ['a'], |
207 | - 'c': ['b'], |
208 | - 'd': ['c'], |
209 | - 'e': ['d'], |
210 | - 'f': ['a', 'd', 'g'], |
211 | - 'g': [NULL_REVISION], |
212 | +shortcut_extra_root = {b'a': [NULL_REVISION], |
213 | + b'b': [b'a'], |
214 | + b'c': [b'b'], |
215 | + b'd': [b'c'], |
216 | + b'e': [b'd'], |
217 | + b'f': [b'a', b'd', b'g'], |
218 | + b'g': [NULL_REVISION], |
219 | } |
220 | |
221 | # NULL_REVISION |
222 | @@ -377,8 +377,8 @@ |
223 | # | \ | |
224 | # a c |
225 | |
226 | -boundary = {'a': ['b'], 'c': ['b', 'd'], 'b':['e'], 'd':['e'], 'e': ['f'], |
227 | - 'f':[NULL_REVISION]} |
228 | +boundary = {b'a': [b'b'], b'c': [b'b', b'd'], b'b':[b'e'], b'd':[b'e'], b'e': [b'f'], |
229 | + b'f':[NULL_REVISION]} |
230 | |
231 | |
232 | # A graph that contains a ghost |
233 | @@ -392,8 +392,8 @@ |
234 | # | \ | |
235 | # a c |
236 | |
237 | -with_ghost = {'a': ['b'], 'c': ['b', 'd'], 'b':['e'], 'd':['e', 'g'], |
238 | - 'e': ['f'], 'f':[NULL_REVISION], NULL_REVISION:()} |
239 | +with_ghost = {b'a': [b'b'], b'c': [b'b', b'd'], b'b':[b'e'], b'd':[b'e', b'g'], |
240 | + b'e': [b'f'], b'f':[NULL_REVISION], NULL_REVISION:()} |
241 | |
242 | # A graph that shows we can shortcut finding revnos when reaching them from the |
243 | # side. |
244 | @@ -415,8 +415,8 @@ |
245 | # | |
246 | # i |
247 | |
248 | -with_tail = {'a':[NULL_REVISION], 'b':['a'], 'c':['b'], 'd':['c'], 'e':['d'], |
249 | - 'f':['e'], 'g':['e'], 'h':['f'], 'i':['h']} |
250 | +with_tail = {b'a':[NULL_REVISION], b'b':[b'a'], b'c':[b'b'], b'd':[b'c'], b'e':[b'd'], |
251 | + b'f':[b'e'], b'g':[b'e'], b'h':[b'f'], b'i':[b'h']} |
252 | |
253 | |
254 | class InstrumentedParentsProvider(object): |
255 | @@ -531,41 +531,41 @@ |
256 | self.assertEqual({NULL_REVISION}, |
257 | graph.find_lca(NULL_REVISION, NULL_REVISION)) |
258 | self.assertEqual({NULL_REVISION}, |
259 | - graph.find_lca(NULL_REVISION, 'rev1')) |
260 | - self.assertEqual({'rev1'}, graph.find_lca('rev1', 'rev1')) |
261 | - self.assertEqual({'rev1'}, graph.find_lca('rev2a', 'rev2b')) |
262 | + graph.find_lca(NULL_REVISION, b'rev1')) |
263 | + self.assertEqual({b'rev1'}, graph.find_lca(b'rev1', b'rev1')) |
264 | + self.assertEqual({b'rev1'}, graph.find_lca(b'rev2a', b'rev2b')) |
265 | |
266 | def test_no_unique_lca(self): |
267 | """Test error when one revision is not in the graph""" |
268 | graph = self.make_graph(ancestry_1) |
269 | self.assertRaises(errors.NoCommonAncestor, graph.find_unique_lca, |
270 | - 'rev1', '1rev') |
271 | + b'rev1', b'1rev') |
272 | |
273 | def test_lca_criss_cross(self): |
274 | """Test least-common-ancestor after a criss-cross merge.""" |
275 | graph = self.make_graph(criss_cross) |
276 | - self.assertEqual({'rev2a', 'rev2b'}, |
277 | - graph.find_lca('rev3a', 'rev3b')) |
278 | - self.assertEqual({'rev2b'}, |
279 | - graph.find_lca('rev3a', 'rev3b', 'rev2b')) |
280 | + self.assertEqual({b'rev2a', b'rev2b'}, |
281 | + graph.find_lca(b'rev3a', b'rev3b')) |
282 | + self.assertEqual({b'rev2b'}, |
283 | + graph.find_lca(b'rev3a', b'rev3b', b'rev2b')) |
284 | |
285 | def test_lca_shortcut(self): |
286 | """Test least-common ancestor on this history shortcut""" |
287 | graph = self.make_graph(history_shortcut) |
288 | - self.assertEqual({'rev2b'}, graph.find_lca('rev3a', 'rev3b')) |
289 | + self.assertEqual({b'rev2b'}, graph.find_lca(b'rev3a', b'rev3b')) |
290 | |
291 | def test_lefthand_distance_smoke(self): |
292 | """A simple does it work test for graph.lefthand_distance(keys).""" |
293 | graph = self.make_graph(history_shortcut) |
294 | - distance_graph = graph.find_lefthand_distances(['rev3b', 'rev2a']) |
295 | - self.assertEqual({'rev2a': 2, 'rev3b': 3}, distance_graph) |
296 | + distance_graph = graph.find_lefthand_distances([b'rev3b', b'rev2a']) |
297 | + self.assertEqual({b'rev2a': 2, b'rev3b': 3}, distance_graph) |
298 | |
299 | def test_lefthand_distance_ghosts(self): |
300 | """A simple does it work test for graph.lefthand_distance(keys).""" |
301 | - nodes = {'nonghost':[NULL_REVISION], 'toghost':['ghost']} |
302 | + nodes = {b'nonghost': [NULL_REVISION], b'toghost': [b'ghost']} |
303 | graph = self.make_graph(nodes) |
304 | - distance_graph = graph.find_lefthand_distances(['nonghost', 'toghost']) |
305 | - self.assertEqual({'nonghost': 1, 'toghost': -1}, distance_graph) |
306 | + distance_graph = graph.find_lefthand_distances([b'nonghost', b'toghost']) |
307 | + self.assertEqual({b'nonghost': 1, b'toghost': -1}, distance_graph) |
308 | |
309 | def test_recursive_unique_lca(self): |
310 | """Test finding a unique least common ancestor. |
311 | @@ -576,11 +576,11 @@ |
312 | self.assertEqual(NULL_REVISION, |
313 | graph.find_unique_lca(NULL_REVISION, NULL_REVISION)) |
314 | self.assertEqual(NULL_REVISION, |
315 | - graph.find_unique_lca(NULL_REVISION, 'rev1')) |
316 | - self.assertEqual('rev1', graph.find_unique_lca('rev1', 'rev1')) |
317 | - self.assertEqual('rev1', graph.find_unique_lca('rev2a', 'rev2b')) |
318 | - self.assertEqual(('rev1', 1,), |
319 | - graph.find_unique_lca('rev2a', 'rev2b', |
320 | + graph.find_unique_lca(NULL_REVISION, b'rev1')) |
321 | + self.assertEqual(b'rev1', graph.find_unique_lca(b'rev1', b'rev1')) |
322 | + self.assertEqual(b'rev1', graph.find_unique_lca(b'rev2a', b'rev2b')) |
323 | + self.assertEqual((b'rev1', 1,), |
324 | + graph.find_unique_lca(b'rev2a', b'rev2b', |
325 | count_steps=True)) |
326 | |
327 | def assertRemoveDescendants(self, expected, graph, revisions): |
328 | @@ -590,48 +590,48 @@ |
329 | |
330 | def test__remove_simple_descendants(self): |
331 | graph = self.make_graph(ancestry_1) |
332 | - self.assertRemoveDescendants({'rev1'}, graph, |
333 | - {'rev1', 'rev2a', 'rev2b', 'rev3', 'rev4'}) |
334 | + self.assertRemoveDescendants({b'rev1'}, graph, |
335 | + {b'rev1', b'rev2a', b'rev2b', b'rev3', b'rev4'}) |
336 | |
337 | def test__remove_simple_descendants_disjoint(self): |
338 | graph = self.make_graph(ancestry_1) |
339 | - self.assertRemoveDescendants({'rev1', 'rev3'}, graph, |
340 | - {'rev1', 'rev3'}) |
341 | + self.assertRemoveDescendants({b'rev1', b'rev3'}, graph, |
342 | + {b'rev1', b'rev3'}) |
343 | |
344 | def test__remove_simple_descendants_chain(self): |
345 | graph = self.make_graph(ancestry_1) |
346 | - self.assertRemoveDescendants({'rev1'}, graph, |
347 | - {'rev1', 'rev2a', 'rev3'}) |
348 | + self.assertRemoveDescendants({b'rev1'}, graph, |
349 | + {b'rev1', b'rev2a', b'rev3'}) |
350 | |
351 | def test__remove_simple_descendants_siblings(self): |
352 | graph = self.make_graph(ancestry_1) |
353 | - self.assertRemoveDescendants({'rev2a', 'rev2b'}, graph, |
354 | - {'rev2a', 'rev2b', 'rev3'}) |
355 | + self.assertRemoveDescendants({b'rev2a', b'rev2b'}, graph, |
356 | + {b'rev2a', b'rev2b', b'rev3'}) |
357 | |
358 | def test_unique_lca_criss_cross(self): |
359 | """Ensure we don't pick non-unique lcas in a criss-cross""" |
360 | graph = self.make_graph(criss_cross) |
361 | - self.assertEqual('rev1', graph.find_unique_lca('rev3a', 'rev3b')) |
362 | - lca, steps = graph.find_unique_lca('rev3a', 'rev3b', count_steps=True) |
363 | - self.assertEqual('rev1', lca) |
364 | + self.assertEqual(b'rev1', graph.find_unique_lca(b'rev3a', b'rev3b')) |
365 | + lca, steps = graph.find_unique_lca(b'rev3a', b'rev3b', count_steps=True) |
366 | + self.assertEqual(b'rev1', lca) |
367 | self.assertEqual(2, steps) |
368 | |
369 | def test_unique_lca_null_revision(self): |
370 | """Ensure we pick NULL_REVISION when necessary""" |
371 | graph = self.make_graph(criss_cross2) |
372 | - self.assertEqual('rev1b', graph.find_unique_lca('rev2a', 'rev1b')) |
373 | + self.assertEqual(b'rev1b', graph.find_unique_lca(b'rev2a', b'rev1b')) |
374 | self.assertEqual(NULL_REVISION, |
375 | - graph.find_unique_lca('rev2a', 'rev2b')) |
376 | + graph.find_unique_lca(b'rev2a', b'rev2b')) |
377 | |
378 | def test_unique_lca_null_revision2(self): |
379 | """Ensure we pick NULL_REVISION when necessary""" |
380 | graph = self.make_graph(ancestry_2) |
381 | self.assertEqual(NULL_REVISION, |
382 | - graph.find_unique_lca('rev4a', 'rev1b')) |
383 | + graph.find_unique_lca(b'rev4a', b'rev1b')) |
384 | |
385 | def test_lca_double_shortcut(self): |
386 | graph = self.make_graph(double_shortcut) |
387 | - self.assertEqual('c', graph.find_unique_lca('f', 'g')) |
388 | + self.assertEqual(b'c', graph.find_unique_lca(b'f', b'g')) |
389 | |
390 | def test_common_ancestor_two_repos(self): |
391 | """Ensure we do unique_lca using data from two repos""" |
392 | @@ -647,96 +647,96 @@ |
393 | |
394 | graph = mainline_tree.branch.repository.get_graph( |
395 | feature_tree.branch.repository) |
396 | - self.assertEqual('rev2b', graph.find_unique_lca('rev2a', 'rev3b')) |
397 | + self.assertEqual(b'rev2b', graph.find_unique_lca(b'rev2a', b'rev3b')) |
398 | |
399 | def test_graph_difference(self): |
400 | graph = self.make_graph(ancestry_1) |
401 | - self.assertEqual((set(), set()), graph.find_difference('rev1', 'rev1')) |
402 | - self.assertEqual((set(), {'rev1'}), |
403 | - graph.find_difference(NULL_REVISION, 'rev1')) |
404 | - self.assertEqual(({'rev1'}, set()), |
405 | - graph.find_difference('rev1', NULL_REVISION)) |
406 | - self.assertEqual(({'rev2a', 'rev3'}, {'rev2b'}), |
407 | - graph.find_difference('rev3', 'rev2b')) |
408 | - self.assertEqual(({'rev4', 'rev3', 'rev2a'}, set()), |
409 | - graph.find_difference('rev4', 'rev2b')) |
410 | + self.assertEqual((set(), set()), graph.find_difference(b'rev1', b'rev1')) |
411 | + self.assertEqual((set(), {b'rev1'}), |
412 | + graph.find_difference(NULL_REVISION, b'rev1')) |
413 | + self.assertEqual(({b'rev1'}, set()), |
414 | + graph.find_difference(b'rev1', NULL_REVISION)) |
415 | + self.assertEqual(({b'rev2a', b'rev3'}, {b'rev2b'}), |
416 | + graph.find_difference(b'rev3', b'rev2b')) |
417 | + self.assertEqual(({b'rev4', b'rev3', b'rev2a'}, set()), |
418 | + graph.find_difference(b'rev4', b'rev2b')) |
419 | |
420 | def test_graph_difference_separate_ancestry(self): |
421 | graph = self.make_graph(ancestry_2) |
422 | - self.assertEqual(({'rev1a'}, {'rev1b'}), |
423 | - graph.find_difference('rev1a', 'rev1b')) |
424 | - self.assertEqual(({'rev1a', 'rev2a', 'rev3a', 'rev4a'}, |
425 | - {'rev1b'}), |
426 | - graph.find_difference('rev4a', 'rev1b')) |
427 | + self.assertEqual(({b'rev1a'}, {b'rev1b'}), |
428 | + graph.find_difference(b'rev1a', b'rev1b')) |
429 | + self.assertEqual(({b'rev1a', b'rev2a', b'rev3a', b'rev4a'}, |
430 | + {b'rev1b'}), |
431 | + graph.find_difference(b'rev4a', b'rev1b')) |
432 | |
433 | def test_graph_difference_criss_cross(self): |
434 | graph = self.make_graph(criss_cross) |
435 | - self.assertEqual(({'rev3a'}, {'rev3b'}), |
436 | - graph.find_difference('rev3a', 'rev3b')) |
437 | - self.assertEqual((set([]), {'rev3b', 'rev2b'}), |
438 | - graph.find_difference('rev2a', 'rev3b')) |
439 | + self.assertEqual(({b'rev3a'}, {b'rev3b'}), |
440 | + graph.find_difference(b'rev3a', b'rev3b')) |
441 | + self.assertEqual((set([]), {b'rev3b', b'rev2b'}), |
442 | + graph.find_difference(b'rev2a', b'rev3b')) |
443 | |
444 | def test_graph_difference_extended_history(self): |
445 | graph = self.make_graph(extended_history_shortcut) |
446 | - self.assertEqual(({'e'}, {'f'}), |
447 | - graph.find_difference('e', 'f')) |
448 | - self.assertEqual(({'f'}, {'e'}), |
449 | - graph.find_difference('f', 'e')) |
450 | + self.assertEqual(({b'e'}, {b'f'}), |
451 | + graph.find_difference(b'e', b'f')) |
452 | + self.assertEqual(({b'f'}, {b'e'}), |
453 | + graph.find_difference(b'f', b'e')) |
454 | |
455 | def test_graph_difference_double_shortcut(self): |
456 | graph = self.make_graph(double_shortcut) |
457 | - self.assertEqual(({'d', 'f'}, {'e', 'g'}), |
458 | - graph.find_difference('f', 'g')) |
459 | + self.assertEqual(({b'd', b'f'}, {b'e', b'g'}), |
460 | + graph.find_difference(b'f', b'g')) |
461 | |
462 | def test_graph_difference_complex_shortcut(self): |
463 | graph = self.make_graph(complex_shortcut) |
464 | - self.assertEqual(({'m', 'i', 'e'}, {'n', 'h'}), |
465 | - graph.find_difference('m', 'n')) |
466 | + self.assertEqual(({b'm', b'i', b'e'}, {b'n', b'h'}), |
467 | + graph.find_difference(b'm', b'n')) |
468 | |
469 | def test_graph_difference_complex_shortcut2(self): |
470 | graph = self.make_graph(complex_shortcut2) |
471 | - self.assertEqual(({'t'}, {'j', 'u'}), |
472 | - graph.find_difference('t', 'u')) |
473 | + self.assertEqual(({b't'}, {b'j', b'u'}), |
474 | + graph.find_difference(b't', b'u')) |
475 | |
476 | def test_graph_difference_shortcut_extra_root(self): |
477 | graph = self.make_graph(shortcut_extra_root) |
478 | - self.assertEqual(({'e'}, {'f', 'g'}), |
479 | - graph.find_difference('e', 'f')) |
480 | + self.assertEqual(({b'e'}, {b'f', b'g'}), |
481 | + graph.find_difference(b'e', b'f')) |
482 | |
483 | def test_iter_topo_order(self): |
484 | graph = self.make_graph(ancestry_1) |
485 | - args = ['rev2a', 'rev3', 'rev1'] |
486 | + args = [b'rev2a', b'rev3', b'rev1'] |
487 | topo_args = list(graph.iter_topo_order(args)) |
488 | self.assertEqual(set(args), set(topo_args)) |
489 | - self.assertTrue(topo_args.index('rev2a') > topo_args.index('rev1')) |
490 | - self.assertTrue(topo_args.index('rev2a') < topo_args.index('rev3')) |
491 | + self.assertTrue(topo_args.index(b'rev2a') > topo_args.index(b'rev1')) |
492 | + self.assertTrue(topo_args.index(b'rev2a') < topo_args.index(b'rev3')) |
493 | |
494 | def test_is_ancestor(self): |
495 | graph = self.make_graph(ancestry_1) |
496 | - self.assertEqual(True, graph.is_ancestor('null:', 'null:')) |
497 | - self.assertEqual(True, graph.is_ancestor('null:', 'rev1')) |
498 | - self.assertEqual(False, graph.is_ancestor('rev1', 'null:')) |
499 | - self.assertEqual(True, graph.is_ancestor('null:', 'rev4')) |
500 | - self.assertEqual(False, graph.is_ancestor('rev4', 'null:')) |
501 | - self.assertEqual(False, graph.is_ancestor('rev4', 'rev2b')) |
502 | - self.assertEqual(True, graph.is_ancestor('rev2b', 'rev4')) |
503 | - self.assertEqual(False, graph.is_ancestor('rev2b', 'rev3')) |
504 | - self.assertEqual(False, graph.is_ancestor('rev3', 'rev2b')) |
505 | + self.assertEqual(True, graph.is_ancestor(b'null:', b'null:')) |
506 | + self.assertEqual(True, graph.is_ancestor(b'null:', b'rev1')) |
507 | + self.assertEqual(False, graph.is_ancestor(b'rev1', b'null:')) |
508 | + self.assertEqual(True, graph.is_ancestor(b'null:', b'rev4')) |
509 | + self.assertEqual(False, graph.is_ancestor(b'rev4', b'null:')) |
510 | + self.assertEqual(False, graph.is_ancestor(b'rev4', b'rev2b')) |
511 | + self.assertEqual(True, graph.is_ancestor(b'rev2b', b'rev4')) |
512 | + self.assertEqual(False, graph.is_ancestor(b'rev2b', b'rev3')) |
513 | + self.assertEqual(False, graph.is_ancestor(b'rev3', b'rev2b')) |
514 | instrumented_provider = InstrumentedParentsProvider(graph) |
515 | instrumented_graph = _mod_graph.Graph(instrumented_provider) |
516 | - instrumented_graph.is_ancestor('rev2a', 'rev2b') |
517 | - self.assertTrue('null:' not in instrumented_provider.calls) |
518 | + instrumented_graph.is_ancestor(b'rev2a', b'rev2b') |
519 | + self.assertTrue(b'null:' not in instrumented_provider.calls) |
520 | |
521 | def test_is_between(self): |
522 | graph = self.make_graph(ancestry_1) |
523 | - self.assertEqual(True, graph.is_between('null:', 'null:', 'null:')) |
524 | - self.assertEqual(True, graph.is_between('rev1', 'null:', 'rev1')) |
525 | - self.assertEqual(True, graph.is_between('rev1', 'rev1', 'rev4')) |
526 | - self.assertEqual(True, graph.is_between('rev4', 'rev1', 'rev4')) |
527 | - self.assertEqual(True, graph.is_between('rev3', 'rev1', 'rev4')) |
528 | - self.assertEqual(False, graph.is_between('rev4', 'rev1', 'rev3')) |
529 | - self.assertEqual(False, graph.is_between('rev1', 'rev2a', 'rev4')) |
530 | - self.assertEqual(False, graph.is_between('null:', 'rev1', 'rev4')) |
531 | + self.assertEqual(True, graph.is_between(b'null:', b'null:', b'null:')) |
532 | + self.assertEqual(True, graph.is_between(b'rev1', b'null:', b'rev1')) |
533 | + self.assertEqual(True, graph.is_between(b'rev1', b'rev1', b'rev4')) |
534 | + self.assertEqual(True, graph.is_between(b'rev4', b'rev1', b'rev4')) |
535 | + self.assertEqual(True, graph.is_between(b'rev3', b'rev1', b'rev4')) |
536 | + self.assertEqual(False, graph.is_between(b'rev4', b'rev1', b'rev3')) |
537 | + self.assertEqual(False, graph.is_between(b'rev1', b'rev2a', b'rev4')) |
538 | + self.assertEqual(False, graph.is_between(b'null:', b'rev1', b'rev4')) |
539 | |
540 | def test_is_ancestor_boundary(self): |
541 | """Ensure that we avoid searching the whole graph. |
542 | @@ -747,40 +747,40 @@ |
543 | graph = self.make_graph(boundary) |
544 | instrumented_provider = InstrumentedParentsProvider(graph) |
545 | graph = _mod_graph.Graph(instrumented_provider) |
546 | - self.assertFalse(graph.is_ancestor('a', 'c')) |
547 | - self.assertTrue('null:' not in instrumented_provider.calls) |
548 | + self.assertFalse(graph.is_ancestor(b'a', b'c')) |
549 | + self.assertTrue(b'null:' not in instrumented_provider.calls) |
550 | |
551 | def test_iter_ancestry(self): |
552 | nodes = boundary.copy() |
553 | nodes[NULL_REVISION] = () |
554 | graph = self.make_graph(nodes) |
555 | expected = nodes.copy() |
556 | - expected.pop('a') # 'a' is not in the ancestry of 'c', all the |
557 | + expected.pop(b'a') # b'a' is not in the ancestry of b'c', all the |
558 | # other nodes are |
559 | - self.assertEqual(expected, dict(graph.iter_ancestry(['c']))) |
560 | - self.assertEqual(nodes, dict(graph.iter_ancestry(['a', 'c']))) |
561 | + self.assertEqual(expected, dict(graph.iter_ancestry([b'c']))) |
562 | + self.assertEqual(nodes, dict(graph.iter_ancestry([b'a', b'c']))) |
563 | |
564 | def test_iter_ancestry_with_ghost(self): |
565 | graph = self.make_graph(with_ghost) |
566 | expected = with_ghost.copy() |
567 | - # 'a' is not in the ancestry of 'c', and 'g' is a ghost |
568 | - expected['g'] = None |
569 | - self.assertEqual(expected, dict(graph.iter_ancestry(['a', 'c']))) |
570 | - expected.pop('a') |
571 | - self.assertEqual(expected, dict(graph.iter_ancestry(['c']))) |
572 | + # b'a' is not in the ancestry of b'c', and b'g' is a ghost |
573 | + expected[b'g'] = None |
574 | + self.assertEqual(expected, dict(graph.iter_ancestry([b'a', b'c']))) |
575 | + expected.pop(b'a') |
576 | + self.assertEqual(expected, dict(graph.iter_ancestry([b'c']))) |
577 | |
578 | def test_filter_candidate_lca(self): |
579 | """Test filter_candidate_lca for a corner case |
580 | |
581 | - This tests the case where we encounter the end of iteration for 'e' |
582 | - in the same pass as we discover that 'd' is an ancestor of 'e', and |
583 | - therefore 'e' can't be an lca. |
584 | + This tests the case where we encounter the end of iteration for b'e' |
585 | + in the same pass as we discover that b'd' is an ancestor of b'e', and |
586 | + therefore b'e' can't be an lca. |
587 | |
588 | To compensate for different dict orderings on other Python |
589 | - implementations, we mirror 'd' and 'e' with 'b' and 'a'. |
590 | + implementations, we mirror b'd' and b'e' with b'b' and b'a'. |
591 | """ |
592 | # This test is sensitive to the iteration order of dicts. It will |
593 | - # pass incorrectly if 'e' and 'a' sort before 'c' |
594 | + # pass incorrectly if b'e' and b'a' sort before b'c' |
595 | # |
596 | # NULL_REVISION |
597 | # / \ |
598 | @@ -789,100 +789,100 @@ |
599 | # b d |
600 | # \ / |
601 | # c |
602 | - graph = self.make_graph({'c': ['b', 'd'], 'd': ['e'], 'b': ['a'], |
603 | - 'a': [NULL_REVISION], 'e': [NULL_REVISION]}) |
604 | - self.assertEqual({'c'}, graph.heads(['a', 'c', 'e'])) |
605 | + graph = self.make_graph({b'c': [b'b', b'd'], b'd': [b'e'], b'b': [b'a'], |
606 | + b'a': [NULL_REVISION], b'e': [NULL_REVISION]}) |
607 | + self.assertEqual({b'c'}, graph.heads([b'a', b'c', b'e'])) |
608 | |
609 | def test_heads_null(self): |
610 | graph = self.make_graph(ancestry_1) |
611 | - self.assertEqual({'null:'}, graph.heads(['null:'])) |
612 | - self.assertEqual({'rev1'}, graph.heads(['null:', 'rev1'])) |
613 | - self.assertEqual({'rev1'}, graph.heads(['rev1', 'null:'])) |
614 | - self.assertEqual({'rev1'}, graph.heads({'rev1', 'null:'})) |
615 | - self.assertEqual({'rev1'}, graph.heads(('rev1', 'null:'))) |
616 | + self.assertEqual({b'null:'}, graph.heads([b'null:'])) |
617 | + self.assertEqual({b'rev1'}, graph.heads([b'null:', b'rev1'])) |
618 | + self.assertEqual({b'rev1'}, graph.heads([b'rev1', b'null:'])) |
619 | + self.assertEqual({b'rev1'}, graph.heads({b'rev1', b'null:'})) |
620 | + self.assertEqual({b'rev1'}, graph.heads((b'rev1', b'null:'))) |
621 | |
622 | def test_heads_one(self): |
623 | # A single node will always be a head |
624 | graph = self.make_graph(ancestry_1) |
625 | - self.assertEqual({'null:'}, graph.heads(['null:'])) |
626 | - self.assertEqual({'rev1'}, graph.heads(['rev1'])) |
627 | - self.assertEqual({'rev2a'}, graph.heads(['rev2a'])) |
628 | - self.assertEqual({'rev2b'}, graph.heads(['rev2b'])) |
629 | - self.assertEqual({'rev3'}, graph.heads(['rev3'])) |
630 | - self.assertEqual({'rev4'}, graph.heads(['rev4'])) |
631 | + self.assertEqual({b'null:'}, graph.heads([b'null:'])) |
632 | + self.assertEqual({b'rev1'}, graph.heads([b'rev1'])) |
633 | + self.assertEqual({b'rev2a'}, graph.heads([b'rev2a'])) |
634 | + self.assertEqual({b'rev2b'}, graph.heads([b'rev2b'])) |
635 | + self.assertEqual({b'rev3'}, graph.heads([b'rev3'])) |
636 | + self.assertEqual({b'rev4'}, graph.heads([b'rev4'])) |
637 | |
638 | def test_heads_single(self): |
639 | graph = self.make_graph(ancestry_1) |
640 | - self.assertEqual({'rev4'}, graph.heads(['null:', 'rev4'])) |
641 | - self.assertEqual({'rev2a'}, graph.heads(['rev1', 'rev2a'])) |
642 | - self.assertEqual({'rev2b'}, graph.heads(['rev1', 'rev2b'])) |
643 | - self.assertEqual({'rev3'}, graph.heads(['rev1', 'rev3'])) |
644 | - self.assertEqual({'rev4'}, graph.heads(['rev1', 'rev4'])) |
645 | - self.assertEqual({'rev4'}, graph.heads(['rev2a', 'rev4'])) |
646 | - self.assertEqual({'rev4'}, graph.heads(['rev2b', 'rev4'])) |
647 | - self.assertEqual({'rev4'}, graph.heads(['rev3', 'rev4'])) |
648 | + self.assertEqual({b'rev4'}, graph.heads([b'null:', b'rev4'])) |
649 | + self.assertEqual({b'rev2a'}, graph.heads([b'rev1', b'rev2a'])) |
650 | + self.assertEqual({b'rev2b'}, graph.heads([b'rev1', b'rev2b'])) |
651 | + self.assertEqual({b'rev3'}, graph.heads([b'rev1', b'rev3'])) |
652 | + self.assertEqual({b'rev4'}, graph.heads([b'rev1', b'rev4'])) |
653 | + self.assertEqual({b'rev4'}, graph.heads([b'rev2a', b'rev4'])) |
654 | + self.assertEqual({b'rev4'}, graph.heads([b'rev2b', b'rev4'])) |
655 | + self.assertEqual({b'rev4'}, graph.heads([b'rev3', b'rev4'])) |
656 | |
657 | def test_heads_two_heads(self): |
658 | graph = self.make_graph(ancestry_1) |
659 | - self.assertEqual({'rev2a', 'rev2b'}, |
660 | - graph.heads(['rev2a', 'rev2b'])) |
661 | - self.assertEqual({'rev3', 'rev2b'}, |
662 | - graph.heads(['rev3', 'rev2b'])) |
663 | + self.assertEqual({b'rev2a', b'rev2b'}, |
664 | + graph.heads([b'rev2a', b'rev2b'])) |
665 | + self.assertEqual({b'rev3', b'rev2b'}, |
666 | + graph.heads([b'rev3', b'rev2b'])) |
667 | |
668 | def test_heads_criss_cross(self): |
669 | graph = self.make_graph(criss_cross) |
670 | - self.assertEqual({'rev2a'}, |
671 | - graph.heads(['rev2a', 'rev1'])) |
672 | - self.assertEqual({'rev2b'}, |
673 | - graph.heads(['rev2b', 'rev1'])) |
674 | - self.assertEqual({'rev3a'}, |
675 | - graph.heads(['rev3a', 'rev1'])) |
676 | - self.assertEqual({'rev3b'}, |
677 | - graph.heads(['rev3b', 'rev1'])) |
678 | - self.assertEqual({'rev2a', 'rev2b'}, |
679 | - graph.heads(['rev2a', 'rev2b'])) |
680 | - self.assertEqual({'rev3a'}, |
681 | - graph.heads(['rev3a', 'rev2a'])) |
682 | - self.assertEqual({'rev3a'}, |
683 | - graph.heads(['rev3a', 'rev2b'])) |
684 | - self.assertEqual({'rev3a'}, |
685 | - graph.heads(['rev3a', 'rev2a', 'rev2b'])) |
686 | - self.assertEqual({'rev3b'}, |
687 | - graph.heads(['rev3b', 'rev2a'])) |
688 | - self.assertEqual({'rev3b'}, |
689 | - graph.heads(['rev3b', 'rev2b'])) |
690 | - self.assertEqual({'rev3b'}, |
691 | - graph.heads(['rev3b', 'rev2a', 'rev2b'])) |
692 | - self.assertEqual({'rev3a', 'rev3b'}, |
693 | - graph.heads(['rev3a', 'rev3b'])) |
694 | - self.assertEqual({'rev3a', 'rev3b'}, |
695 | - graph.heads(['rev3a', 'rev3b', 'rev2a', 'rev2b'])) |
696 | + self.assertEqual({b'rev2a'}, |
697 | + graph.heads([b'rev2a', b'rev1'])) |
698 | + self.assertEqual({b'rev2b'}, |
699 | + graph.heads([b'rev2b', b'rev1'])) |
700 | + self.assertEqual({b'rev3a'}, |
701 | + graph.heads([b'rev3a', b'rev1'])) |
702 | + self.assertEqual({b'rev3b'}, |
703 | + graph.heads([b'rev3b', b'rev1'])) |
704 | + self.assertEqual({b'rev2a', b'rev2b'}, |
705 | + graph.heads([b'rev2a', b'rev2b'])) |
706 | + self.assertEqual({b'rev3a'}, |
707 | + graph.heads([b'rev3a', b'rev2a'])) |
708 | + self.assertEqual({b'rev3a'}, |
709 | + graph.heads([b'rev3a', b'rev2b'])) |
710 | + self.assertEqual({b'rev3a'}, |
711 | + graph.heads([b'rev3a', b'rev2a', b'rev2b'])) |
712 | + self.assertEqual({b'rev3b'}, |
713 | + graph.heads([b'rev3b', b'rev2a'])) |
714 | + self.assertEqual({b'rev3b'}, |
715 | + graph.heads([b'rev3b', b'rev2b'])) |
716 | + self.assertEqual({b'rev3b'}, |
717 | + graph.heads([b'rev3b', b'rev2a', b'rev2b'])) |
718 | + self.assertEqual({b'rev3a', b'rev3b'}, |
719 | + graph.heads([b'rev3a', b'rev3b'])) |
720 | + self.assertEqual({b'rev3a', b'rev3b'}, |
721 | + graph.heads([b'rev3a', b'rev3b', b'rev2a', b'rev2b'])) |
722 | |
723 | def test_heads_shortcut(self): |
724 | graph = self.make_graph(history_shortcut) |
725 | |
726 | - self.assertEqual({'rev2a', 'rev2b', 'rev2c'}, |
727 | - graph.heads(['rev2a', 'rev2b', 'rev2c'])) |
728 | - self.assertEqual({'rev3a', 'rev3b'}, |
729 | - graph.heads(['rev3a', 'rev3b'])) |
730 | - self.assertEqual({'rev3a', 'rev3b'}, |
731 | - graph.heads(['rev2a', 'rev3a', 'rev3b'])) |
732 | - self.assertEqual({'rev2a', 'rev3b'}, |
733 | - graph.heads(['rev2a', 'rev3b'])) |
734 | - self.assertEqual({'rev2c', 'rev3a'}, |
735 | - graph.heads(['rev2c', 'rev3a'])) |
736 | + self.assertEqual({b'rev2a', b'rev2b', b'rev2c'}, |
737 | + graph.heads([b'rev2a', b'rev2b', b'rev2c'])) |
738 | + self.assertEqual({b'rev3a', b'rev3b'}, |
739 | + graph.heads([b'rev3a', b'rev3b'])) |
740 | + self.assertEqual({b'rev3a', b'rev3b'}, |
741 | + graph.heads([b'rev2a', b'rev3a', b'rev3b'])) |
742 | + self.assertEqual({b'rev2a', b'rev3b'}, |
743 | + graph.heads([b'rev2a', b'rev3b'])) |
744 | + self.assertEqual({b'rev2c', b'rev3a'}, |
745 | + graph.heads([b'rev2c', b'rev3a'])) |
746 | |
747 | def _run_heads_break_deeper(self, graph_dict, search): |
748 | """Run heads on a graph-as-a-dict. |
749 | |
750 | - If the search asks for the parents of 'deeper' the test will fail. |
751 | + If the search asks for the parents of b'deeper' the test will fail. |
752 | """ |
753 | class stub(object): |
754 | pass |
755 | def get_parent_map(keys): |
756 | result = {} |
757 | for key in keys: |
758 | - if key == 'deeper': |
759 | + if key == b'deeper': |
760 | self.fail('key deeper was accessed') |
761 | result[key] = graph_dict[key] |
762 | return result |
763 | @@ -894,67 +894,67 @@ |
764 | def test_heads_limits_search(self): |
765 | # test that a heads query does not search all of history |
766 | graph_dict = { |
767 | - 'left': ['common'], |
768 | - 'right': ['common'], |
769 | - 'common': ['deeper'], |
770 | + b'left': [b'common'], |
771 | + b'right': [b'common'], |
772 | + b'common': [b'deeper'], |
773 | } |
774 | - self.assertEqual({'left', 'right'}, |
775 | - self._run_heads_break_deeper(graph_dict, ['left', 'right'])) |
776 | + self.assertEqual({b'left', b'right'}, |
777 | + self._run_heads_break_deeper(graph_dict, [b'left', b'right'])) |
778 | |
779 | def test_heads_limits_search_assymetric(self): |
780 | # test that a heads query does not search all of history |
781 | graph_dict = { |
782 | - 'left': ['midleft'], |
783 | - 'midleft': ['common'], |
784 | - 'right': ['common'], |
785 | - 'common': ['aftercommon'], |
786 | - 'aftercommon': ['deeper'], |
787 | + b'left': [b'midleft'], |
788 | + b'midleft': [b'common'], |
789 | + b'right': [b'common'], |
790 | + b'common': [b'aftercommon'], |
791 | + b'aftercommon': [b'deeper'], |
792 | } |
793 | - self.assertEqual({'left', 'right'}, |
794 | - self._run_heads_break_deeper(graph_dict, ['left', 'right'])) |
795 | + self.assertEqual({b'left', b'right'}, |
796 | + self._run_heads_break_deeper(graph_dict, [b'left', b'right'])) |
797 | |
798 | def test_heads_limits_search_common_search_must_continue(self): |
799 | # test that common nodes are still queried, preventing |
800 | # all-the-way-to-origin behaviour in the following graph: |
801 | graph_dict = { |
802 | - 'h1': ['shortcut', 'common1'], |
803 | - 'h2': ['common1'], |
804 | - 'shortcut': ['common2'], |
805 | - 'common1': ['common2'], |
806 | - 'common2': ['deeper'], |
807 | + b'h1': [b'shortcut', b'common1'], |
808 | + b'h2': [b'common1'], |
809 | + b'shortcut': [b'common2'], |
810 | + b'common1': [b'common2'], |
811 | + b'common2': [b'deeper'], |
812 | } |
813 | - self.assertEqual({'h1', 'h2'}, |
814 | - self._run_heads_break_deeper(graph_dict, ['h1', 'h2'])) |
815 | + self.assertEqual({b'h1', b'h2'}, |
816 | + self._run_heads_break_deeper(graph_dict, [b'h1', b'h2'])) |
817 | |
818 | def test_breadth_first_search_start_ghosts(self): |
819 | graph = self.make_graph({}) |
820 | # with_ghosts reports the ghosts |
821 | - search = graph._make_breadth_first_searcher(['a-ghost']) |
822 | - self.assertEqual((set(), {'a-ghost'}), search.next_with_ghosts()) |
823 | + search = graph._make_breadth_first_searcher([b'a-ghost']) |
824 | + self.assertEqual((set(), {b'a-ghost'}), search.next_with_ghosts()) |
825 | self.assertRaises(StopIteration, search.next_with_ghosts) |
826 | # next includes them |
827 | - search = graph._make_breadth_first_searcher(['a-ghost']) |
828 | - self.assertEqual({'a-ghost'}, next(search)) |
829 | + search = graph._make_breadth_first_searcher([b'a-ghost']) |
830 | + self.assertEqual({b'a-ghost'}, next(search)) |
831 | self.assertRaises(StopIteration, next, search) |
832 | |
833 | def test_breadth_first_search_deep_ghosts(self): |
834 | graph = self.make_graph({ |
835 | - 'head': ['present'], |
836 | - 'present': ['child', 'ghost'], |
837 | - 'child': [], |
838 | + b'head': [b'present'], |
839 | + b'present': [b'child', b'ghost'], |
840 | + b'child': [], |
841 | }) |
842 | # with_ghosts reports the ghosts |
843 | - search = graph._make_breadth_first_searcher(['head']) |
844 | - self.assertEqual(({'head'}, set()), search.next_with_ghosts()) |
845 | - self.assertEqual(({'present'}, set()), search.next_with_ghosts()) |
846 | - self.assertEqual(({'child'}, {'ghost'}), |
847 | + search = graph._make_breadth_first_searcher([b'head']) |
848 | + self.assertEqual(({b'head'}, set()), search.next_with_ghosts()) |
849 | + self.assertEqual(({b'present'}, set()), search.next_with_ghosts()) |
850 | + self.assertEqual(({b'child'}, {b'ghost'}), |
851 | search.next_with_ghosts()) |
852 | self.assertRaises(StopIteration, search.next_with_ghosts) |
853 | # next includes them |
854 | - search = graph._make_breadth_first_searcher(['head']) |
855 | - self.assertEqual({'head'}, next(search)) |
856 | - self.assertEqual({'present'}, next(search)) |
857 | - self.assertEqual({'child', 'ghost'}, |
858 | + search = graph._make_breadth_first_searcher([b'head']) |
859 | + self.assertEqual({b'head'}, next(search)) |
860 | + self.assertEqual({b'present'}, next(search)) |
861 | + self.assertEqual({b'child', b'ghost'}, |
862 | next(search)) |
863 | self.assertRaises(StopIteration, next, search) |
864 | |
865 | @@ -962,50 +962,50 @@ |
866 | # To make the API robust, we allow calling both next() and |
867 | # next_with_ghosts() on the same searcher. |
868 | graph = self.make_graph({ |
869 | - 'head': ['present'], |
870 | - 'present': ['child', 'ghost'], |
871 | - 'child': [], |
872 | + b'head': [b'present'], |
873 | + b'present': [b'child', b'ghost'], |
874 | + b'child': [], |
875 | }) |
876 | # start with next_with_ghosts |
877 | - search = graph._make_breadth_first_searcher(['head']) |
878 | - self.assertEqual(({'head'}, set()), search.next_with_ghosts()) |
879 | - self.assertEqual({'present'}, next(search)) |
880 | - self.assertEqual(({'child'}, {'ghost'}), |
881 | + search = graph._make_breadth_first_searcher([b'head']) |
882 | + self.assertEqual(({b'head'}, set()), search.next_with_ghosts()) |
883 | + self.assertEqual({b'present'}, next(search)) |
884 | + self.assertEqual(({b'child'}, {b'ghost'}), |
885 | search.next_with_ghosts()) |
886 | self.assertRaises(StopIteration, next, search) |
887 | # start with next |
888 | - search = graph._make_breadth_first_searcher(['head']) |
889 | - self.assertEqual({'head'}, next(search)) |
890 | - self.assertEqual(({'present'}, set()), search.next_with_ghosts()) |
891 | - self.assertEqual({'child', 'ghost'}, |
892 | + search = graph._make_breadth_first_searcher([b'head']) |
893 | + self.assertEqual({b'head'}, next(search)) |
894 | + self.assertEqual(({b'present'}, set()), search.next_with_ghosts()) |
895 | + self.assertEqual({b'child', b'ghost'}, |
896 | next(search)) |
897 | self.assertRaises(StopIteration, search.next_with_ghosts) |
898 | |
899 | def test_breadth_first_change_search(self): |
900 | # Changing the search should work with both next and next_with_ghosts. |
901 | graph = self.make_graph({ |
902 | - 'head': ['present'], |
903 | - 'present': ['stopped'], |
904 | - 'other': ['other_2'], |
905 | - 'other_2': [], |
906 | + b'head': [b'present'], |
907 | + b'present': [b'stopped'], |
908 | + b'other': [b'other_2'], |
909 | + b'other_2': [], |
910 | }) |
911 | - search = graph._make_breadth_first_searcher(['head']) |
912 | - self.assertEqual(({'head'}, set()), search.next_with_ghosts()) |
913 | - self.assertEqual(({'present'}, set()), search.next_with_ghosts()) |
914 | - self.assertEqual({'present'}, |
915 | - search.stop_searching_any(['present'])) |
916 | - self.assertEqual(({'other'}, {'other_ghost'}), |
917 | - search.start_searching(['other', 'other_ghost'])) |
918 | - self.assertEqual(({'other_2'}, set()), search.next_with_ghosts()) |
919 | + search = graph._make_breadth_first_searcher([b'head']) |
920 | + self.assertEqual(({b'head'}, set()), search.next_with_ghosts()) |
921 | + self.assertEqual(({b'present'}, set()), search.next_with_ghosts()) |
922 | + self.assertEqual({b'present'}, |
923 | + search.stop_searching_any([b'present'])) |
924 | + self.assertEqual(({b'other'}, {b'other_ghost'}), |
925 | + search.start_searching([b'other', b'other_ghost'])) |
926 | + self.assertEqual(({b'other_2'}, set()), search.next_with_ghosts()) |
927 | self.assertRaises(StopIteration, search.next_with_ghosts) |
928 | # next includes them |
929 | - search = graph._make_breadth_first_searcher(['head']) |
930 | - self.assertEqual({'head'}, next(search)) |
931 | - self.assertEqual({'present'}, next(search)) |
932 | - self.assertEqual({'present'}, |
933 | - search.stop_searching_any(['present'])) |
934 | - search.start_searching(['other', 'other_ghost']) |
935 | - self.assertEqual({'other_2'}, next(search)) |
936 | + search = graph._make_breadth_first_searcher([b'head']) |
937 | + self.assertEqual({b'head'}, next(search)) |
938 | + self.assertEqual({b'present'}, next(search)) |
939 | + self.assertEqual({b'present'}, |
940 | + search.stop_searching_any([b'present'])) |
941 | + search.start_searching([b'other', b'other_ghost']) |
942 | + self.assertEqual({b'other_2'}, next(search)) |
943 | self.assertRaises(StopIteration, next, search) |
944 | |
945 | def assertSeenAndResult(self, instructions, search, next): |
946 | @@ -1035,216 +1035,216 @@ |
947 | |
948 | def test_breadth_first_get_result_excludes_current_pending(self): |
949 | graph = self.make_graph({ |
950 | - 'head': ['child'], |
951 | - 'child': [NULL_REVISION], |
952 | + b'head': [b'child'], |
953 | + b'child': [NULL_REVISION], |
954 | NULL_REVISION: [], |
955 | }) |
956 | - search = graph._make_breadth_first_searcher(['head']) |
957 | + search = graph._make_breadth_first_searcher([b'head']) |
958 | # At the start, nothing has been seen, to its all excluded: |
959 | state = search.get_state() |
960 | - self.assertEqual(({'head'}, {'head'}, set()), |
961 | + self.assertEqual(({b'head'}, {b'head'}, set()), |
962 | state) |
963 | self.assertEqual(set(), search.seen) |
964 | # using next: |
965 | expected = [ |
966 | - ({'head'}, ({'head'}, {'child'}, 1), |
967 | - ['head'], None, None), |
968 | - ({'head', 'child'}, ({'head'}, {NULL_REVISION}, 2), |
969 | - ['head', 'child'], None, None), |
970 | - ({'head', 'child', NULL_REVISION}, ({'head'}, set(), 3), |
971 | - ['head', 'child', NULL_REVISION], None, None), |
972 | + ({b'head'}, ({b'head'}, {b'child'}, 1), |
973 | + [b'head'], None, None), |
974 | + ({b'head', b'child'}, ({b'head'}, {NULL_REVISION}, 2), |
975 | + [b'head', b'child'], None, None), |
976 | + ({b'head', b'child', NULL_REVISION}, ({b'head'}, set(), 3), |
977 | + [b'head', b'child', NULL_REVISION], None, None), |
978 | ] |
979 | self.assertSeenAndResult(expected, search, search.__next__) |
980 | # using next_with_ghosts: |
981 | - search = graph._make_breadth_first_searcher(['head']) |
982 | + search = graph._make_breadth_first_searcher([b'head']) |
983 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
984 | |
985 | def test_breadth_first_get_result_starts_stops(self): |
986 | graph = self.make_graph({ |
987 | - 'head':['child'], |
988 | - 'child':[NULL_REVISION], |
989 | - 'otherhead':['otherchild'], |
990 | - 'otherchild':['excluded'], |
991 | - 'excluded':[NULL_REVISION], |
992 | + b'head':[b'child'], |
993 | + b'child':[NULL_REVISION], |
994 | + b'otherhead':[b'otherchild'], |
995 | + b'otherchild':[b'excluded'], |
996 | + b'excluded':[NULL_REVISION], |
997 | NULL_REVISION:[] |
998 | }) |
999 | search = graph._make_breadth_first_searcher([]) |
1000 | # Starting with nothing and adding a search works: |
1001 | - search.start_searching(['head']) |
1002 | + search.start_searching([b'head']) |
1003 | # head has been seen: |
1004 | state = search.get_state() |
1005 | - self.assertEqual(({'head'}, {'child'}, {'head'}), |
1006 | + self.assertEqual(({b'head'}, {b'child'}, {b'head'}), |
1007 | state) |
1008 | - self.assertEqual({'head'}, search.seen) |
1009 | + self.assertEqual({b'head'}, search.seen) |
1010 | # using next: |
1011 | expected = [ |
1012 | # stop at child, and start a new search at otherhead: |
1013 | # - otherhead counts as seen immediately when start_searching is |
1014 | # called. |
1015 | - ({'head', 'child', 'otherhead'}, |
1016 | - ({'head', 'otherhead'}, {'child', 'otherchild'}, 2), |
1017 | - ['head', 'otherhead'], ['otherhead'], ['child']), |
1018 | - ({'head', 'child', 'otherhead', 'otherchild'}, |
1019 | - ({'head', 'otherhead'}, {'child', 'excluded'}, 3), |
1020 | - ['head', 'otherhead', 'otherchild'], None, None), |
1021 | + ({b'head', b'child', b'otherhead'}, |
1022 | + ({b'head', b'otherhead'}, {b'child', b'otherchild'}, 2), |
1023 | + [b'head', b'otherhead'], [b'otherhead'], [b'child']), |
1024 | + ({b'head', b'child', b'otherhead', b'otherchild'}, |
1025 | + ({b'head', b'otherhead'}, {b'child', b'excluded'}, 3), |
1026 | + [b'head', b'otherhead', b'otherchild'], None, None), |
1027 | # stop searching excluded now |
1028 | - ({'head', 'child', 'otherhead', 'otherchild', 'excluded'}, |
1029 | - ({'head', 'otherhead'}, {'child', 'excluded'}, 3), |
1030 | - ['head', 'otherhead', 'otherchild'], None, ['excluded']), |
1031 | + ({b'head', b'child', b'otherhead', b'otherchild', b'excluded'}, |
1032 | + ({b'head', b'otherhead'}, {b'child', b'excluded'}, 3), |
1033 | + [b'head', b'otherhead', b'otherchild'], None, [b'excluded']), |
1034 | ] |
1035 | self.assertSeenAndResult(expected, search, search.__next__) |
1036 | # using next_with_ghosts: |
1037 | search = graph._make_breadth_first_searcher([]) |
1038 | - search.start_searching(['head']) |
1039 | + search.start_searching([b'head']) |
1040 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1041 | |
1042 | def test_breadth_first_stop_searching_not_queried(self): |
1043 | - # A client should be able to say 'stop node X' even if X has not been |
1044 | + # A client should be able to say b'stop node X' even if X has not been |
1045 | # returned to the client. |
1046 | graph = self.make_graph({ |
1047 | - 'head': ['child', 'ghost1'], |
1048 | - 'child': [NULL_REVISION], |
1049 | + b'head': [b'child', b'ghost1'], |
1050 | + b'child': [NULL_REVISION], |
1051 | NULL_REVISION: [], |
1052 | }) |
1053 | - search = graph._make_breadth_first_searcher(['head']) |
1054 | + search = graph._make_breadth_first_searcher([b'head']) |
1055 | expected = [ |
1056 | # NULL_REVISION and ghost1 have not been returned |
1057 | - ({'head'}, |
1058 | - ({'head'}, {'child', NULL_REVISION, 'ghost1'}, 1), |
1059 | - ['head'], None, [NULL_REVISION, 'ghost1']), |
1060 | + ({b'head'}, |
1061 | + ({b'head'}, {b'child', NULL_REVISION, b'ghost1'}, 1), |
1062 | + [b'head'], None, [NULL_REVISION, b'ghost1']), |
1063 | # ghost1 has been returned, NULL_REVISION is to be returned in the |
1064 | # next iteration. |
1065 | - ({'head', 'child', 'ghost1'}, |
1066 | - ({'head'}, {'ghost1', NULL_REVISION}, 2), |
1067 | - ['head', 'child'], None, [NULL_REVISION, 'ghost1']), |
1068 | + ({b'head', b'child', b'ghost1'}, |
1069 | + ({b'head'}, {b'ghost1', NULL_REVISION}, 2), |
1070 | + [b'head', b'child'], None, [NULL_REVISION, b'ghost1']), |
1071 | ] |
1072 | self.assertSeenAndResult(expected, search, search.__next__) |
1073 | # using next_with_ghosts: |
1074 | - search = graph._make_breadth_first_searcher(['head']) |
1075 | + search = graph._make_breadth_first_searcher([b'head']) |
1076 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1077 | |
1078 | def test_breadth_first_stop_searching_late(self): |
1079 | - # A client should be able to say 'stop node X' and have it excluded |
1080 | + # A client should be able to say b'stop node X' and have it excluded |
1081 | # from the result even if X was seen in an older iteration of the |
1082 | # search. |
1083 | graph = self.make_graph({ |
1084 | - 'head': ['middle'], |
1085 | - 'middle': ['child'], |
1086 | - 'child': [NULL_REVISION], |
1087 | + b'head': [b'middle'], |
1088 | + b'middle': [b'child'], |
1089 | + b'child': [NULL_REVISION], |
1090 | NULL_REVISION: [], |
1091 | }) |
1092 | - search = graph._make_breadth_first_searcher(['head']) |
1093 | + search = graph._make_breadth_first_searcher([b'head']) |
1094 | expected = [ |
1095 | - ({'head'}, ({'head'}, {'middle'}, 1), |
1096 | - ['head'], None, None), |
1097 | - ({'head', 'middle'}, ({'head'}, {'child'}, 2), |
1098 | - ['head', 'middle'], None, None), |
1099 | - # 'middle' came from the previous iteration, but we don't stop |
1100 | + ({b'head'}, ({b'head'}, {b'middle'}, 1), |
1101 | + [b'head'], None, None), |
1102 | + ({b'head', b'middle'}, ({b'head'}, {b'child'}, 2), |
1103 | + [b'head', b'middle'], None, None), |
1104 | + # b'middle' came from the previous iteration, but we don't stop |
1105 | # searching it until *after* advancing the searcher. |
1106 | - ({'head', 'middle', 'child'}, |
1107 | - ({'head'}, {'middle', 'child'}, 1), |
1108 | - ['head'], None, ['middle', 'child']), |
1109 | + ({b'head', b'middle', b'child'}, |
1110 | + ({b'head'}, {b'middle', b'child'}, 1), |
1111 | + [b'head'], None, [b'middle', b'child']), |
1112 | ] |
1113 | self.assertSeenAndResult(expected, search, search.__next__) |
1114 | # using next_with_ghosts: |
1115 | - search = graph._make_breadth_first_searcher(['head']) |
1116 | + search = graph._make_breadth_first_searcher([b'head']) |
1117 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1118 | |
1119 | def test_breadth_first_get_result_ghosts_are_excluded(self): |
1120 | graph = self.make_graph({ |
1121 | - 'head': ['child', 'ghost'], |
1122 | - 'child': [NULL_REVISION], |
1123 | + b'head': [b'child', b'ghost'], |
1124 | + b'child': [NULL_REVISION], |
1125 | NULL_REVISION: [], |
1126 | }) |
1127 | - search = graph._make_breadth_first_searcher(['head']) |
1128 | + search = graph._make_breadth_first_searcher([b'head']) |
1129 | # using next: |
1130 | expected = [ |
1131 | - ({'head'}, |
1132 | - ({'head'}, {'ghost', 'child'}, 1), |
1133 | - ['head'], None, None), |
1134 | - ({'head', 'child', 'ghost'}, |
1135 | - ({'head'}, {NULL_REVISION, 'ghost'}, 2), |
1136 | - ['head', 'child'], None, None), |
1137 | + ({b'head'}, |
1138 | + ({b'head'}, {b'ghost', b'child'}, 1), |
1139 | + [b'head'], None, None), |
1140 | + ({b'head', b'child', b'ghost'}, |
1141 | + ({b'head'}, {NULL_REVISION, b'ghost'}, 2), |
1142 | + [b'head', b'child'], None, None), |
1143 | ] |
1144 | self.assertSeenAndResult(expected, search, search.__next__) |
1145 | # using next_with_ghosts: |
1146 | - search = graph._make_breadth_first_searcher(['head']) |
1147 | + search = graph._make_breadth_first_searcher([b'head']) |
1148 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1149 | |
1150 | def test_breadth_first_get_result_starting_a_ghost_ghost_is_excluded(self): |
1151 | graph = self.make_graph({ |
1152 | - 'head': ['child'], |
1153 | - 'child': [NULL_REVISION], |
1154 | + b'head': [b'child'], |
1155 | + b'child': [NULL_REVISION], |
1156 | NULL_REVISION: [], |
1157 | }) |
1158 | - search = graph._make_breadth_first_searcher(['head']) |
1159 | + search = graph._make_breadth_first_searcher([b'head']) |
1160 | # using next: |
1161 | expected = [ |
1162 | - ({'head', 'ghost'}, |
1163 | - ({'head', 'ghost'}, {'child', 'ghost'}, 1), |
1164 | - ['head'], ['ghost'], None), |
1165 | - ({'head', 'child', 'ghost'}, |
1166 | - ({'head', 'ghost'}, {NULL_REVISION, 'ghost'}, 2), |
1167 | - ['head', 'child'], None, None), |
1168 | + ({b'head', b'ghost'}, |
1169 | + ({b'head', b'ghost'}, {b'child', b'ghost'}, 1), |
1170 | + [b'head'], [b'ghost'], None), |
1171 | + ({b'head', b'child', b'ghost'}, |
1172 | + ({b'head', b'ghost'}, {NULL_REVISION, b'ghost'}, 2), |
1173 | + [b'head', b'child'], None, None), |
1174 | ] |
1175 | self.assertSeenAndResult(expected, search, search.__next__) |
1176 | # using next_with_ghosts: |
1177 | - search = graph._make_breadth_first_searcher(['head']) |
1178 | + search = graph._make_breadth_first_searcher([b'head']) |
1179 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1180 | |
1181 | def test_breadth_first_revision_count_includes_NULL_REVISION(self): |
1182 | graph = self.make_graph({ |
1183 | - 'head': [NULL_REVISION], |
1184 | + b'head': [NULL_REVISION], |
1185 | NULL_REVISION: [], |
1186 | }) |
1187 | - search = graph._make_breadth_first_searcher(['head']) |
1188 | + search = graph._make_breadth_first_searcher([b'head']) |
1189 | # using next: |
1190 | expected = [ |
1191 | - ({'head'}, |
1192 | - ({'head'}, {NULL_REVISION}, 1), |
1193 | - ['head'], None, None), |
1194 | - ({'head', NULL_REVISION}, |
1195 | - ({'head'}, set([]), 2), |
1196 | - ['head', NULL_REVISION], None, None), |
1197 | + ({b'head'}, |
1198 | + ({b'head'}, {NULL_REVISION}, 1), |
1199 | + [b'head'], None, None), |
1200 | + ({b'head', NULL_REVISION}, |
1201 | + ({b'head'}, set([]), 2), |
1202 | + [b'head', NULL_REVISION], None, None), |
1203 | ] |
1204 | self.assertSeenAndResult(expected, search, search.__next__) |
1205 | # using next_with_ghosts: |
1206 | - search = graph._make_breadth_first_searcher(['head']) |
1207 | + search = graph._make_breadth_first_searcher([b'head']) |
1208 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1209 | |
1210 | def test_breadth_first_search_get_result_after_StopIteration(self): |
1211 | # StopIteration should not invalid anything.. |
1212 | graph = self.make_graph({ |
1213 | - 'head': [NULL_REVISION], |
1214 | + b'head': [NULL_REVISION], |
1215 | NULL_REVISION: [], |
1216 | }) |
1217 | - search = graph._make_breadth_first_searcher(['head']) |
1218 | + search = graph._make_breadth_first_searcher([b'head']) |
1219 | # using next: |
1220 | expected = [ |
1221 | - ({'head'}, |
1222 | - ({'head'}, {NULL_REVISION}, 1), |
1223 | - ['head'], None, None), |
1224 | - ({'head', 'ghost', NULL_REVISION}, |
1225 | - ({'head', 'ghost'}, {'ghost'}, 2), |
1226 | - ['head', NULL_REVISION], ['ghost'], None), |
1227 | + ({b'head'}, |
1228 | + ({b'head'}, {NULL_REVISION}, 1), |
1229 | + [b'head'], None, None), |
1230 | + ({b'head', b'ghost', NULL_REVISION}, |
1231 | + ({b'head', b'ghost'}, {b'ghost'}, 2), |
1232 | + [b'head', NULL_REVISION], [b'ghost'], None), |
1233 | ] |
1234 | self.assertSeenAndResult(expected, search, search.__next__) |
1235 | self.assertRaises(StopIteration, next, search) |
1236 | - self.assertEqual({'head', 'ghost', NULL_REVISION}, search.seen) |
1237 | + self.assertEqual({b'head', b'ghost', NULL_REVISION}, search.seen) |
1238 | state = search.get_state() |
1239 | self.assertEqual( |
1240 | - ({'ghost', 'head'}, {'ghost'}, |
1241 | - {'head', NULL_REVISION}), |
1242 | + ({b'ghost', b'head'}, {b'ghost'}, |
1243 | + {b'head', NULL_REVISION}), |
1244 | state) |
1245 | # using next_with_ghosts: |
1246 | - search = graph._make_breadth_first_searcher(['head']) |
1247 | + search = graph._make_breadth_first_searcher([b'head']) |
1248 | self.assertSeenAndResult(expected, search, search.next_with_ghosts) |
1249 | self.assertRaises(StopIteration, next, search) |
1250 | - self.assertEqual({'head', 'ghost', NULL_REVISION}, search.seen) |
1251 | + self.assertEqual({b'head', b'ghost', NULL_REVISION}, search.seen) |
1252 | state = search.get_state() |
1253 | self.assertEqual( |
1254 | - ({'ghost', 'head'}, {'ghost'}, |
1255 | - {'head', NULL_REVISION}), |
1256 | + ({b'ghost', b'head'}, {b'ghost'}, |
1257 | + {b'head', NULL_REVISION}), |
1258 | state) |
1259 | |
1260 | |
1261 | @@ -1256,71 +1256,71 @@ |
1262 | |
1263 | def test_empty_set(self): |
1264 | graph = self.make_graph(ancestry_1) |
1265 | - self.assertFindUniqueAncestors(graph, [], 'rev1', ['rev1']) |
1266 | - self.assertFindUniqueAncestors(graph, [], 'rev2b', ['rev2b']) |
1267 | - self.assertFindUniqueAncestors(graph, [], 'rev3', ['rev1', 'rev3']) |
1268 | + self.assertFindUniqueAncestors(graph, [], b'rev1', [b'rev1']) |
1269 | + self.assertFindUniqueAncestors(graph, [], b'rev2b', [b'rev2b']) |
1270 | + self.assertFindUniqueAncestors(graph, [], b'rev3', [b'rev1', b'rev3']) |
1271 | |
1272 | def test_single_node(self): |
1273 | graph = self.make_graph(ancestry_1) |
1274 | - self.assertFindUniqueAncestors(graph, ['rev2a'], 'rev2a', ['rev1']) |
1275 | - self.assertFindUniqueAncestors(graph, ['rev2b'], 'rev2b', ['rev1']) |
1276 | - self.assertFindUniqueAncestors(graph, ['rev3'], 'rev3', ['rev2a']) |
1277 | + self.assertFindUniqueAncestors(graph, [b'rev2a'], b'rev2a', [b'rev1']) |
1278 | + self.assertFindUniqueAncestors(graph, [b'rev2b'], b'rev2b', [b'rev1']) |
1279 | + self.assertFindUniqueAncestors(graph, [b'rev3'], b'rev3', [b'rev2a']) |
1280 | |
1281 | def test_minimal_ancestry(self): |
1282 | graph = self.make_breaking_graph(extended_history_shortcut, |
1283 | - [NULL_REVISION, 'a', 'b']) |
1284 | - self.assertFindUniqueAncestors(graph, ['e'], 'e', ['d']) |
1285 | + [NULL_REVISION, b'a', b'b']) |
1286 | + self.assertFindUniqueAncestors(graph, [b'e'], b'e', [b'd']) |
1287 | |
1288 | graph = self.make_breaking_graph(extended_history_shortcut, |
1289 | - ['b']) |
1290 | - self.assertFindUniqueAncestors(graph, ['f'], 'f', ['a', 'd']) |
1291 | + [b'b']) |
1292 | + self.assertFindUniqueAncestors(graph, [b'f'], b'f', [b'a', b'd']) |
1293 | |
1294 | graph = self.make_breaking_graph(complex_shortcut, |
1295 | - ['a', 'b']) |
1296 | - self.assertFindUniqueAncestors(graph, ['h'], 'h', ['i']) |
1297 | - self.assertFindUniqueAncestors(graph, ['e', 'g', 'i'], 'i', ['h']) |
1298 | - self.assertFindUniqueAncestors(graph, ['h'], 'h', ['g']) |
1299 | - self.assertFindUniqueAncestors(graph, ['h'], 'h', ['j']) |
1300 | + [b'a', b'b']) |
1301 | + self.assertFindUniqueAncestors(graph, [b'h'], b'h', [b'i']) |
1302 | + self.assertFindUniqueAncestors(graph, [b'e', b'g', b'i'], b'i', [b'h']) |
1303 | + self.assertFindUniqueAncestors(graph, [b'h'], b'h', [b'g']) |
1304 | + self.assertFindUniqueAncestors(graph, [b'h'], b'h', [b'j']) |
1305 | |
1306 | def test_in_ancestry(self): |
1307 | graph = self.make_graph(ancestry_1) |
1308 | - self.assertFindUniqueAncestors(graph, [], 'rev1', ['rev3']) |
1309 | - self.assertFindUniqueAncestors(graph, [], 'rev2b', ['rev4']) |
1310 | + self.assertFindUniqueAncestors(graph, [], b'rev1', [b'rev3']) |
1311 | + self.assertFindUniqueAncestors(graph, [], b'rev2b', [b'rev4']) |
1312 | |
1313 | def test_multiple_revisions(self): |
1314 | graph = self.make_graph(ancestry_1) |
1315 | self.assertFindUniqueAncestors(graph, |
1316 | - ['rev4'], 'rev4', ['rev3', 'rev2b']) |
1317 | + [b'rev4'], b'rev4', [b'rev3', b'rev2b']) |
1318 | self.assertFindUniqueAncestors(graph, |
1319 | - ['rev2a', 'rev3', 'rev4'], 'rev4', ['rev2b']) |
1320 | + [b'rev2a', b'rev3', b'rev4'], b'rev4', [b'rev2b']) |
1321 | |
1322 | def test_complex_shortcut(self): |
1323 | graph = self.make_graph(complex_shortcut) |
1324 | self.assertFindUniqueAncestors(graph, |
1325 | - ['h', 'n'], 'n', ['m']) |
1326 | + [b'h', b'n'], b'n', [b'm']) |
1327 | self.assertFindUniqueAncestors(graph, |
1328 | - ['e', 'i', 'm'], 'm', ['n']) |
1329 | + [b'e', b'i', b'm'], b'm', [b'n']) |
1330 | |
1331 | def test_complex_shortcut2(self): |
1332 | graph = self.make_graph(complex_shortcut2) |
1333 | self.assertFindUniqueAncestors(graph, |
1334 | - ['j', 'u'], 'u', ['t']) |
1335 | + [b'j', b'u'], b'u', [b't']) |
1336 | self.assertFindUniqueAncestors(graph, |
1337 | - ['t'], 't', ['u']) |
1338 | + [b't'], b't', [b'u']) |
1339 | |
1340 | def test_multiple_interesting_unique(self): |
1341 | graph = self.make_graph(multiple_interesting_unique) |
1342 | self.assertFindUniqueAncestors(graph, |
1343 | - ['j', 'y'], 'y', ['z']) |
1344 | + [b'j', b'y'], b'y', [b'z']) |
1345 | self.assertFindUniqueAncestors(graph, |
1346 | - ['p', 'z'], 'z', ['y']) |
1347 | + [b'p', b'z'], b'z', [b'y']) |
1348 | |
1349 | def test_racing_shortcuts(self): |
1350 | graph = self.make_graph(racing_shortcuts) |
1351 | self.assertFindUniqueAncestors(graph, |
1352 | - ['p', 'q', 'z'], 'z', ['y']) |
1353 | + [b'p', b'q', b'z'], b'z', [b'y']) |
1354 | self.assertFindUniqueAncestors(graph, |
1355 | - ['h', 'i', 'j', 'y'], 'j', ['z']) |
1356 | + [b'h', b'i', b'j', b'y'], b'j', [b'z']) |
1357 | |
1358 | |
1359 | class TestGraphFindDistanceToNull(TestGraphBase): |
1360 | @@ -1334,52 +1334,52 @@ |
1361 | def test_nothing_known(self): |
1362 | graph = self.make_graph(ancestry_1) |
1363 | self.assertFindDistance(0, graph, NULL_REVISION, []) |
1364 | - self.assertFindDistance(1, graph, 'rev1', []) |
1365 | - self.assertFindDistance(2, graph, 'rev2a', []) |
1366 | - self.assertFindDistance(2, graph, 'rev2b', []) |
1367 | - self.assertFindDistance(3, graph, 'rev3', []) |
1368 | - self.assertFindDistance(4, graph, 'rev4', []) |
1369 | + self.assertFindDistance(1, graph, b'rev1', []) |
1370 | + self.assertFindDistance(2, graph, b'rev2a', []) |
1371 | + self.assertFindDistance(2, graph, b'rev2b', []) |
1372 | + self.assertFindDistance(3, graph, b'rev3', []) |
1373 | + self.assertFindDistance(4, graph, b'rev4', []) |
1374 | |
1375 | def test_rev_is_ghost(self): |
1376 | graph = self.make_graph(ancestry_1) |
1377 | e = self.assertRaises(errors.GhostRevisionsHaveNoRevno, |
1378 | - graph.find_distance_to_null, 'rev_missing', []) |
1379 | - self.assertEqual('rev_missing', e.revision_id) |
1380 | - self.assertEqual('rev_missing', e.ghost_revision_id) |
1381 | + graph.find_distance_to_null, b'rev_missing', []) |
1382 | + self.assertEqual(b'rev_missing', e.revision_id) |
1383 | + self.assertEqual(b'rev_missing', e.ghost_revision_id) |
1384 | |
1385 | def test_ancestor_is_ghost(self): |
1386 | - graph = self.make_graph({'rev':['parent']}) |
1387 | + graph = self.make_graph({b'rev': [b'parent']}) |
1388 | e = self.assertRaises(errors.GhostRevisionsHaveNoRevno, |
1389 | - graph.find_distance_to_null, 'rev', []) |
1390 | - self.assertEqual('rev', e.revision_id) |
1391 | - self.assertEqual('parent', e.ghost_revision_id) |
1392 | + graph.find_distance_to_null, b'rev', []) |
1393 | + self.assertEqual(b'rev', e.revision_id) |
1394 | + self.assertEqual(b'parent', e.ghost_revision_id) |
1395 | |
1396 | def test_known_in_ancestry(self): |
1397 | graph = self.make_graph(ancestry_1) |
1398 | - self.assertFindDistance(2, graph, 'rev2a', [('rev1', 1)]) |
1399 | - self.assertFindDistance(3, graph, 'rev3', [('rev2a', 2)]) |
1400 | + self.assertFindDistance(2, graph, b'rev2a', [(b'rev1', 1)]) |
1401 | + self.assertFindDistance(3, graph, b'rev3', [(b'rev2a', 2)]) |
1402 | |
1403 | def test_known_in_ancestry_limits(self): |
1404 | - graph = self.make_breaking_graph(ancestry_1, ['rev1']) |
1405 | - self.assertFindDistance(4, graph, 'rev4', [('rev3', 3)]) |
1406 | + graph = self.make_breaking_graph(ancestry_1, [b'rev1']) |
1407 | + self.assertFindDistance(4, graph, b'rev4', [(b'rev3', 3)]) |
1408 | |
1409 | def test_target_is_ancestor(self): |
1410 | graph = self.make_graph(ancestry_1) |
1411 | - self.assertFindDistance(2, graph, 'rev2a', [('rev3', 3)]) |
1412 | + self.assertFindDistance(2, graph, b'rev2a', [(b'rev3', 3)]) |
1413 | |
1414 | def test_target_is_ancestor_limits(self): |
1415 | """We shouldn't search all history if we run into ourselves""" |
1416 | - graph = self.make_breaking_graph(ancestry_1, ['rev1']) |
1417 | - self.assertFindDistance(3, graph, 'rev3', [('rev4', 4)]) |
1418 | + graph = self.make_breaking_graph(ancestry_1, [b'rev1']) |
1419 | + self.assertFindDistance(3, graph, b'rev3', [(b'rev4', 4)]) |
1420 | |
1421 | def test_target_parallel_to_known_limits(self): |
1422 | # Even though the known revision isn't part of the other ancestry, they |
1423 | # eventually converge |
1424 | - graph = self.make_breaking_graph(with_tail, ['a']) |
1425 | - self.assertFindDistance(6, graph, 'f', [('g', 6)]) |
1426 | - self.assertFindDistance(7, graph, 'h', [('g', 6)]) |
1427 | - self.assertFindDistance(8, graph, 'i', [('g', 6)]) |
1428 | - self.assertFindDistance(6, graph, 'g', [('i', 8)]) |
1429 | + graph = self.make_breaking_graph(with_tail, [b'a']) |
1430 | + self.assertFindDistance(6, graph, b'f', [(b'g', 6)]) |
1431 | + self.assertFindDistance(7, graph, b'h', [(b'g', 6)]) |
1432 | + self.assertFindDistance(8, graph, b'i', [(b'g', 6)]) |
1433 | + self.assertFindDistance(6, graph, b'g', [(b'i', 8)]) |
1434 | |
1435 | |
1436 | class TestFindMergeOrder(TestGraphBase): |
1437 | @@ -1389,46 +1389,46 @@ |
1438 | |
1439 | def test_parents(self): |
1440 | graph = self.make_graph(ancestry_1) |
1441 | - self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4', |
1442 | - ['rev3', 'rev2b']) |
1443 | - self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4', |
1444 | - ['rev2b', 'rev3']) |
1445 | + self.assertMergeOrder([b'rev3', b'rev2b'], graph, b'rev4', |
1446 | + [b'rev3', b'rev2b']) |
1447 | + self.assertMergeOrder([b'rev3', b'rev2b'], graph, b'rev4', |
1448 | + [b'rev2b', b'rev3']) |
1449 | |
1450 | def test_ancestors(self): |
1451 | graph = self.make_graph(ancestry_1) |
1452 | - self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4', |
1453 | - ['rev1', 'rev2b']) |
1454 | - self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4', |
1455 | - ['rev2b', 'rev1']) |
1456 | + self.assertMergeOrder([b'rev1', b'rev2b'], graph, b'rev4', |
1457 | + [b'rev1', b'rev2b']) |
1458 | + self.assertMergeOrder([b'rev1', b'rev2b'], graph, b'rev4', |
1459 | + [b'rev2b', b'rev1']) |
1460 | |
1461 | def test_shortcut_one_ancestor(self): |
1462 | # When we have enough info, we can stop searching |
1463 | - graph = self.make_breaking_graph(ancestry_1, ['rev3', 'rev2b', 'rev4']) |
1464 | + graph = self.make_breaking_graph(ancestry_1, [b'rev3', b'rev2b', b'rev4']) |
1465 | # Single ancestors shortcut right away |
1466 | - self.assertMergeOrder(['rev3'], graph, 'rev4', ['rev3']) |
1467 | + self.assertMergeOrder([b'rev3'], graph, b'rev4', [b'rev3']) |
1468 | |
1469 | def test_shortcut_after_one_ancestor(self): |
1470 | - graph = self.make_breaking_graph(ancestry_1, ['rev2a', 'rev2b']) |
1471 | - self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3']) |
1472 | + graph = self.make_breaking_graph(ancestry_1, [b'rev2a', b'rev2b']) |
1473 | + self.assertMergeOrder([b'rev3', b'rev1'], graph, b'rev4', [b'rev1', b'rev3']) |
1474 | |
1475 | |
1476 | class TestFindDescendants(TestGraphBase): |
1477 | |
1478 | def test_find_descendants_rev1_rev3(self): |
1479 | graph = self.make_graph(ancestry_1) |
1480 | - descendants = graph.find_descendants('rev1', 'rev3') |
1481 | - self.assertEqual({'rev1', 'rev2a', 'rev3'}, descendants) |
1482 | + descendants = graph.find_descendants(b'rev1', b'rev3') |
1483 | + self.assertEqual({b'rev1', b'rev2a', b'rev3'}, descendants) |
1484 | |
1485 | def test_find_descendants_rev1_rev4(self): |
1486 | graph = self.make_graph(ancestry_1) |
1487 | - descendants = graph.find_descendants('rev1', 'rev4') |
1488 | - self.assertEqual({'rev1', 'rev2a', 'rev2b', 'rev3', 'rev4'}, |
1489 | + descendants = graph.find_descendants(b'rev1', b'rev4') |
1490 | + self.assertEqual({b'rev1', b'rev2a', b'rev2b', b'rev3', b'rev4'}, |
1491 | descendants) |
1492 | |
1493 | def test_find_descendants_rev2a_rev4(self): |
1494 | graph = self.make_graph(ancestry_1) |
1495 | - descendants = graph.find_descendants('rev2a', 'rev4') |
1496 | - self.assertEqual({'rev2a', 'rev3', 'rev4'}, descendants) |
1497 | + descendants = graph.find_descendants(b'rev2a', b'rev4') |
1498 | + self.assertEqual({b'rev2a', b'rev3', b'rev4'}, descendants) |
1499 | |
1500 | class TestFindLefthandMerger(TestGraphBase): |
1501 | |
1502 | @@ -1437,33 +1437,33 @@ |
1503 | self.assertEqual(result, graph.find_lefthand_merger(merged, tip)) |
1504 | |
1505 | def test_find_lefthand_merger_rev2b(self): |
1506 | - self.check_merger('rev4', ancestry_1, 'rev2b', 'rev4') |
1507 | + self.check_merger(b'rev4', ancestry_1, b'rev2b', b'rev4') |
1508 | |
1509 | def test_find_lefthand_merger_rev2a(self): |
1510 | - self.check_merger('rev2a', ancestry_1, 'rev2a', 'rev4') |
1511 | + self.check_merger(b'rev2a', ancestry_1, b'rev2a', b'rev4') |
1512 | |
1513 | def test_find_lefthand_merger_rev4(self): |
1514 | - self.check_merger(None, ancestry_1, 'rev4', 'rev2a') |
1515 | + self.check_merger(None, ancestry_1, b'rev4', b'rev2a') |
1516 | |
1517 | def test_find_lefthand_merger_f(self): |
1518 | - self.check_merger('i', complex_shortcut, 'f', 'm') |
1519 | + self.check_merger(b'i', complex_shortcut, b'f', b'm') |
1520 | |
1521 | def test_find_lefthand_merger_g(self): |
1522 | - self.check_merger('i', complex_shortcut, 'g', 'm') |
1523 | + self.check_merger(b'i', complex_shortcut, b'g', b'm') |
1524 | |
1525 | def test_find_lefthand_merger_h(self): |
1526 | - self.check_merger('n', complex_shortcut, 'h', 'n') |
1527 | + self.check_merger(b'n', complex_shortcut, b'h', b'n') |
1528 | |
1529 | |
1530 | class TestGetChildMap(TestGraphBase): |
1531 | |
1532 | def test_get_child_map(self): |
1533 | graph = self.make_graph(ancestry_1) |
1534 | - child_map = graph.get_child_map(['rev4', 'rev3', 'rev2a', 'rev2b']) |
1535 | - self.assertEqual({'rev1': ['rev2a', 'rev2b'], |
1536 | - 'rev2a': ['rev3'], |
1537 | - 'rev2b': ['rev4'], |
1538 | - 'rev3': ['rev4']}, |
1539 | + child_map = graph.get_child_map([b'rev4', b'rev3', b'rev2a', b'rev2b']) |
1540 | + self.assertEqual({b'rev1': [b'rev2a', b'rev2b'], |
1541 | + b'rev2a': [b'rev3'], |
1542 | + b'rev2b': [b'rev4'], |
1543 | + b'rev3': [b'rev4']}, |
1544 | child_map) |
1545 | |
1546 | |
1547 | @@ -1477,58 +1477,58 @@ |
1548 | |
1549 | def setUp(self): |
1550 | super(TestCachingParentsProvider, self).setUp() |
1551 | - dict_pp = _mod_graph.DictParentsProvider({'a': ('b',)}) |
1552 | + dict_pp = _mod_graph.DictParentsProvider({b'a': (b'b',)}) |
1553 | self.inst_pp = InstrumentedParentsProvider(dict_pp) |
1554 | self.caching_pp = _mod_graph.CachingParentsProvider(self.inst_pp) |
1555 | |
1556 | def test_get_parent_map(self): |
1557 | """Requesting the same revision should be returned from cache""" |
1558 | self.assertEqual({}, self.caching_pp._cache) |
1559 | - self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a'])) |
1560 | - self.assertEqual(['a'], self.inst_pp.calls) |
1561 | - self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a'])) |
1562 | + self.assertEqual({b'a':(b'b',)}, self.caching_pp.get_parent_map([b'a'])) |
1563 | + self.assertEqual([b'a'], self.inst_pp.calls) |
1564 | + self.assertEqual({b'a':(b'b',)}, self.caching_pp.get_parent_map([b'a'])) |
1565 | # No new call, as it should have been returned from the cache |
1566 | - self.assertEqual(['a'], self.inst_pp.calls) |
1567 | - self.assertEqual({'a':('b',)}, self.caching_pp._cache) |
1568 | + self.assertEqual([b'a'], self.inst_pp.calls) |
1569 | + self.assertEqual({b'a':(b'b',)}, self.caching_pp._cache) |
1570 | |
1571 | def test_get_parent_map_not_present(self): |
1572 | """The cache should also track when a revision doesn't exist""" |
1573 | - self.assertEqual({}, self.caching_pp.get_parent_map(['b'])) |
1574 | - self.assertEqual(['b'], self.inst_pp.calls) |
1575 | - self.assertEqual({}, self.caching_pp.get_parent_map(['b'])) |
1576 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'b'])) |
1577 | + self.assertEqual([b'b'], self.inst_pp.calls) |
1578 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'b'])) |
1579 | # No new calls |
1580 | - self.assertEqual(['b'], self.inst_pp.calls) |
1581 | + self.assertEqual([b'b'], self.inst_pp.calls) |
1582 | |
1583 | def test_get_parent_map_mixed(self): |
1584 | """Anything that can be returned from cache, should be""" |
1585 | - self.assertEqual({}, self.caching_pp.get_parent_map(['b'])) |
1586 | - self.assertEqual(['b'], self.inst_pp.calls) |
1587 | - self.assertEqual({'a':('b',)}, |
1588 | - self.caching_pp.get_parent_map(['a', 'b'])) |
1589 | - self.assertEqual(['b', 'a'], self.inst_pp.calls) |
1590 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'b'])) |
1591 | + self.assertEqual([b'b'], self.inst_pp.calls) |
1592 | + self.assertEqual({b'a':(b'b',)}, |
1593 | + self.caching_pp.get_parent_map([b'a', b'b'])) |
1594 | + self.assertEqual([b'b', b'a'], self.inst_pp.calls) |
1595 | |
1596 | def test_get_parent_map_repeated(self): |
1597 | """Asking for the same parent 2x will only forward 1 request.""" |
1598 | - self.assertEqual({'a':('b',)}, |
1599 | - self.caching_pp.get_parent_map(['b', 'a', 'b'])) |
1600 | + self.assertEqual({b'a':(b'b',)}, |
1601 | + self.caching_pp.get_parent_map([b'b', b'a', b'b'])) |
1602 | # Use sorted because we don't care about the order, just that each is |
1603 | # only present 1 time. |
1604 | - self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls)) |
1605 | + self.assertEqual([b'a', b'b'], sorted(self.inst_pp.calls)) |
1606 | |
1607 | def test_note_missing_key(self): |
1608 | """After noting that a key is missing it is cached.""" |
1609 | - self.caching_pp.note_missing_key('b') |
1610 | - self.assertEqual({}, self.caching_pp.get_parent_map(['b'])) |
1611 | + self.caching_pp.note_missing_key(b'b') |
1612 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'b'])) |
1613 | self.assertEqual([], self.inst_pp.calls) |
1614 | - self.assertEqual({'b'}, self.caching_pp.missing_keys) |
1615 | + self.assertEqual({b'b'}, self.caching_pp.missing_keys) |
1616 | |
1617 | def test_get_cached_parent_map(self): |
1618 | - self.assertEqual({}, self.caching_pp.get_cached_parent_map(['a'])) |
1619 | + self.assertEqual({}, self.caching_pp.get_cached_parent_map([b'a'])) |
1620 | self.assertEqual([], self.inst_pp.calls) |
1621 | - self.assertEqual({'a': ('b',)}, self.caching_pp.get_parent_map(['a'])) |
1622 | - self.assertEqual(['a'], self.inst_pp.calls) |
1623 | - self.assertEqual({'a': ('b',)}, |
1624 | - self.caching_pp.get_cached_parent_map(['a'])) |
1625 | + self.assertEqual({b'a': (b'b',)}, self.caching_pp.get_parent_map([b'a'])) |
1626 | + self.assertEqual([b'a'], self.inst_pp.calls) |
1627 | + self.assertEqual({b'a': (b'b',)}, |
1628 | + self.caching_pp.get_cached_parent_map([b'a'])) |
1629 | |
1630 | |
1631 | class TestCachingParentsProviderExtras(tests.TestCaseWithTransport): |
1632 | @@ -1539,7 +1539,7 @@ |
1633 | class ExtraParentsProvider(object): |
1634 | |
1635 | def get_parent_map(self, keys): |
1636 | - return {'rev1': [], 'rev2': ['rev1',]} |
1637 | + return {b'rev1': [], b'rev2': [b'rev1',]} |
1638 | |
1639 | self.inst_pp = InstrumentedParentsProvider(ExtraParentsProvider()) |
1640 | self.caching_pp = _mod_graph.CachingParentsProvider( |
1641 | @@ -1547,27 +1547,27 @@ |
1642 | |
1643 | def test_uncached(self): |
1644 | self.caching_pp.disable_cache() |
1645 | - self.assertEqual({'rev1': []}, |
1646 | - self.caching_pp.get_parent_map(['rev1'])) |
1647 | - self.assertEqual(['rev1'], self.inst_pp.calls) |
1648 | + self.assertEqual({b'rev1': []}, |
1649 | + self.caching_pp.get_parent_map([b'rev1'])) |
1650 | + self.assertEqual([b'rev1'], self.inst_pp.calls) |
1651 | self.assertIs(None, self.caching_pp._cache) |
1652 | |
1653 | def test_cache_initially_empty(self): |
1654 | self.assertEqual({}, self.caching_pp._cache) |
1655 | |
1656 | def test_cached(self): |
1657 | - self.assertEqual({'rev1': []}, |
1658 | - self.caching_pp.get_parent_map(['rev1'])) |
1659 | - self.assertEqual(['rev1'], self.inst_pp.calls) |
1660 | - self.assertEqual({'rev1': [], 'rev2': ['rev1']}, |
1661 | + self.assertEqual({b'rev1': []}, |
1662 | + self.caching_pp.get_parent_map([b'rev1'])) |
1663 | + self.assertEqual([b'rev1'], self.inst_pp.calls) |
1664 | + self.assertEqual({b'rev1': [], b'rev2': [b'rev1']}, |
1665 | self.caching_pp._cache) |
1666 | - self.assertEqual({'rev1': []}, |
1667 | - self.caching_pp.get_parent_map(['rev1'])) |
1668 | - self.assertEqual(['rev1'], self.inst_pp.calls) |
1669 | + self.assertEqual({b'rev1': []}, |
1670 | + self.caching_pp.get_parent_map([b'rev1'])) |
1671 | + self.assertEqual([b'rev1'], self.inst_pp.calls) |
1672 | |
1673 | def test_disable_cache_clears_cache(self): |
1674 | # Put something in the cache |
1675 | - self.caching_pp.get_parent_map(['rev1']) |
1676 | + self.caching_pp.get_parent_map([b'rev1']) |
1677 | self.assertEqual(2, len(self.caching_pp._cache)) |
1678 | self.caching_pp.disable_cache() |
1679 | self.assertIs(None, self.caching_pp._cache) |
1680 | @@ -1577,29 +1577,29 @@ |
1681 | self.assertEqual('Cache enabled when already enabled.', str(e)) |
1682 | |
1683 | def test_cache_misses(self): |
1684 | - self.caching_pp.get_parent_map(['rev3']) |
1685 | - self.caching_pp.get_parent_map(['rev3']) |
1686 | - self.assertEqual(['rev3'], self.inst_pp.calls) |
1687 | + self.caching_pp.get_parent_map([b'rev3']) |
1688 | + self.caching_pp.get_parent_map([b'rev3']) |
1689 | + self.assertEqual([b'rev3'], self.inst_pp.calls) |
1690 | |
1691 | def test_no_cache_misses(self): |
1692 | self.caching_pp.disable_cache() |
1693 | self.caching_pp.enable_cache(cache_misses=False) |
1694 | - self.caching_pp.get_parent_map(['rev3']) |
1695 | - self.caching_pp.get_parent_map(['rev3']) |
1696 | - self.assertEqual(['rev3', 'rev3'], self.inst_pp.calls) |
1697 | + self.caching_pp.get_parent_map([b'rev3']) |
1698 | + self.caching_pp.get_parent_map([b'rev3']) |
1699 | + self.assertEqual([b'rev3', b'rev3'], self.inst_pp.calls) |
1700 | |
1701 | def test_cache_extras(self): |
1702 | - self.assertEqual({}, self.caching_pp.get_parent_map(['rev3'])) |
1703 | - self.assertEqual({'rev2': ['rev1']}, |
1704 | - self.caching_pp.get_parent_map(['rev2'])) |
1705 | - self.assertEqual(['rev3'], self.inst_pp.calls) |
1706 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'rev3'])) |
1707 | + self.assertEqual({b'rev2': [b'rev1']}, |
1708 | + self.caching_pp.get_parent_map([b'rev2'])) |
1709 | + self.assertEqual([b'rev3'], self.inst_pp.calls) |
1710 | |
1711 | def test_extras_using_cached(self): |
1712 | - self.assertEqual({}, self.caching_pp.get_cached_parent_map(['rev3'])) |
1713 | - self.assertEqual({}, self.caching_pp.get_parent_map(['rev3'])) |
1714 | - self.assertEqual({'rev2': ['rev1']}, |
1715 | - self.caching_pp.get_cached_parent_map(['rev2'])) |
1716 | - self.assertEqual(['rev3'], self.inst_pp.calls) |
1717 | + self.assertEqual({}, self.caching_pp.get_cached_parent_map([b'rev3'])) |
1718 | + self.assertEqual({}, self.caching_pp.get_parent_map([b'rev3'])) |
1719 | + self.assertEqual({b'rev2': [b'rev1']}, |
1720 | + self.caching_pp.get_cached_parent_map([b'rev2'])) |
1721 | + self.assertEqual([b'rev3'], self.inst_pp.calls) |
1722 | |
1723 | |
1724 | |
1725 | @@ -1649,31 +1649,31 @@ |
1726 | # B C |
1727 | # |/ |
1728 | # D |
1729 | - d = {('D',): [('B',), ('C',)], ('C',):[('A',)], |
1730 | - ('B',): [('A',)], ('A',): []} |
1731 | + d = {(b'D',): [(b'B',), (b'C',)], (b'C',):[(b'A',)], |
1732 | + (b'B',): [(b'A',)], (b'A',): []} |
1733 | g = _mod_graph.Graph(_mod_graph.DictParentsProvider(d)) |
1734 | graph_thunk = _mod_graph.GraphThunkIdsToKeys(g) |
1735 | - self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'A']))) |
1736 | - self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'B']))) |
1737 | - self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C']))) |
1738 | - self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C']))) |
1739 | + self.assertEqual([b'D'], sorted(graph_thunk.heads([b'D', b'A']))) |
1740 | + self.assertEqual([b'D'], sorted(graph_thunk.heads([b'D', b'B']))) |
1741 | + self.assertEqual([b'D'], sorted(graph_thunk.heads([b'D', b'C']))) |
1742 | + self.assertEqual([b'B', b'C'], sorted(graph_thunk.heads([b'B', b'C']))) |
1743 | |
1744 | def test_add_node(self): |
1745 | - d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []} |
1746 | + d = {(b'C',):[(b'A',)], (b'B',): [(b'A',)], (b'A',): []} |
1747 | g = _mod_graph.KnownGraph(d) |
1748 | graph_thunk = _mod_graph.GraphThunkIdsToKeys(g) |
1749 | - graph_thunk.add_node("D", ["A", "C"]) |
1750 | - self.assertEqual(['B', 'D'], |
1751 | - sorted(graph_thunk.heads(['D', 'B', 'A']))) |
1752 | + graph_thunk.add_node(b"D", [b"A", b"C"]) |
1753 | + self.assertEqual([b'B', b'D'], |
1754 | + sorted(graph_thunk.heads([b'D', b'B', b'A']))) |
1755 | |
1756 | def test_merge_sort(self): |
1757 | - d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []} |
1758 | + d = {(b'C',):[(b'A',)], (b'B',): [(b'A',)], (b'A',): []} |
1759 | g = _mod_graph.KnownGraph(d) |
1760 | graph_thunk = _mod_graph.GraphThunkIdsToKeys(g) |
1761 | - graph_thunk.add_node("D", ["A", "C"]) |
1762 | - self.assertEqual([('C', 0, (2,), False), ('A', 0, (1,), True)], |
1763 | + graph_thunk.add_node(b"D", [b"A", b"C"]) |
1764 | + self.assertEqual([(b'C', 0, (2,), False), (b'A', 0, (1,), True)], |
1765 | [(n.key, n.merge_depth, n.revno, n.end_of_merge) |
1766 | - for n in graph_thunk.merge_sort('C')]) |
1767 | + for n in graph_thunk.merge_sort(b'C')]) |
1768 | |
1769 | |
1770 | class TestStackedParentsProvider(tests.TestCase): |
1771 | @@ -1689,55 +1689,55 @@ |
1772 | return SharedInstrumentedParentsProvider(pp, self.calls, info) |
1773 | |
1774 | def test_stacked_parents_provider(self): |
1775 | - parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']}) |
1776 | - parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']}) |
1777 | + parents1 = _mod_graph.DictParentsProvider({b'rev2': [b'rev3']}) |
1778 | + parents2 = _mod_graph.DictParentsProvider({b'rev1': [b'rev4']}) |
1779 | stacked = _mod_graph.StackedParentsProvider([parents1, parents2]) |
1780 | - self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']}, |
1781 | - stacked.get_parent_map(['rev1', 'rev2'])) |
1782 | - self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']}, |
1783 | - stacked.get_parent_map(['rev2', 'rev1'])) |
1784 | - self.assertEqual({'rev2':['rev3']}, |
1785 | - stacked.get_parent_map(['rev2', 'rev2'])) |
1786 | - self.assertEqual({'rev1':['rev4']}, |
1787 | - stacked.get_parent_map(['rev1', 'rev1'])) |
1788 | + self.assertEqual({b'rev1':[b'rev4'], b'rev2':[b'rev3']}, |
1789 | + stacked.get_parent_map([b'rev1', b'rev2'])) |
1790 | + self.assertEqual({b'rev2':[b'rev3'], b'rev1':[b'rev4']}, |
1791 | + stacked.get_parent_map([b'rev2', b'rev1'])) |
1792 | + self.assertEqual({b'rev2':[b'rev3']}, |
1793 | + stacked.get_parent_map([b'rev2', b'rev2'])) |
1794 | + self.assertEqual({b'rev1':[b'rev4']}, |
1795 | + stacked.get_parent_map([b'rev1', b'rev1'])) |
1796 | |
1797 | def test_stacked_parents_provider_overlapping(self): |
1798 | # rev2 is availible in both providers. |
1799 | # 1 |
1800 | # | |
1801 | # 2 |
1802 | - parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev1']}) |
1803 | - parents2 = _mod_graph.DictParentsProvider({'rev2': ['rev1']}) |
1804 | + parents1 = _mod_graph.DictParentsProvider({b'rev2': [b'rev1']}) |
1805 | + parents2 = _mod_graph.DictParentsProvider({b'rev2': [b'rev1']}) |
1806 | stacked = _mod_graph.StackedParentsProvider([parents1, parents2]) |
1807 | - self.assertEqual({'rev2': ['rev1']}, |
1808 | - stacked.get_parent_map(['rev2'])) |
1809 | + self.assertEqual({b'rev2': [b'rev1']}, |
1810 | + stacked.get_parent_map([b'rev2'])) |
1811 | |
1812 | def test_handles_no_get_cached_parent_map(self): |
1813 | # this shows that we both handle when a provider doesn't implement |
1814 | # get_cached_parent_map |
1815 | - pp1 = self.get_shared_provider('pp1', {'rev2': ('rev1',)}, |
1816 | + pp1 = self.get_shared_provider(b'pp1', {b'rev2': (b'rev1',)}, |
1817 | has_cached=False) |
1818 | - pp2 = self.get_shared_provider('pp2', {'rev2': ('rev1',)}, |
1819 | + pp2 = self.get_shared_provider(b'pp2', {b'rev2': (b'rev1',)}, |
1820 | has_cached=True) |
1821 | stacked = _mod_graph.StackedParentsProvider([pp1, pp2]) |
1822 | - self.assertEqual({'rev2': ('rev1',)}, stacked.get_parent_map(['rev2'])) |
1823 | - # No call on 'pp1' because it doesn't provide get_cached_parent_map |
1824 | - self.assertEqual([('pp2', 'cached', ['rev2'])], self.calls) |
1825 | + self.assertEqual({b'rev2': (b'rev1',)}, stacked.get_parent_map([b'rev2'])) |
1826 | + # No call on b'pp1' because it doesn't provide get_cached_parent_map |
1827 | + self.assertEqual([(b'pp2', 'cached', [b'rev2'])], self.calls) |
1828 | |
1829 | def test_query_order(self): |
1830 | # We should call get_cached_parent_map on all providers before we call |
1831 | # get_parent_map. Further, we should track what entries we have found, |
1832 | # and not re-try them. |
1833 | - pp1 = self.get_shared_provider('pp1', {'a': ()}, has_cached=True) |
1834 | - pp2 = self.get_shared_provider('pp2', {'c': ('b',)}, has_cached=False) |
1835 | - pp3 = self.get_shared_provider('pp3', {'b': ('a',)}, has_cached=True) |
1836 | + pp1 = self.get_shared_provider(b'pp1', {b'a': ()}, has_cached=True) |
1837 | + pp2 = self.get_shared_provider(b'pp2', {b'c': (b'b',)}, has_cached=False) |
1838 | + pp3 = self.get_shared_provider(b'pp3', {b'b': (b'a',)}, has_cached=True) |
1839 | stacked = _mod_graph.StackedParentsProvider([pp1, pp2, pp3]) |
1840 | - self.assertEqual({'a': (), 'b': ('a',), 'c': ('b',)}, |
1841 | - stacked.get_parent_map(['a', 'b', 'c', 'd'])) |
1842 | - self.assertEqual([('pp1', 'cached', ['a', 'b', 'c', 'd']), |
1843 | + self.assertEqual({b'a': (), b'b': (b'a',), b'c': (b'b',)}, |
1844 | + stacked.get_parent_map([b'a', b'b', b'c', b'd'])) |
1845 | + self.assertEqual([(b'pp1', 'cached', [b'a', b'b', b'c', b'd']), |
1846 | # No call to pp2, because it doesn't have cached |
1847 | - ('pp3', 'cached', ['b', 'c', 'd']), |
1848 | - ('pp1', ['c', 'd']), |
1849 | - ('pp2', ['c', 'd']), |
1850 | - ('pp3', ['d']), |
1851 | + (b'pp3', 'cached', [b'b', b'c', b'd']), |
1852 | + (b'pp1', [b'c', b'd']), |
1853 | + (b'pp2', [b'c', b'd']), |
1854 | + (b'pp3', [b'd']), |
1855 | ], self.calls) |
1856 | |
1857 | === modified file 'python3.passing' |
1858 | --- python3.passing 2018-05-19 14:54:22 +0000 |
1859 | +++ python3.passing 2018-05-22 01:21:07 +0000 |
1860 | @@ -8148,14 +8148,26 @@ |
1861 | breezy.tests.test_graph.TestGraph.test_breadth_first_stop_searching_late |
1862 | breezy.tests.test_graph.TestGraph.test_breadth_first_stop_searching_not_queried |
1863 | breezy.tests.test_graph.TestGraph.test_filter_candidate_lca |
1864 | +breezy.tests.test_graph.TestGraph.test_graph_difference |
1865 | +breezy.tests.test_graph.TestGraph.test_graph_difference_complex_shortcut |
1866 | +breezy.tests.test_graph.TestGraph.test_graph_difference_complex_shortcut2 |
1867 | +breezy.tests.test_graph.TestGraph.test_graph_difference_criss_cross |
1868 | +breezy.tests.test_graph.TestGraph.test_graph_difference_double_shortcut |
1869 | +breezy.tests.test_graph.TestGraph.test_graph_difference_extended_history |
1870 | +breezy.tests.test_graph.TestGraph.test_graph_difference_separate_ancestry |
1871 | +breezy.tests.test_graph.TestGraph.test_graph_difference_shortcut_extra_root |
1872 | breezy.tests.test_graph.TestGraph.test_heads_criss_cross |
1873 | breezy.tests.test_graph.TestGraph.test_heads_limits_search |
1874 | breezy.tests.test_graph.TestGraph.test_heads_limits_search_assymetric |
1875 | breezy.tests.test_graph.TestGraph.test_heads_limits_search_common_search_must_continue |
1876 | +breezy.tests.test_graph.TestGraph.test_heads_null |
1877 | breezy.tests.test_graph.TestGraph.test_heads_one |
1878 | breezy.tests.test_graph.TestGraph.test_heads_shortcut |
1879 | +breezy.tests.test_graph.TestGraph.test_heads_single |
1880 | breezy.tests.test_graph.TestGraph.test_heads_two_heads |
1881 | +breezy.tests.test_graph.TestGraph.test_is_ancestor |
1882 | breezy.tests.test_graph.TestGraph.test_is_ancestor_boundary |
1883 | +breezy.tests.test_graph.TestGraph.test_is_between |
1884 | breezy.tests.test_graph.TestGraph.test_iter_ancestry |
1885 | breezy.tests.test_graph.TestGraph.test_iter_ancestry_with_ghost |
1886 | breezy.tests.test_graph.TestGraph.test_iter_topo_order |
Thanks. That was a lot of b-s.