~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

NEWS section template into a separate file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from bzrlib import (
18
18
    errors,
22
22
    )
23
23
from bzrlib.revision import NULL_REVISION
24
24
from bzrlib.tests import TestCaseWithMemoryTransport
 
25
from bzrlib.symbol_versioning import deprecated_in
25
26
 
26
27
 
27
28
# Ancestry 1:
237
238
                    'e':['d'], 'f':['e'], 'g':['f'], 'h':['d'], 'i':['g'],
238
239
                    'j':['h'], 'k':['h', 'i'], 'l':['k'], 'm':['l'], 'n':['m'],
239
240
                    'o':['n'], 'p':['o'], 'q':['p'], 'r':['q'], 's':['r'],
240
 
                    't':['i', 's'], 'u':['s', 'j'], 
 
241
                    't':['i', 's'], 'u':['s', 'j'],
241
242
                    }
242
243
 
243
244
# Graph where different walkers will race to find the common and uncommon
525
526
        graph = self.make_graph(history_shortcut)
526
527
        self.assertEqual(set(['rev2b']), graph.find_lca('rev3a', 'rev3b'))
527
528
 
 
529
    def test_lefthand_distance_smoke(self):
 
530
        """A simple does it work test for graph.lefthand_distance(keys)."""
 
531
        graph = self.make_graph(history_shortcut)
 
532
        distance_graph = graph.find_lefthand_distances(['rev3b', 'rev2a'])
 
533
        self.assertEqual({'rev2a': 2, 'rev3b': 3}, distance_graph)
 
534
 
 
535
    def test_lefthand_distance_ghosts(self):
 
536
        """A simple does it work test for graph.lefthand_distance(keys)."""
 
537
        nodes = {'nonghost':[NULL_REVISION], 'toghost':['ghost']}
 
538
        graph = self.make_graph(nodes)
 
539
        distance_graph = graph.find_lefthand_distances(['nonghost', 'toghost'])
 
540
        self.assertEqual({'nonghost': 1, 'toghost': -1}, distance_graph)
 
541
 
528
542
    def test_recursive_unique_lca(self):
529
543
        """Test finding a unique least common ancestor.
530
544
 
661
675
        self.assertEqual((set(['e']), set(['f', 'g'])),
662
676
                         graph.find_difference('e', 'f'))
663
677
 
 
678
 
664
679
    def test_stacked_parents_provider(self):
665
680
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
666
681
        parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
667
 
        stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
 
682
        stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
 
683
        self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
 
684
                         stacked.get_parent_map(['rev1', 'rev2']))
 
685
        self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
 
686
                         stacked.get_parent_map(['rev2', 'rev1']))
 
687
        self.assertEqual({'rev2':['rev3']},
 
688
                         stacked.get_parent_map(['rev2', 'rev2']))
 
689
        self.assertEqual({'rev1':['rev4']},
 
690
                         stacked.get_parent_map(['rev1', 'rev1']))
 
691
    
 
692
    def test_stacked_parents_provider_overlapping(self):
 
693
        # rev2 is availible in both providers.
 
694
        # 1
 
695
        # |
 
696
        # 2
 
697
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
 
698
        parents2 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
 
699
        stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
 
700
        self.assertEqual({'rev2': ['rev1']},
 
701
                         stacked.get_parent_map(['rev2']))
 
702
 
 
703
    def test__stacked_parents_provider_deprecated(self):
 
704
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
 
705
        parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
 
706
        stacked = self.applyDeprecated(deprecated_in((1, 16, 0)),
 
707
                    _mod_graph._StackedParentsProvider, [parents1, parents2])
668
708
        self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
669
709
                         stacked.get_parent_map(['rev1', 'rev2']))
670
710
        self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
698
738
        instrumented_graph.is_ancestor('rev2a', 'rev2b')
699
739
        self.assertTrue('null:' not in instrumented_provider.calls)
700
740
 
 
741
    def test_is_between(self):
 
742
        graph = self.make_graph(ancestry_1)
 
743
        self.assertEqual(True, graph.is_between('null:', 'null:', 'null:'))
 
744
        self.assertEqual(True, graph.is_between('rev1', 'null:', 'rev1'))
 
745
        self.assertEqual(True, graph.is_between('rev1', 'rev1', 'rev4'))
 
746
        self.assertEqual(True, graph.is_between('rev4', 'rev1', 'rev4'))
 
747
        self.assertEqual(True, graph.is_between('rev3', 'rev1', 'rev4'))
 
748
        self.assertEqual(False, graph.is_between('rev4', 'rev1', 'rev3'))
 
749
        self.assertEqual(False, graph.is_between('rev1', 'rev2a', 'rev4'))
 
750
        self.assertEqual(False, graph.is_between('null:', 'rev1', 'rev4'))
 
751
 
701
752
    def test_is_ancestor_boundary(self):
702
753
        """Ensure that we avoid searching the whole graph.
