~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: John Arbash Meinel
  • Date: 2007-12-18 19:42:10 UTC
  • mto: This revision was merged to the branch mainline in revision 3126.
  • Revision ID: john@arbash-meinel.com-20071218194210-hrciq0bscpg2ge3p
Deprecate get_parents() in favor of get_parent_map()

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from bzrlib import (
18
18
    errors,
19
19
    graph as _mod_graph,
 
20
    symbol_versioning,
20
21
    tests,
21
22
    )
22
23
from bzrlib.revision import NULL_REVISION
449
450
        self.assertEqual((set(['e']), set(['f', 'g'])),
450
451
                         graph.find_difference('e', 'f'))
451
452
 
452
 
    def test_stacked_parents_provider(self):
453
 
 
 
453
    def test_stacked_parents_provider_get_parents(self):
454
454
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
455
455
        parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
456
456
        stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
457
457
        self.assertEqual([['rev4',], ['rev3']],
458
 
                         stacked.get_parents(['rev1', 'rev2']))
 
458
             self.applyDeprecated(symbol_versioning.one_one,
 
459
                                  stacked.get_parents, ['rev1', 'rev2']))
459
460
        self.assertEqual([['rev3',], ['rev4']],
460
 
                         stacked.get_parents(['rev2', 'rev1']))
 
461
             self.applyDeprecated(symbol_versioning.one_one,
 
462
                                  stacked.get_parents, ['rev2', 'rev1']))
461
463
        self.assertEqual([['rev3',], ['rev3']],
462
 
                         stacked.get_parents(['rev2', 'rev2']))
 
464
             self.applyDeprecated(symbol_versioning.one_one,
 
465
                         stacked.get_parents, ['rev2', 'rev2']))
463
466
        self.assertEqual([['rev4',], ['rev4']],
464
 
                         stacked.get_parents(['rev1', 'rev1']))
 
467
             self.applyDeprecated(symbol_versioning.one_one,
 
468
                         stacked.get_parents, ['rev1', 'rev1']))
 
469
 
 
470
    def test_stacked_parents_provider(self):
 
471
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
 
472
        parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
 
473
        stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
 
474
        self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
 
475
                         stacked.get_parent_map(['rev1', 'rev2']))
 
476
        self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
 
477
                         stacked.get_parent_map(['rev2', 'rev1']))
 
478
        self.assertEqual({'rev2':['rev3']},
 
479
                         stacked.get_parent_map(['rev2', 'rev2']))
 
480
        self.assertEqual({'rev1':['rev4']},
 
481
                         stacked.get_parent_map(['rev1', 'rev1']))
465
482
 
466
483
    def test_iter_topo_order(self):
467
484
        graph = self.make_graph(ancestry_1)
676
693
    def test_get_parents(self):
677
694
        """Requesting the same revision should be returned from cache"""
678
695
        self.assertEqual({}, self.caching_pp._cache)
679
 
        self.assertEqual([('b',)], self.caching_pp.get_parents(['a']))
680
 
        self.assertEqual(['a'], self.inst_pp.calls)
681
 
        self.assertEqual([('b',)], self.caching_pp.get_parents(['a']))
682
 
        # No new call, as it should have been returned from the cache
683
 
        self.assertEqual(['a'], self.inst_pp.calls)
684
 
        self.assertEqual({'a':('b',)}, self.caching_pp._cache)
685
 
 
686
 
    def test_get_parents_not_present(self):
 
696
        self.assertEqual([('b',)],
 
697
            self.applyDeprecated(symbol_versioning.one_one,
 
698
            self.caching_pp.get_parents, ['a']))
 
699
        self.assertEqual(['a'], self.inst_pp.calls)
 
700
        self.assertEqual([('b',)],
 
701
            self.applyDeprecated(symbol_versioning.one_one,
 
702
            self.caching_pp.get_parents, ['a']))
 
703
        # No new call, as it should have been returned from the cache
 
704
        self.assertEqual(['a'], self.inst_pp.calls)
 
705
        self.assertEqual({'a':('b',)}, self.caching_pp._cache)
 
706
 
 
707
    def test_get_parent_map(self):
 
708
        """Requesting the same revision should be returned from cache"""
 
709
        self.assertEqual({}, self.caching_pp._cache)
 
710
        self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a']))
 
711
        self.assertEqual(['a'], self.inst_pp.calls)
 
712
        self.assertEqual({'a':('b',)}, self.caching_pp.get_parent_map(['a']))
 
713
        # No new call, as it should have been returned from the cache
 
714
        self.assertEqual(['a'], self.inst_pp.calls)
 
715
        self.assertEqual({'a':('b',)}, self.caching_pp._cache)
 
716
 
 
717
    def test_get_parent_map_not_present(self):
687
718
        """The cache should also track when a revision doesn't exist"""
688
 
        self.assertEqual([None], self.caching_pp.get_parents(['b']))
 
719
        self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
689
720
        self.assertEqual(['b'], self.inst_pp.calls)
690
 
        self.assertEqual([None], self.caching_pp.get_parents(['b']))
 
721
        self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
691
722
        # No new calls
692
723
        self.assertEqual(['b'], self.inst_pp.calls)
693
724
        self.assertEqual({'b':None}, self.caching_pp._cache)
694
725
 
695
 
    def test_get_parents_mixed(self):
 
726
    def test_get_parent_map_mixed(self):
696
727
        """Anything that can be returned from cache, should be"""
697
 
        self.assertEqual([None], self.caching_pp.get_parents(['b']))
 
728
        self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
698
729
        self.assertEqual(['b'], self.inst_pp.calls)
699
 
        self.assertEqual([('b',), None],
700
 
                         self.caching_pp.get_parents(['a', 'b']))
 
730
        self.assertEqual({'a':('b',)},
 
731
                         self.caching_pp.get_parent_map(['a', 'b']))
701
732
        self.assertEqual(['b', 'a'], self.inst_pp.calls)
702
733
 
703
 
    def test_get_parents_repeated(self):
 
734
    def test_get_parent_map_repeated(self):
704
735
        """Asking for the same parent 2x will only forward 1 request."""
705
 
        self.assertEqual([None, ('b',), None],
706
 
                         self.caching_pp.get_parents(['b', 'a', 'b']))
 
736
        self.assertEqual({'a':('b',)},
 
737
                         self.caching_pp.get_parent_map(['b', 'a', 'b']))
707
738
        # Use sorted because we don't care about the order, just that each is
708
739
        # only present 1 time.
709
740
        self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))