~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Robert Collins
  • Date: 2007-10-22 01:23:51 UTC
  • mfrom: (2921.3.1 graph)
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: robertc@robertcollins.net-20071022012351-16lm27an2lbzk038
Merge graph history-access bugfix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
453
453
                         graph.heads(['rev2a', 'rev3b']))
454
454
        self.assertEqual(set(['rev2c', 'rev3a']),
455
455
                         graph.heads(['rev2c', 'rev3a']))
 
456
 
 
457
 
 
458
    def _run_heads_break_deeper(self, graph_dict, search):
 
459
        """Run heads on a graph-as-a-dict.
 
460
        
 
461
        If the search asks for the parents of 'deeper' the test will fail.
 
462
        """
 
463
        class stub(object):
 
464
            pass
 
465
        def get_parents(keys):
 
466
            result = []
 
467
            for key in keys:
 
468
                if key == 'deeper':
 
469
                    import pdb;pdb.set_trace()
 
470
                    self.fail('key deeper was accessed')
 
471
                result.append(graph_dict[key])
 
472
            return result
 
473
        an_obj = stub()
 
474
        an_obj.get_parents = get_parents
 
475
        graph = _mod_graph.Graph(an_obj)
 
476
        return graph.heads(search)
 
477
 
 
478
    def test_heads_limits_search(self):
 
479
        # test that a heads query does not search all of history
 
480
        graph_dict = {
 
481
            'left':['common'],
 
482
            'right':['common'],
 
483
            'common':['deeper'],
 
484
        }
 
485
        self.assertEqual(set(['left', 'right']),
 
486
            self._run_heads_break_deeper(graph_dict, ['left', 'right']))
 
487
 
 
488
    def test_heads_limits_search_assymetric(self):
 
489
        # test that a heads query does not search all of history
 
490
        graph_dict = {
 
491
            'left':['midleft'],
 
492
            'midleft':['common'],
 
493
            'right':['common'],
 
494
            'common':['aftercommon'],
 
495
            'aftercommon':['deeper'],
 
496
        }
 
497
        self.assertEqual(set(['left', 'right']),
 
498
            self._run_heads_break_deeper(graph_dict, ['left', 'right']))
 
499
 
 
500
    def test_heads_limits_search_common_search_must_continue(self):
 
501
        # test that common nodes are still queried, preventing
 
502
        # all-the-way-to-origin behaviour in the following graph:
 
503
        graph_dict = {
 
504
            'h1':['shortcut', 'common1'],
 
505
            'h2':['common1'],
 
506
            'shortcut':['common2'],
 
507
            'common1':['common2'],
 
508
            'common2':['deeper'],
 
509
        }
 
510
        self.assertEqual(set(['h1', 'h2']),
 
511
            self._run_heads_break_deeper(graph_dict, ['h1', 'h2']))