703
 
        
 
754
 
704
755
        This requires searching through b as a common ancestor, so we
705
756
        can identify that e is common.
706
757
        """
726
777
        # 'a' is not in the ancestry of 'c', and 'g' is a ghost
727
778
        expected['g'] = None
728
779
        self.assertEqual(expected, dict(graph.iter_ancestry(['a', 'c'])))
729
 
        expected.pop('a') 
 
780
        expected.pop('a')
730
781
        self.assertEqual(expected, dict(graph.iter_ancestry(['c'])))
731
782
 
732
783
    def test_filter_candidate_lca(self):
834
885
 
835
886
    def _run_heads_break_deeper(self, graph_dict, search):
836
887
        """Run heads on a graph-as-a-dict.
837
 
        
 
888
 
838
889
        If the search asks for the parents of 'deeper' the test will fail.
839
890
        """
840
891
        class stub(object):
981
1032
        :param next: A callable to advance the search.
982
1033
        """
983
1034
        for seen, recipe, included_keys, starts, stops in instructions:
 
1035
            # Adjust for recipe contract changes that don't vary for all the
 
1036
            # current tests.
 
1037
            recipe = ('search',) + recipe
984
1038
            next()
985
1039
            if starts is not None:
986
1040
                search.start_searching(starts)
1000
1054
        search = graph._make_breadth_first_searcher(['head'])
1001
1055
        # At the start, nothing has been seen, to its all excluded:
1002
1056
        result = search.get_result()
