~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Martin Pool
  • Date: 2009-07-10 06:46:10 UTC
  • mto: (4525.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4526.
  • Revision ID: mbp@sourcefrog.net-20090710064610-sqviksbqp5i34sw2
Rename to per_interrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 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
526
526
        graph = self.make_graph(history_shortcut)
527
527
        self.assertEqual(set(['rev2b']), graph.find_lca('rev3a', 'rev3b'))
528
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
 
 
542
529
    def test_recursive_unique_lca(self):
543
530
        """Test finding a unique least common ancestor.
544
531
 
1424
1411
        self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
1425
1412
 
1426
1413
 
1427
 
class TestFindDescendants(TestGraphBase):
1428
 
 
1429
 
    def test_find_descendants_rev1_rev3(self):
1430
 
        graph = self.make_graph(ancestry_1)
1431
 
        descendants = graph.find_descendants('rev1', 'rev3')
1432
 
        self.assertEqual(set(['rev1', 'rev2a', 'rev3']), descendants)
1433
 
 
1434
 
    def test_find_descendants_rev1_rev4(self):
1435
 
        graph = self.make_graph(ancestry_1)
1436
 
        descendants = graph.find_descendants('rev1', 'rev4')
1437
 
        self.assertEqual(set(['rev1', 'rev2a', 'rev2b', 'rev3', 'rev4']),
1438
 
                         descendants)
1439
 
 
1440
 
    def test_find_descendants_rev2a_rev4(self):
1441
 
        graph = self.make_graph(ancestry_1)
1442
 
        descendants = graph.find_descendants('rev2a', 'rev4')
1443
 
        self.assertEqual(set(['rev2a', 'rev3', 'rev4']), descendants)
1444
 
 
1445
 
class TestFindLefthandMerger(TestGraphBase):
1446
 
 
1447
 
    def check_merger(self, result, ancestry, merged, tip):
1448
 
        graph = self.make_graph(ancestry)
1449
 
        self.assertEqual(result, graph.find_lefthand_merger(merged, tip))
1450
 
 
1451
 
    def test_find_lefthand_merger_rev2b(self):
1452
 
        self.check_merger('rev4', ancestry_1, 'rev2b', 'rev4')
1453
 
 
1454
 
    def test_find_lefthand_merger_rev2a(self):
1455
 
        self.check_merger('rev2a', ancestry_1, 'rev2a', 'rev4')
1456
 
 
1457
 
    def test_find_lefthand_merger_rev4(self):
1458
 
        self.check_merger(None, ancestry_1, 'rev4', 'rev2a')
1459
 
 
1460
 
    def test_find_lefthand_merger_f(self):
1461
 
        self.check_merger('i', complex_shortcut, 'f', 'm')
1462
 
 
1463
 
    def test_find_lefthand_merger_g(self):
1464
 
        self.check_merger('i', complex_shortcut, 'g', 'm')
1465
 
 
1466
 
    def test_find_lefthand_merger_h(self):
1467
 
        self.check_merger('n', complex_shortcut, 'h', 'n')
1468
 
 
1469
 
 
1470
 
class TestGetChildMap(TestGraphBase):
1471
 
 
1472
 
    def test_get_child_map(self):
1473
 
        graph = self.make_graph(ancestry_1)
1474
 
        child_map = graph.get_child_map(['rev4', 'rev3', 'rev2a', 'rev2b'])
1475
 
        self.assertEqual({'rev1': ['rev2a', 'rev2b'],
1476
 
                          'rev2a': ['rev3'],
1477
 
                          'rev2b': ['rev4'],
1478
 
                          'rev3': ['rev4']},
1479
 
                          child_map)
1480
 
 
1481
 
 
1482
1414
class TestCachingParentsProvider(tests.TestCase):
1483
1415
    """These tests run with:
1484
1416
 
1637
1569
        self.assertCollapsed(d, d)
1638
1570
 
1639
1571
 
1640
 
class TestGraphThunkIdsToKeys(tests.TestCase):
1641
 
 
1642
 
    def test_heads(self):
1643
 
        # A
1644
 
        # |\
1645
 
        # B C
1646
 
        # |/
1647
 
        # D
1648
 
        d = {('D',): [('B',), ('C',)], ('C',):[('A',)],
1649
 
             ('B',): [('A',)], ('A',): []}
1650
 
        g = _mod_graph.Graph(_mod_graph.DictParentsProvider(d))
1651
 
        graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1652
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'A'])))
1653
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'B'])))
1654
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C'])))
1655
 
        self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C'])))
1656
 
 
1657
 
 
1658
1572
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1659
1573
    """Tests for bzrlib.graph.PendingAncestryResult."""
1660
1574