~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-04 14:48:21 UTC
  • mto: (4349.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4350.
  • Revision ID: v.ladeuil+lp@free.fr-20090504144821-39dvqkikmd3zqkdg
Handle servers proposing several authentication schemes.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Several schemes can be
proposed by the server, try to match each one in turn.
(BasicAuthHandler.auth_match): Delete dead code.

* bzrlib/tests/test_http.py:
(load_tests): Separate proxy and http authentication tests as they
require different server setups.
(TestAuth.create_transport_readonly_server): Simplified by using
parameter provided by load_tests.
(TestAuth.test_changing_nonce): Adapt to new parametrization.
(TestProxyAuth.create_transport_readonly_server): Deleted.

* bzrlib/tests/http_utils.py:
(DigestAndBasicAuthRequestHandler, HTTPBasicAndDigestAuthServer,
ProxyBasicAndDigestAuthServer): Add a test server proposing both
basic and digest auth schemes but accepting only digest as valid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007 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
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
524
525
        graph = self.make_graph(history_shortcut)
525
526
        self.assertEqual(set(['rev2b']), graph.find_lca('rev3a', 'rev3b'))
526
527
 
527
 
    def test_lefthand_distance_smoke(self):
528
 
        """A simple does it work test for graph.lefthand_distance(keys)."""
529
 
        graph = self.make_graph(history_shortcut)
530
 
        distance_graph = graph.find_lefthand_distances(['rev3b', 'rev2a'])
531
 
        self.assertEqual({'rev2a': 2, 'rev3b': 3}, distance_graph)
532
 
 
533
 
    def test_lefthand_distance_ghosts(self):
534
 
        """A simple does it work test for graph.lefthand_distance(keys)."""
535
 
        nodes = {'nonghost':[NULL_REVISION], 'toghost':['ghost']}
536
 
        graph = self.make_graph(nodes)
537
 
        distance_graph = graph.find_lefthand_distances(['nonghost', 'toghost'])
538
 
        self.assertEqual({'nonghost': 1, 'toghost': -1}, distance_graph)
539
 
 
540
528
    def test_recursive_unique_lca(self):
541
529
        """Test finding a unique least common ancestor.
542
530
 
673
661
        self.assertEqual((set(['e']), set(['f', 'g'])),
674
662
                         graph.find_difference('e', 'f'))
675
663
 
676
 
 
677
664
    def test_stacked_parents_provider(self):
678
665
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
679
666
        parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
680
 
        stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
 
667
        stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
681
668
        self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
682
669
                         stacked.get_parent_map(['rev1', 'rev2']))
683
670
        self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
686
673
                         stacked.get_parent_map(['rev2', 'rev2']))
687
674
        self.assertEqual({'rev1':['rev4']},
688
675
                         stacked.get_parent_map(['rev1', 'rev1']))
689
 
    
690
 
    def test_stacked_parents_provider_overlapping(self):
691
 
        # rev2 is availible in both providers.
692
 
        # 1
693
 
        # |
694
 
        # 2
695
 
        parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
696
 
        parents2 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
697
 
        stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
698
 
        self.assertEqual({'rev2': ['rev1']},
699
 
                         stacked.get_parent_map(['rev2']))
700
676
 
701
677
    def test_iter_topo_order(self):
702
678
        graph = self.make_graph(ancestry_1)
1408
1384
        self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
1409
1385
 
1410
1386
 
1411
 
class TestFindDescendants(TestGraphBase):
1412
 
 
1413
 
    def test_find_descendants_rev1_rev3(self):
1414
 
        graph = self.make_graph(ancestry_1)
1415
 
        descendants = graph.find_descendants('rev1', 'rev3')
1416
 
        self.assertEqual(set(['rev1', 'rev2a', 'rev3']), descendants)
1417
 
 
1418
 
    def test_find_descendants_rev1_rev4(self):
1419
 
        graph = self.make_graph(ancestry_1)
1420
 
        descendants = graph.find_descendants('rev1', 'rev4')
1421
 
        self.assertEqual(set(['rev1', 'rev2a', 'rev2b', 'rev3', 'rev4']),
1422
 
                         descendants)
1423
 
 
1424
 
    def test_find_descendants_rev2a_rev4(self):
1425
 
        graph = self.make_graph(ancestry_1)
1426
 
        descendants = graph.find_descendants('rev2a', 'rev4')
1427
 
        self.assertEqual(set(['rev2a', 'rev3', 'rev4']), descendants)
1428
 
 
1429
 
class TestFindLefthandMerger(TestGraphBase):
1430
 
 
1431
 
    def check_merger(self, result, ancestry, merged, tip):
1432
 
        graph = self.make_graph(ancestry)
1433
 
        self.assertEqual(result, graph.find_lefthand_merger(merged, tip))
1434
 
 
1435
 
    def test_find_lefthand_merger_rev2b(self):
1436
 
        self.check_merger('rev4', ancestry_1, 'rev2b', 'rev4')
1437
 
 
1438
 
    def test_find_lefthand_merger_rev2a(self):
1439
 
        self.check_merger('rev2a', ancestry_1, 'rev2a', 'rev4')
1440
 
 
1441
 
    def test_find_lefthand_merger_rev4(self):
1442
 
        self.check_merger(None, ancestry_1, 'rev4', 'rev2a')
1443
 
 
1444
 
    def test_find_lefthand_merger_f(self):
1445
 
        self.check_merger('i', complex_shortcut, 'f', 'm')
1446
 
 
1447
 
    def test_find_lefthand_merger_g(self):
1448
 
        self.check_merger('i', complex_shortcut, 'g', 'm')
1449
 
 
1450
 
    def test_find_lefthand_merger_h(self):
1451
 
        self.check_merger('n', complex_shortcut, 'h', 'n')
1452
 
 
1453
 
 
1454
 
class TestGetChildMap(TestGraphBase):
1455
 
 
1456
 
    def test_get_child_map(self):
1457
 
        graph = self.make_graph(ancestry_1)
1458
 
        child_map = graph.get_child_map(['rev4', 'rev3', 'rev2a', 'rev2b'])
1459
 
        self.assertEqual({'rev1': ['rev2a', 'rev2b'],
1460
 
                          'rev2a': ['rev3'],
1461
 
                          'rev2b': ['rev4'],
1462
 
                          'rev3': ['rev4']},
1463
 
                          child_map)
1464
 
 
1465
 
 
1466
1387
class TestCachingParentsProvider(tests.TestCase):
1467
1388
    """These tests run with:
1468
1389
 
1621
1542
        self.assertCollapsed(d, d)
1622
1543
 
1623
1544
 
1624
 
class TestGraphThunkIdsToKeys(tests.TestCase):
1625
 
 
1626
 
    def test_heads(self):
1627
 
        # A
1628
 
        # |\
1629
 
        # B C
1630
 
        # |/
1631
 
        # D
1632
 
        d = {('D',): [('B',), ('C',)], ('C',):[('A',)],
1633
 
             ('B',): [('A',)], ('A',): []}
1634
 
        g = _mod_graph.Graph(_mod_graph.DictParentsProvider(d))
1635
 
        graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1636
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'A'])))
1637
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'B'])))
1638
 
        self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C'])))
