453
453
graph.heads(['rev2a', 'rev3b']))
454
454
self.assertEqual(set(['rev2c', 'rev3a']),
455
455
graph.heads(['rev2c', 'rev3a']))
457
def _run_heads_break_deeper(self, graph_dict, search):
458
"""Run heads on a graph-as-a-dict.
460
If the search asks for the parents of 'deeper' the test will fail.
464
def get_parents(keys):
468
self.fail('key deeper was accessed')
469
result.append(graph_dict[key])
472
an_obj.get_parents = get_parents
473
graph = _mod_graph.Graph(an_obj)
474
return graph.heads(search)
476
def test_heads_limits_search(self):
477
# test that a heads query does not search all of history
483
self.assertEqual(set(['left', 'right']),
484
self._run_heads_break_deeper(graph_dict, ['left', 'right']))
486
def test_heads_limits_search_assymetric(self):
487
# test that a heads query does not search all of history
490
'midleft':['common'],
492
'common':['aftercommon'],
493
'aftercommon':['deeper'],
495
self.assertEqual(set(['left', 'right']),
496
self._run_heads_break_deeper(graph_dict, ['left', 'right']))
498
def test_heads_limits_search_common_search_must_continue(self):
499
# test that common nodes are still queried, preventing
500
# all-the-way-to-origin behaviour in the following graph:
502
'h1':['shortcut', 'common1'],
504
'shortcut':['common2'],
505
'common1':['common2'],
506
'common2':['deeper'],
508
self.assertEqual(set(['h1', 'h2']),
509
self._run_heads_break_deeper(graph_dict, ['h1', 'h2']))