1003
 
        self.assertEqual((set(['head']), set(['head']), 0),
 
1057
        self.assertEqual(('search', set(['head']), set(['head']), 0),
1004
1058
            result.get_recipe())
1005
1059
        self.assertEqual(set(), result.get_keys())
1006
1060
        self.assertEqual(set(), search.seen)
1032
1086
        search.start_searching(['head'])
1033
1087
        # head has been seen:
1034
1088
        result = search.get_result()
1035
 
        self.assertEqual((set(['head']), set(['child']), 1),
 
1089
        self.assertEqual(('search', set(['head']), set(['child']), 1),
1036
1090
            result.get_recipe())
1037
1091
        self.assertEqual(set(['head']), result.get_keys())
1038
1092
        self.assertEqual(set(['head']), search.seen)
1069
1123
        search = graph._make_breadth_first_searcher(['head'])
1070
1124
        expected = [
1071
1125
            # NULL_REVISION and ghost1 have not been returned
1072
 
            (set(['head']), (set(['head']), set(['child', 'ghost1']), 1),
 
1126
            (set(['head']),
 
1127
             (set(['head']), set(['child', NULL_REVISION, 'ghost1']), 1),
1073
1128
             ['head'], None, [NULL_REVISION, 'ghost1']),
1074
1129
            # ghost1 has been returned, NULL_REVISION is to be returned in the
1075
1130
            # next iteration.
1082
1137
        search = graph._make_breadth_first_searcher(['head'])
1083
1138
        self.assertSeenAndResult(expected, search, search.next_with_ghosts)
1084
1139
 
 
1140
    def test_breadth_first_stop_searching_late(self):
 
1141
        # A client should be able to say 'stop node X' and have it excluded
 
1142
        # from the result even if X was seen in an older iteration of the
 
1143
        # search.
 
1144
        graph = self.make_graph({
 
1145
            'head':['middle'],
 
1146
            'middle':['child'],
 
1147
            'child':[NULL_REVISION],
 
1148
            NULL_REVISION:[],
 
1149
            })
 
1150
        search = graph._make_breadth_first_searcher(['head'])
 
1151
        expected = [
 
1152
            (set(['head']), (set(['head']), set(['middle']), 1),
 
1153
             ['head'], None, None),
 
1154
            (set(['head', 'middle']), (set(['head']), set(['child']), 2),
 
1155
             ['head', 'middle'], None, None),
 
1156
            # 'middle' came from the previous iteration, but we don't stop
 
1157
            # searching it until *after* advancing the searcher.
 
1158
            (set(['head', 'middle', 'child']),
 
1159
             (set(['head']), set(['middle', 'child']), 1),
 
1160
             ['head'], None, ['middle', 'child']),
 
1161
            ]
 
1162
        self.assertSeenAndResult(expected, search, search.next)
 
1163
        # using next_with_ghosts:
 
1164
        search = graph._make_breadth_first_searcher(['head'])
 
1165
        self.assertSeenAndResult(expected, search, search.next_with_ghosts)
 
1166
 
1085
1167
    def test_breadth_first_get_result_ghosts_are_excluded(self):
1086
1168
        graph = self.make_graph({
1087
1169
            'head':['child', 'ghost'],
1164
1246
        self.assertRaises(StopIteration, search.next)
1165
1247
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
1166
1248
        result = search.get_result()
1167
 
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
1249
        self.assertEqual(('search', set(['ghost', 'head']), set(['ghost']), 2),
1168
1250
            result.get_recipe())
1169
1251
        self.assertEqual(set(['head', NULL_REVISION]), result.get_keys())
1170
1252
        # using next_with_ghosts:
1173
1255
        self.assertRaises(StopIteration, search.next)
1174
1256
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
1175
1257
        result = search.get_result()
1176
 
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
1258
        self.assertEqual(('search', set(['ghost', 'head']), set(['ghost']), 2),
1177
1259
            result.get_recipe())
1178
1260
        self.assertEqual(set(['head', NULL_REVISION]), result.get_keys())
1179
1261
 
1312
1394
        self.assertFindDistance(6, graph, 'g', [('i', 8)])
1313
1395
 
1314
1396
 
 
1397
class TestFindMergeOrder(TestGraphBase):
 
1398
 
 
1399
    def assertMergeOrder(self, expected, graph, tip, base_revisions):
 
1400
        self.assertEqual(expected, graph.find_merge_order(tip, base_revisions))
 
1401
 
 
1402
    def test_parents(self):
 
1403
        graph = self.make_graph(ancestry_1)
 
1404
        self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4',
 
1405
                                                        ['rev3', 'rev2b'])
 
1406
        self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4',
 
1407
                                                        ['rev2b', 'rev3'])
 
1408
 
 
1409
    def test_ancestors(self):
 
1410
        graph = self.make_graph(ancestry_1)
 
1411
        self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4',
 
1412
                                                        ['rev1', 'rev2b'])
 
1413
        self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4',
 
1414
                                                        ['rev2b', 'rev1'])
 
1415
 
 
1416
    def test_shortcut_one_ancestor(self):
 
1417
        # When we have enough info, we can stop searching
 
1418
        graph = self.make_breaking_graph(ancestry_1, ['rev3', 'rev2b', 'rev4'])
 
1419
        # Single ancestors shortcut right away
 
1420
        self.assertMergeOrder(['rev3'], graph, 'rev4', ['rev3'])
 
1421
 
 
1422
    def test_shortcut_after_one_ancestor(self):
 
1423
        graph = self.make_breaking_graph(ancestry_1, ['rev2a', 'rev2b'])
 
1424
        self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
 
1425
 
 
1426
 
1315
1427
class TestCachingParentsProvider(tests.TestCase):
 
1428
    """These tests run with:
 
1429
 
 
1430
    self.inst_pp, a recording parents provider with a graph of a->b, and b is a
 
1431
    ghost.
 
1432
    self.caching_pp, a CachingParentsProvider layered on inst_pp.
 
1433
    """
1316
1434
 
1317
1435
    def setUp(self):
1318
1436
        super(TestCachingParentsProvider, self).setUp()
1337
1455
        self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
1338
1456
        # No new calls
1339
1457
        self.assertEqual(['b'], self.inst_pp.calls)
1340
 
        self.assertEqual({'b':None}, self.caching_pp._cache)
1341
1458
 
1342
1459
    def test_get_parent_map_mixed(self):
1343
1460
        """Anything that can be returned from cache, should be"""
1354
1471
        # Use sorted because we don't care about the order, just that each is
1355
1472
        # only present 1 time.
1356
1473
        self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))
 