1639
 
        self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C'])))
1640
 
 
1641
 
    def test_add_node(self):
1642
 
        d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []}
1643
 
        g = _mod_graph.KnownGraph(d)
1644
 
        graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1645
 
        graph_thunk.add_node("D", ["A", "C"])
1646
 
        self.assertEqual(['B', 'D'],
1647
 
            sorted(graph_thunk.heads(['D', 'B', 'A'])))
1648
 
 
1649
 
    def test_merge_sort(self):
1650
 
        d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []}
1651
 
        g = _mod_graph.KnownGraph(d)
1652
 
        graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1653
 
        graph_thunk.add_node("D", ["A", "C"])
1654
 
        self.assertEqual([('C', 0, (2,), False), ('A', 0, (1,), True)],
1655
 
            [(n.key, n.merge_depth, n.revno, n.end_of_merge)
1656
 
                 for n in graph_thunk.merge_sort('C')])
1657
 
 
1658
 
 
1659
1545
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1660
1546
    """Tests for bzrlib.graph.PendingAncestryResult."""
1661
1547
 
1672
1558
        result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1673
1559
        self.assertEqual(set(['rev-1', 'rev-2']), set(result.get_keys()))
1674
1560
 
1675
 
    def test_get_keys_excludes_ghosts(self):
1676
 
        builder = self.make_branch_builder('b')
1677
 
        builder.start_series()
1678
 
        builder.build_snapshot('rev-1', None, [
1679
 
            ('add', ('', 'root-id', 'directory', ''))])
1680
 
        builder.build_snapshot('rev-2', ['rev-1', 'ghost'], [])
1681
 
        builder.finish_series()
1682
 
        repo = builder.get_branch().repository
1683
 
        repo.lock_read()
1684
 
        self.addCleanup(repo.unlock)
1685
 
        result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1686
 
        self.assertEqual(sorted(['rev-1', 'rev-2']), sorted(result.get_keys()))
1687
 
 
1688
1561
    def test_get_keys_excludes_null(self):
1689
1562
        # Make a 'graph' with an iter_ancestry that returns NULL_REVISION
1690
1563
        # somewhere other than the last element, which can happen in real