/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test__known_graph.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import pprint
20
20
 
21
 
from bzrlib import (
 
21
from .. import (
22
22
    errors,
23
23
    _known_graph_py,
24
24
    tests,
25
25
    )
26
 
from bzrlib.tests import test_graph
27
 
from bzrlib.revision import NULL_REVISION
28
 
from bzrlib.tests.scenarios import load_tests_apply_scenarios
29
 
from bzrlib.tests import (
 
26
from . import test_graph
 
27
from ..revision import NULL_REVISION
 
28
from .scenarios import load_tests_apply_scenarios
 
29
from . import (
30
30
    features,
31
31
    )
32
32
 
56
56
 
57
57
 
58
58
compiled_known_graph_feature = features.ModuleAvailableFeature(
59
 
    'bzrlib._known_graph_pyx')
 
59
    'breezy._known_graph_pyx')
60
60
 
61
61
 
62
62
#  a
216
216
 
217
217
    def test_heads_null(self):
218
218
        graph = self.make_known_graph(test_graph.ancestry_1)
219
 
        self.assertEqual(set(['null:']), graph.heads(['null:']))
220
 
        self.assertEqual(set(['rev1']), graph.heads(['null:', 'rev1']))
221
 
        self.assertEqual(set(['rev1']), graph.heads(['rev1', 'null:']))
222
 
        self.assertEqual(set(['rev1']), graph.heads(set(['rev1', 'null:'])))
223
 
        self.assertEqual(set(['rev1']), graph.heads(('rev1', 'null:')))
 
219
        self.assertEqual({'null:'}, graph.heads(['null:']))
 
220
        self.assertEqual({'rev1'}, graph.heads(['null:', 'rev1']))
 
221
        self.assertEqual({'rev1'}, graph.heads(['rev1', 'null:']))
 
222
        self.assertEqual({'rev1'}, graph.heads({'rev1', 'null:'}))
 
223
        self.assertEqual({'rev1'}, graph.heads(('rev1', 'null:')))
224
224
 
225
225
    def test_heads_one(self):
226
226
        # A single node will always be a head
227
227
        graph = self.make_known_graph(test_graph.ancestry_1)
228
 
        self.assertEqual(set(['null:']), graph.heads(['null:']))
229
 
        self.assertEqual(set(['rev1']), graph.heads(['rev1']))
230
 
        self.assertEqual(set(['rev2a']), graph.heads(['rev2a']))
231
 
        self.assertEqual(set(['rev2b']), graph.heads(['rev2b']))
232
 
        self.assertEqual(set(['rev3']), graph.heads(['rev3']))
233
 
        self.assertEqual(set(['rev4']), graph.heads(['rev4']))
 
228
        self.assertEqual({'null:'}, graph.heads(['null:']))
 
229
        self.assertEqual({'rev1'}, graph.heads(['rev1']))
 
230
        self.assertEqual({'rev2a'}, graph.heads(['rev2a']))
 
231
        self.assertEqual({'rev2b'}, graph.heads(['rev2b']))
 
232
        self.assertEqual({'rev3'}, graph.heads(['rev3']))
 
233
        self.assertEqual({'rev4'}, graph.heads(['rev4']))
234
234
 
235
235
    def test_heads_single(self):
236
236
        graph = self.make_known_graph(test_graph.ancestry_1)
237
 
        self.assertEqual(set(['rev4']), graph.heads(['null:', 'rev4']))
238
 
        self.assertEqual(set(['rev2a']), graph.heads(['rev1', 'rev2a']))
239
 
        self.assertEqual(set(['rev2b']), graph.heads(['rev1', 'rev2b']))
240
 
        self.assertEqual(set(['rev3']), graph.heads(['rev1', 'rev3']))
241
 
        self.assertEqual(set(['rev3']), graph.heads(['rev3', 'rev2a']))
242
 
        self.assertEqual(set(['rev4']), graph.heads(['rev1', 'rev4']))
243
 
        self.assertEqual(set(['rev4']), graph.heads(['rev2a', 'rev4']))
244
 
        self.assertEqual(set(['rev4']), graph.heads(['rev2b', 'rev4']))
245
 
        self.assertEqual(set(['rev4']), graph.heads(['rev3', 'rev4']))
 
237
        self.assertEqual({'rev4'}, graph.heads(['null:', 'rev4']))
 
238
        self.assertEqual({'rev2a'}, graph.heads(['rev1', 'rev2a']))
 
239
        self.assertEqual({'rev2b'}, graph.heads(['rev1', 'rev2b']))
 
240
        self.assertEqual({'rev3'}, graph.heads(['rev1', 'rev3']))
 
241
        self.assertEqual({'rev3'}, graph.heads(['rev3', 'rev2a']))
 
242
        self.assertEqual({'rev4'}, graph.heads(['rev1', 'rev4']))
 
243
        self.assertEqual({'rev4'}, graph.heads(['rev2a', 'rev4']))
 
244
        self.assertEqual({'rev4'}, graph.heads(['rev2b', 'rev4']))
 
245
        self.assertEqual({'rev4'}, graph.heads(['rev3', 'rev4']))
246
246
 
247
247
    def test_heads_two_heads(self):
248
248
        graph = self.make_known_graph(test_graph.ancestry_1)
249
 
        self.assertEqual(set(['rev2a', 'rev2b']),
 
249
        self.assertEqual({'rev2a', 'rev2b'},
250
250
                         graph.heads(['rev2a', 'rev2b']))
251
 
        self.assertEqual(set(['rev3', 'rev2b']),
 
251
        self.assertEqual({'rev3', 'rev2b'},
252
252
                         graph.heads(['rev3', 'rev2b']))
253
253
 
254
254
    def test_heads_criss_cross(self):
255
255
        graph = self.make_known_graph(test_graph.criss_cross)
256
 
        self.assertEqual(set(['rev2a']),
 
256
        self.assertEqual({'rev2a'},
257
257
                         graph.heads(['rev2a', 'rev1']))
258
 
        self.assertEqual(set(['rev2b']),
 
258
        self.assertEqual({'rev2b'},
259
259
                         graph.heads(['rev2b', 'rev1']))
260
 
        self.assertEqual(set(['rev3a']),
 
260
        self.assertEqual({'rev3a'},
261
261
                         graph.heads(['rev3a', 'rev1']))
262
 
        self.assertEqual(set(['rev3b']),
 
262
        self.assertEqual({'rev3b'},
263
263
                         graph.heads(['rev3b', 'rev1']))
264
 
        self.assertEqual(set(['rev2a', 'rev2b']),
 
264
        self.assertEqual({'rev2a', 'rev2b'},
265
265
                         graph.heads(['rev2a', 'rev2b']))
266
 
        self.assertEqual(set(['rev3a']),
 
266
        self.assertEqual({'rev3a'},
267
267
                         graph.heads(['rev3a', 'rev2a']))
268
 
        self.assertEqual(set(['rev3a']),
 
268
        self.assertEqual({'rev3a'},
269
269
                         graph.heads(['rev3a', 'rev2b']))
270
 
        self.assertEqual(set(['rev3a']),
 
270
        self.assertEqual({'rev3a'},
271
271
                         graph.heads(['rev3a', 'rev2a', 'rev2b']))
272
 
        self.assertEqual(set(['rev3b']),
 
272
        self.assertEqual({'rev3b'},
273
273
                         graph.heads(['rev3b', 'rev2a']))
274
 
        self.assertEqual(set(['rev3b']),
 
274
        self.assertEqual({'rev3b'},
275
275
                         graph.heads(['rev3b', 'rev2b']))
276
 
        self.assertEqual(set(['rev3b']),
 
276
        self.assertEqual({'rev3b'},
277
277
                         graph.heads(['rev3b', 'rev2a', 'rev2b']))
278
 
        self.assertEqual(set(['rev3a', 'rev3b']),
 
278
        self.assertEqual({'rev3a', 'rev3b'},
279
279
                         graph.heads(['rev3a', 'rev3b']))
280
 
        self.assertEqual(set(['rev3a', 'rev3b']),
 
280
        self.assertEqual({'rev3a', 'rev3b'},
281
281
                         graph.heads(['rev3a', 'rev3b', 'rev2a', 'rev2b']))
282
282
 
283
283
    def test_heads_shortcut(self):
284
284
        graph = self.make_known_graph(test_graph.history_shortcut)
285
 
        self.assertEqual(set(['rev2a', 'rev2b', 'rev2c']),
 
285
        self.assertEqual({'rev2a', 'rev2b', 'rev2c'},
286
286
                         graph.heads(['rev2a', 'rev2b', 'rev2c']))
287
 
        self.assertEqual(set(['rev3a', 'rev3b']),
 
287
        self.assertEqual({'rev3a', 'rev3b'},
288
288
                         graph.heads(['rev3a', 'rev3b']))
289
 
        self.assertEqual(set(['rev3a', 'rev3b']),
 
289
        self.assertEqual({'rev3a', 'rev3b'},
290
290
                         graph.heads(['rev2a', 'rev3a', 'rev3b']))
291
 
        self.assertEqual(set(['rev2a', 'rev3b']),
 
291
        self.assertEqual({'rev2a', 'rev3b'},
292
292
                         graph.heads(['rev2a', 'rev3b']))
293
 
        self.assertEqual(set(['rev2c', 'rev3a']),
 
293
        self.assertEqual({'rev2c', 'rev3a'},
294
294
                         graph.heads(['rev2c', 'rev3a']))
295
295
 
296
296
    def test_heads_linear(self):
297
297
        graph = self.make_known_graph(test_graph.racing_shortcuts)
298
 
        self.assertEqual(set(['w']), graph.heads(['w', 's']))
299
 
        self.assertEqual(set(['z']), graph.heads(['w', 's', 'z']))
300
 
        self.assertEqual(set(['w', 'q']), graph.heads(['w', 's', 'q']))
301
 
        self.assertEqual(set(['z']), graph.heads(['s', 'z']))
 
298
        self.assertEqual({'w'}, graph.heads(['w', 's']))
 
299
        self.assertEqual({'z'}, graph.heads(['w', 's', 'z']))
 
300
        self.assertEqual({'w', 'q'}, graph.heads(['w', 's', 'q']))
 
301
        self.assertEqual({'z'}, graph.heads(['s', 'z']))
302
302
 
303
303
    def test_heads_alt_merge(self):
304
304
        graph = self.make_known_graph(alt_merge)
305
 
        self.assertEqual(set(['c']), graph.heads(['a', 'c']))
 
305
        self.assertEqual({'c'}, graph.heads(['a', 'c']))
306
306
 
307
307
    def test_heads_with_ghost(self):
308
308
        graph = self.make_known_graph(test_graph.with_ghost)
309
 
        self.assertEqual(set(['e', 'g']), graph.heads(['e', 'g']))
310
 
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c']))
311
 
        self.assertEqual(set(['a', 'g']), graph.heads(['a', 'g']))
312
 
        self.assertEqual(set(['f', 'g']), graph.heads(['f', 'g']))
313
 
        self.assertEqual(set(['c']), graph.heads(['c', 'g']))
314
 
        self.assertEqual(set(['c']), graph.heads(['c', 'b', 'd', 'g']))
315
 
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'e', 'g']))
316
 
        self.assertEqual(set(['a', 'c']), graph.heads(['a', 'c', 'f']))
 
309
        self.assertEqual({'e', 'g'}, graph.heads(['e', 'g']))
 
310
        self.assertEqual({'a', 'c'}, graph.heads(['a', 'c']))
 
311
        self.assertEqual({'a', 'g'}, graph.heads(['a', 'g']))
 
312
        self.assertEqual({'f', 'g'}, graph.heads(['f', 'g']))
 
313
        self.assertEqual({'c'}, graph.heads(['c', 'g']))
 
314
        self.assertEqual({'c'}, graph.heads(['c', 'b', 'd', 'g']))
 
315
        self.assertEqual({'a', 'c'}, graph.heads(['a', 'c', 'e', 'g']))
 
316
        self.assertEqual({'a', 'c'}, graph.heads(['a', 'c', 'f']))
317
317
 
318
318
    def test_filling_in_ghosts_resets_head_cache(self):
319
319
        graph = self.make_known_graph(test_graph.with_ghost)
320
 
        self.assertEqual(set(['e', 'g']), graph.heads(['e', 'g']))
 
320
        self.assertEqual({'e', 'g'}, graph.heads(['e', 'g']))
321
321
        # 'g' is filled in, and decends from 'e', so the heads result is now
322
322
        # different
323
323
        graph.add_node('g', ['e'])
324
 
        self.assertEqual(set(['g']), graph.heads(['e', 'g']))
 
324
        self.assertEqual({'g'}, graph.heads(['e', 'g']))
325
325
 
326
326
 
327
327
class TestKnownGraphTopoSort(TestCaseWithKnownGraph):