1474
 
 
1475
    def test_note_missing_key(self):
 
1476
        """After noting that a key is missing it is cached."""
 
1477
        self.caching_pp.note_missing_key('b')
 
1478
        self.assertEqual({}, self.caching_pp.get_parent_map(['b']))
 
1479
        self.assertEqual([], self.inst_pp.calls)
 
1480
        self.assertEqual(set(['b']), self.caching_pp.missing_keys)
 
1481
 
 
1482
 
 
1483
class TestCachingParentsProviderExtras(tests.TestCaseWithTransport):
 
1484
    """Test the behaviour when parents are provided that were not requested."""
 
1485
 
 
1486
    def setUp(self):
 
1487
        super(TestCachingParentsProviderExtras, self).setUp()
 
1488
        class ExtraParentsProvider(object):
 
1489
 
 
1490
            def get_parent_map(self, keys):
 
1491
                return {'rev1': [], 'rev2': ['rev1',]}
 
1492
 
 
1493
        self.inst_pp = InstrumentedParentsProvider(ExtraParentsProvider())
 
1494
        self.caching_pp = _mod_graph.CachingParentsProvider(
 
1495
            get_parent_map=self.inst_pp.get_parent_map)
 
1496
 
 
1497
    def test_uncached(self):
 
1498
        self.caching_pp.disable_cache()
 
1499
        self.assertEqual({'rev1': []},
 
1500
                         self.caching_pp.get_parent_map(['rev1']))
 
1501
        self.assertEqual(['rev1'], self.inst_pp.calls)
 
1502
        self.assertIs(None, self.caching_pp._cache)
 
1503
 
 
1504
    def test_cache_initially_empty(self):
 
1505
        self.assertEqual({}, self.caching_pp._cache)
 
1506
 
 
1507
    def test_cached(self):
 
1508
        self.assertEqual({'rev1': []},
 
1509
                         self.caching_pp.get_parent_map(['rev1']))
 
1510
        self.assertEqual(['rev1'], self.inst_pp.calls)
 
1511
        self.assertEqual({'rev1': [], 'rev2': ['rev1']},
 
1512
                         self.caching_pp._cache)
 
1513
        self.assertEqual({'rev1': []},
 
1514
                          self.caching_pp.get_parent_map(['rev1']))
 
1515
        self.assertEqual(['rev1'], self.inst_pp.calls)
 
1516
 
 
1517
    def test_disable_cache_clears_cache(self):
 
1518
        # Put something in the cache
 
1519
        self.caching_pp.get_parent_map(['rev1'])
 
1520
        self.assertEqual(2, len(self.caching_pp._cache))
 
1521
        self.caching_pp.disable_cache()
 
1522
        self.assertIs(None, self.caching_pp._cache)
 
1523
 
 
1524
    def test_enable_cache_raises(self):
 
1525
        e = self.assertRaises(AssertionError, self.caching_pp.enable_cache)
 
1526
        self.assertEqual('Cache enabled when already enabled.', str(e))
 
1527
 
 
1528
    def test_cache_misses(self):
 
1529
        self.caching_pp.get_parent_map(['rev3'])
 
1530
        self.caching_pp.get_parent_map(['rev3'])
 
1531
        self.assertEqual(['rev3'], self.inst_pp.calls)
 
