~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-17 07:05:37 UTC
  • mfrom: (4152.1.2 branch.stacked.streams)
  • Revision ID: pqm@pqm.ubuntu.com-20090317070537-zaud24vjs2szna87
(robertc) Add client-side streaming from stacked branches (over
        bzr:// protocols) when the sort order is compatible with doing
        that. (Robert Collins, Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
992
992
        :param next: A callable to advance the search.
993
993
        """
994
994
        for seen, recipe, included_keys, starts, stops in instructions:
 
995
            # Adjust for recipe contract changes that don't vary for all the
 
996
            # current tests.
 
997
            recipe = ('search',) + recipe
995
998
            next()
996
999
            if starts is not None:
997
1000
                search.start_searching(starts)
1011
1014
        search = graph._make_breadth_first_searcher(['head'])
1012
1015
        # At the start, nothing has been seen, to its all excluded:
1013
1016
        result = search.get_result()
1014
 
        self.assertEqual((set(['head']), set(['head']), 0),
 
1017
        self.assertEqual(('search', set(['head']), set(['head']), 0),
1015
1018
            result.get_recipe())
1016
1019
        self.assertEqual(set(), result.get_keys())
1017
1020
        self.assertEqual(set(), search.seen)
1043
1046
        search.start_searching(['head'])
1044
1047
        # head has been seen:
1045
1048
        result = search.get_result()
1046
 
        self.assertEqual((set(['head']), set(['child']), 1),
 
1049
        self.assertEqual(('search', set(['head']), set(['child']), 1),
1047
1050
            result.get_recipe())
1048
1051
        self.assertEqual(set(['head']), result.get_keys())
1049
1052
        self.assertEqual(set(['head']), search.seen)
1203
1206
        self.assertRaises(StopIteration, search.next)
1204
1207
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
1205
1208
        result = search.get_result()
1206
 
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
1209
        self.assertEqual(('search', set(['ghost', 'head']), set(['ghost']), 2),
1207
1210
            result.get_recipe())
1208
1211
        self.assertEqual(set(['head', NULL_REVISION]), result.get_keys())
1209
1212
        # using next_with_ghosts:
1212
1215
        self.assertRaises(StopIteration, search.next)
1213
1216
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
1214
1217
        result = search.get_result()
1215
 
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
1218
        self.assertEqual(('search', set(['ghost', 'head']), set(['ghost']), 2),
1216
1219
            result.get_recipe())
1217
1220
        self.assertEqual(set(['head', NULL_REVISION]), result.get_keys())
1218
1221
 
1527
1530
        self.assertCollapsed(d, d)
1528
1531
 
1529
1532
 
1530
 
class TestPendingAncestryResult(TestCaseWithMemoryTransport):
 
1533
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1531
1534
    """Tests for bzrlib.graph.PendingAncestryResult."""
1532
1535
 
1533
1536
    def test_get_keys(self):
1540
1543
        repo = builder.get_branch().repository
1541
1544
        repo.lock_read()
1542
1545
        self.addCleanup(repo.unlock)
1543
 
        par = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1544
 
        self.assertEqual(set(['rev-1', 'rev-2']), set(par.get_keys()))
 
1546
        result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
 
1547
        self.assertEqual(set(['rev-1', 'rev-2']), set(result.get_keys()))
1545
1548
 
1546
1549
    def test_get_keys_excludes_null(self):
1547
1550
        # Make a 'graph' with an iter_ancestry that returns NULL_REVISION
1550
1553
        class StubGraph(object):
1551
1554
            def iter_ancestry(self, keys):
1552
1555
                return [(NULL_REVISION, ()), ('foo', (NULL_REVISION,))]
1553
 
        par = _mod_graph.PendingAncestryResult(['rev-3'], None)
1554
 
        par_keys = par._get_keys(StubGraph())
 
1556
        result = _mod_graph.PendingAncestryResult(['rev-3'], None)
 
1557
        result_keys = result._get_keys(StubGraph())
1555
1558
        # Only the non-null keys from the ancestry appear.
1556
 
        self.assertEqual(set(['foo']), set(par_keys))
1557
 
 
 
1559
        self.assertEqual(set(['foo']), set(result_keys))
 
1560
 
 
1561
 
 
1562
class TestPendingAncestryResultRefine(TestGraphBase):
 
1563
 
 
1564
    def test_refine(self):
 
1565
        # Used when pulling from a stacked repository, so test some revisions
 
1566
        # being satisfied from the stacking branch.
 
1567
        g = self.make_graph(
 
1568
            {"tip":["mid"], "mid":["base"], "tag":["base"],
 
1569
             "base":[NULL_REVISION], NULL_REVISION:[]})
 
1570
        result = _mod_graph.PendingAncestryResult(['tip', 'tag'], None)
 
1571
        result = result.refine(set(['tip']), set(['mid']))
 
1572
        self.assertEqual(set(['mid', 'tag']), result.heads)
 
1573
        result = result.refine(set(['mid', 'tag', 'base']),
 
1574
            set([NULL_REVISION]))
 
1575
        self.assertEqual(set([NULL_REVISION]), result.heads)
 
1576
        self.assertTrue(result.is_empty())
 
1577
 
 
1578
 
 
1579
class TestSearchResultRefine(TestGraphBase):
 
1580
 
 
1581
    def test_refine(self):
 
1582
        # Used when pulling from a stacked repository, so test some revisions
 
1583
        # being satisfied from the stacking branch.
 
1584
        g = self.make_graph(
 
1585
            {"tip":["mid"], "mid":["base"], "tag":["base"],
 
1586
             "base":[NULL_REVISION], NULL_REVISION:[]})
 
1587
        result = _mod_graph.SearchResult(set(['tip', 'tag']),
 
1588
            set([NULL_REVISION]), 4, set(['tip', 'mid', 'tag', 'base']))
 
1589
        result = result.refine(set(['tip']), set(['mid']))
 
1590
        recipe = result.get_recipe()
 
1591
        # We should be starting from tag (original head) and mid (seen ref)
 
1592
        self.assertEqual(set(['mid', 'tag']), recipe[1])
 
1593
        # We should be stopping at NULL (original stop) and tip (seen head)
 
1594
        self.assertEqual(set([NULL_REVISION, 'tip']), recipe[2])
 
1595
        self.assertEqual(3, recipe[3])
 
1596
        result = result.refine(set(['mid', 'tag', 'base']),
 
1597
            set([NULL_REVISION]))
 
1598
        recipe = result.get_recipe()
 
1599
        # We should be starting from nothing (NULL was known as a cut point)
 
1600
        self.assertEqual(set([]), recipe[1])
 
1601
        # We should be stopping at NULL (original stop) and tip (seen head) and
 
1602
        # tag (seen head) and mid(seen mid-point head). We could come back and
 
1603
        # define this as not including mid, for minimal results, but it is
 
1604
        # still 'correct' to include mid, and simpler/easier.
 
1605
        self.assertEqual(set([NULL_REVISION, 'tip', 'tag', 'mid']), recipe[2])
 
1606
        self.assertEqual(0, recipe[3])
 
1607
        self.assertTrue(result.is_empty())