1532
 
 
1533
    def test_no_cache_misses(self):
 
1534
        self.caching_pp.disable_cache()
 
1535
        self.caching_pp.enable_cache(cache_misses=False)
 
1536
        self.caching_pp.get_parent_map(['rev3'])
 
1537
        self.caching_pp.get_parent_map(['rev3'])
 
1538
        self.assertEqual(['rev3', 'rev3'], self.inst_pp.calls)
 
1539
 
 
1540
    def test_cache_extras(self):
 
1541
        self.assertEqual({}, self.caching_pp.get_parent_map(['rev3']))
 
1542
        self.assertEqual({'rev2': ['rev1']},
 
1543
                         self.caching_pp.get_parent_map(['rev2']))
 
1544
        self.assertEqual(['rev3'], self.inst_pp.calls)
 
1545
 
 
1546
 
 
1547
class TestCollapseLinearRegions(tests.TestCase):
 
1548
 
 
1549
    def assertCollapsed(self, collapsed, original):
 
1550
        self.assertEqual(collapsed,
 
1551
                         _mod_graph.collapse_linear_regions(original))
 
1552
 
 
1553
    def test_collapse_nothing(self):
 
1554
        d = {1:[2, 3], 2:[], 3:[]}
 
1555
        self.assertCollapsed(d, d)
 
1556
        d = {1:[2], 2:[3, 4], 3:[5], 4:[5], 5:[]}
 
1557
        self.assertCollapsed(d, d)
 
1558
 
 
1559
    def test_collapse_chain(self):
 
1560
        # Any time we have a linear chain, we should be able to collapse
 
1561
        d = {1:[2], 2:[3], 3:[4], 4:[5], 5:[]}
 
1562
        self.assertCollapsed({1:[5], 5:[]}, d)
 
1563
        d = {5:[4], 4:[3], 3:[2], 2:[1], 1:[]}
 
1564
        self.assertCollapsed({5:[1], 1:[]}, d)
 
1565
        d = {5:[3], 3:[4], 4:[1], 1:[2], 2:[]}
 
1566
        self.assertCollapsed({5:[2], 2:[]}, d)
 
1567
 
 
1568
    def test_collapse_with_multiple_children(self):
 
1569
        #    7
 
1570
        #    |
 
1571
        #    6
 
1572
        #   / \
 
1573
        #  4   5
 
1574
        #  |   |
 
1575
        #  2   3
 
1576
        #   \ /
 
1577
        #    1
 
1578
        #
 
1579
        # 4 and 5 cannot be removed because 6 has 2 children
 
1580
        # 2 and 3 cannot be removed because 1 has 2 parents
 
1581
        d = {1:[2, 3], 2:[4], 4:[6], 3:[5], 5:[6], 6:[7], 7:[]}
 
1582
        self.assertCollapsed(d, d)
 
1583
 
 
1584
 
 
1585
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
 
1586
    """Tests for bzrlib.graph.PendingAncestryResult."""
 
1587
 
 
1588
    def test_get_keys(self):
 
1589
        builder = self.make_branch_builder('b')
 
1590
        builder.start_series()
 
1591
        builder.build_snapshot('rev-1', None, [
 
1592
            ('add', ('', 'root-id', 'directory', ''))])
 
1593
        builder.build_snapshot('rev-2', ['rev-1'], [])
 
1594
        builder.finish_series()
 
1595
        repo = builder.get_branch().repository
 
1596
        repo.lock_read()
 
1597
        self.addCleanup(repo.unlock)
 
1598
        result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
 
1599
        self.assertEqual(set(['rev-1', 'rev-2']), set(result.get_keys()))
 
1600
 
 
1601
    def test_get_keys_excludes_ghosts(self):
 
1602
        builder = self.make_branch_builder('b')
 
1603
        builder.start_series()
 
1604
        builder.build_snapshot('rev-1', None, [
 
1605
            ('add', ('', 'root-id', 'directory', ''))])
 
1606
        builder.build_snapshot('rev-2', ['rev-1', 'ghost'], [])
 
1607
        builder.finish_series()
 
1608
        repo = builder.get_branch().repository
 
1609
        repo.lock_read()
 
1610
        self.addCleanup(repo.unlock)
 
1611
        result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
 
1612
        self.assertEqual(sorted(['rev-1', 'rev-2']), sorted(result.get_keys()))
 
1613
 
 
1614
    def test_get_keys_excludes_null(self):
 
1615
        # Make a 'graph' with an iter_ancestry that returns NULL_REVISION
 
1616
        # somewhere other than the last element, which can happen in real
 
1617
        # ancestries.
 
1618
        class StubGraph(object):
 
1619
            def iter_ancestry(self, keys):
 
1620
                return [(NULL_REVISION, ()), ('foo', (NULL_REVISION,))]
 
1621
        result = _mod_graph.PendingAncestryResult(['rev-3'], None)
 
1622
        result_keys = result._get_keys(StubGraph())
 
1623
        # Only the non-null keys from the ancestry appear.
 
1624
        self.assertEqual(set(['foo']), set(result_keys))
 
1625
 
 
1626
 
 
1627
class TestPendingAncestryResultRefine(TestGraphBase):
 
1628
 
 
1629
    def test_refine(self):
 
1630
        # Used when pulling from a stacked repository, so test some revisions
 
1631
        # being satisfied from the stacking branch.
 
1632
        g = self.make_graph(
 
1633
            {"tip":["mid"], "mid":["base"], "tag":["base"],
 
1634
             "base":[NULL_REVISION], NULL_REVISION:[]})
 
1635
        result = _mod_graph.PendingAncestryResult(['tip', 'tag'], None)
 
1636
        result = result.refine(set(['tip']), set(['mid']))
 
1637
        self.assertEqual(set(['mid', 'tag']), result.heads)
 
1638
        result = result.refine(set(['mid', 'tag', 'base']),
 
1639
            set([NULL_REVISION]))
 
1640
        self.assertEqual(set([NULL_REVISION]), result.heads)
 
1641
        self.assertTrue(result.is_empty())
 
1642
 
 
1643
 
 
1644
class TestSearchResultRefine(TestGraphBase):
 
1645
 
 
1646
    def test_refine(self):
 
1647
        # Used when pulling from a stacked repository, so test some revisions
 
1648
        # being satisfied from the stacking branch.
 
1649
        g = self.make_graph(
 
1650
            {"tip":["mid"], "mid":["base"], "tag":["base"],
 
1651
             "base":[NULL_REVISION], NULL_REVISION:[]})
 
1652
        result = _mod_graph.SearchResult(set(['tip', 'tag']),
 
1653
            set([NULL_REVISION]), 4, set(['tip', 'mid', 'tag', 'base']))
 
1654
        result = result.refine(set(['tip']), set(['mid']))
 
1655
        recipe = result.get_recipe()
 
1656
        # We should be starting from tag (original head) and mid (seen ref)
 
1657
        self.assertEqual(set(['mid', 'tag']), recipe[1])
 
1658
        # We should be stopping at NULL (original stop) and tip (seen head)
 
1659
        self.assertEqual(set([NULL_REVISION, 'tip']), recipe[2])
 
1660
        self.assertEqual(3, recipe[3])
 
1661
        result = result.refine(set(['mid', 'tag', 'base']),
 
1662
            set([NULL_REVISION]))
 
1663
        recipe = result.get_recipe()
 
1664
        # We should be starting from nothing (NULL was known as a cut point)
 
1665
        self.assertEqual(set([]), recipe[1])
 
1666
        # We should be stopping at NULL (original stop) and tip (seen head) and
 
1667
        # tag (seen head) and mid(seen mid-point head). We could come back and
 
1668
        # define this as not including mid, for minimal results, but it is
 
1669
        # still 'correct' to include mid, and simpler/easier.
 
1670
        self.assertEqual(set([NULL_REVISION, 'tip', 'tag', 'mid']), recipe[2])
 
1671
        self.assertEqual(0, recipe[3])
 
1672
        self.assertTrue(result.is_empty())