/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test__known_graph.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
class TestCaseWithKnownGraph(tests.TestCase):
73
73
 
74
74
    scenarios = caching_scenarios()
75
 
    module = None # Set by load_tests
 
75
    module = None  # Set by load_tests
76
76
 
77
77
    def make_known_graph(self, ancestry):
78
78
        return self.module.KnownGraph(ancestry, do_cache=self.do_cache)
103
103
        self.assertEqual([b'rev2b', b'rev3'],
104
104
                         sorted(graph.get_parent_keys(b'rev4')))
105
105
        self.assertRaises(KeyError, graph.get_child_keys, b'not_in_graph')
106
 
    
 
106
 
107
107
    def test_parent_with_ghost(self):
108
108
        graph = self.make_known_graph(test_graph.with_ghost)
109
109
        self.assertEqual(None, graph.get_parent_keys(b'g'))
212
212
class TestKnownGraphHeads(TestCaseWithKnownGraph):
213
213
 
214
214
    scenarios = caching_scenarios() + non_caching_scenarios()
215
 
    do_cache = None # Set by load_tests
 
215
    do_cache = None  # Set by load_tests
216
216
 
217
217
    def test_heads_null(self):
218
218
        graph = self.make_known_graph(test_graph.ancestry_1)
359
359
    def test_topo_sort_cycle(self):
360
360
        """TopoSort traps graph with cycles"""
361
361
        g = self.make_known_graph({0: [1],
362
 
                                  1: [0]})
 
362
                                   1: [0]})
363
363
        self.assertRaises(errors.GraphCycleError, g.topo_sort)
364
364
 
365
365
    def test_topo_sort_cycle_2(self):
484
484
                 'F': ['B', 'D'],
485
485
                 }
486
486
        self.assertSortAndIterate(graph, 'F',
487
 
            [('F', 0, (3,), False),
488
 
             ('D', 1, (2, 2, 1), False),
489
 
             ('C', 2, (2, 1, 1), True),
490
 
             ('B', 0, (2,), False),
491
 
             ('A', 0, (1,), True),
492
 
             ])
 
487
                                  [('F', 0, (3,), False),
 
488
                                   ('D', 1, (2, 2, 1), False),
 
489
                                      ('C', 2, (2, 1, 1), True),
 
490
                                      ('B', 0, (2,), False),
 
491
                                      ('A', 0, (1,), True),
 
492
                                   ])
493
493
        # A
494
494
        # |
495
495
        # B-.
507
507
                 'F': ['B', 'D'],
508
508
                 }
509
509
        self.assertSortAndIterate(graph, 'F',
510
 
            [('F', 0, (3,), False),
511
 
             ('D', 1, (2, 1, 2), False),
512
 
             ('C', 2, (2, 2, 1), True),
513
 
             ('X', 1, (2, 1, 1), True),
514
 
             ('B', 0, (2,), False),
515
 
             ('A', 0, (1,), True),
516
 
             ])
 
510
                                  [('F', 0, (3,), False),
 
511
                                   ('D', 1, (2, 1, 2), False),
 
512
                                      ('C', 2, (2, 2, 1), True),
 
513
                                      ('X', 1, (2, 1, 1), True),
 
514
                                      ('B', 0, (2,), False),
 
515
                                      ('A', 0, (1,), True),
 
516
                                   ])
517
517
 
518
518
    def test_merge_depth_with_nested_merges(self):
519
519
        # the merge depth marker should reflect the depth of the revision
538
538
             'H': []
539
539
             },
540
540
            'A',
541
 
            [('A', 0, (3,),  False),
 
541
            [('A', 0, (3,), False),
542
542
             ('B', 1, (1, 3, 2), False),
543
543
             ('C', 1, (1, 3, 1), True),
544
544
             ('D', 0, (2,), False),
574
574
             'J': ['G', 'H'],
575
575
             'K': ['I'],
576
576
             'L': ['J', 'K'],
577
 
            },
 
577
             },
578
578
            'L',
579
579
            [('L', 0, (6,), False),
580
580
             ('K', 1, (1, 3, 2), False),
587
587
             ('C', 1, (1, 1, 1), True),
588
588
             ('D', 0, (3,), False),
589
589
             ('B', 0, (2,), False),
590
 
             ('A', 0, (1,),  True),
 
590
             ('A', 0, (1,), True),
591
591
             ],
592
592
            )
593
593
        # Adding a shortcut from the first revision should not change any of
607
607
             'L': ['J', 'K'],
608
608
             'M': ['A'],
609
609
             'N': ['L', 'M'],
610
 
            },
 
610
             },
611
611
            'N',
612
612
            [('N', 0, (7,), False),
613
613
             ('M', 1, (1, 4, 1), True),
622
622
             ('C', 1, (1, 1, 1), True),
623
623
             ('D', 0, (3,), False),
624
624
             ('B', 0, (2,), False),
625
 
             ('A', 0, (1,),  True),
 
625
             ('A', 0, (1,), True),
626
626
             ],
627
627
            )
628
628
 
709
709
        # root: A: []
710
710
        self.assertSortAndIterate(
711
711
            {'J': ['G', 'I'],
712
 
             'I': ['H',],
 
712
             'I': ['H', ],
713
713
             'H': ['A'],
714
714
             'G': ['D', 'F'],
715
715
             'F': ['E'],
768
768
             'P': ['N'],
769
769
             'Q': ['O', 'P'],
770
770
             'R': ['J', 'Q'],
771
 
            },
 
771
             },
772
772
            'R',
773
773
            [('R', 0, (6,), False),
774
774
             ('Q', 1, (0, 4, 5), False),
802
802
            {'A': [],
803
803
             'B': ['A'],
804
804
             'C': ['B', 'ghost'],
805
 
            },
 
805
             },
806
806
            'C',
807
807
            [('C', 0, (3,), False),
808
808
             ('B', 0, (2,), False),
809
809
             ('A', 0, (1,), True),
810
 
            ])
 
810
             ])
811
811
 
812
812
    def test_lefthand_ghost(self):
813
813
        # ghost
818
818
        self.assertSortAndIterate(
819
819
            {'A': ['ghost'],
820
820
             'B': ['A'],
821
 
            }, 'B',
 
821
             }, 'B',
822
822
            [('B', 0, (2,), False),
823
823
             ('A', 0, (1,), True),
824
 
            ])
 
824
             ])
825
825
 
826
826
    def test_graph_cycle(self):
827
827
        # merge_sort should fail with a simple error when a graph cycle is
837
837
        # |'-'
838
838
        # E
839
839
        self.assertRaises(errors.GraphCycleError,
840
 
            self.assertSortAndIterate,
841
 
                {'A': [],
842
 
                 'B': ['D'],
843
 
                 'C': ['B'],
844
 
                 'D': ['C'],
845
 
                 'E': ['D'],
846
 
                },
847
 
                'E',
848
 
                [])
 
840
                          self.assertSortAndIterate,
 
841
                          {'A': [],
 
842
                           'B': ['D'],
 
843
                              'C': ['B'],
 
844
                              'D': ['C'],
 
845
                              'E': ['D'],
 
846
                           },
 
847
                          'E',
 
848
                          [])
849
849
 
850
850
 
851
851
class TestKnownGraphStableReverseTopoSort(TestCaseWithKnownGraph):
862
862
        self.assertSorted([], {})
863
863
 
864
864
    def test_single(self):
865
 
        self.assertSorted(['a'], {'a':()})
866
 
        self.assertSorted([('a',)], {('a',):()})
867
 
        self.assertSorted([('F', 'a')], {('F', 'a'):()})
 
865
        self.assertSorted(['a'], {'a': ()})
 
866
        self.assertSorted([('a',)], {('a',): ()})
 
867
        self.assertSorted([('F', 'a')], {('F', 'a'): ()})
868
868
 
869
869
    def test_linear(self):
870
 
        self.assertSorted(['c', 'b', 'a'], {'a':(), 'b':('a',), 'c':('b',)})
 
870
        self.assertSorted(['c', 'b', 'a'], {'a': (), 'b': ('a',), 'c': ('b',)})
871
871
        self.assertSorted([('c',), ('b',), ('a',)],
872
 
                          {('a',):(), ('b',): (('a',),), ('c',): (('b',),)})
 
872
                          {('a',): (), ('b',): (('a',),), ('c',): (('b',),)})
873
873
        self.assertSorted([('F', 'c'), ('F', 'b'), ('F', 'a')],
874
 
                          {('F', 'a'):(), ('F', 'b'): (('F', 'a'),),
 
874
                          {('F', 'a'): (), ('F', 'b'): (('F', 'a'),),
875
875
                           ('F', 'c'): (('F', 'b'),)})
876
876
 
877
877
    def test_mixed_ancestries(self):
879
879
        self.assertSorted([('F', 'c'), ('F', 'b'), ('F', 'a'),
880
880
                           ('G', 'c'), ('G', 'b'), ('G', 'a'),
881
881
                           ('Q', 'c'), ('Q', 'b'), ('Q', 'a'),
882
 
                          ],
 
882
                           ],
883
883
                          {('F', 'a'): (), ('F', 'b'): (('F', 'a'),),
884
884
                           ('F', 'c'): (('F', 'b'),),
885
885
                           ('G', 'a'): (), ('G', 'b'): (('G', 'a'),),
886
886
                           ('G', 'c'): (('G', 'b'),),
887
887
                           ('Q', 'a'): (), ('Q', 'b'): (('Q', 'a'),),
888
888
                           ('Q', 'c'): (('Q', 'b'),),
889
 
                          })
 
889
                           })
890
890
 
891
891
    def test_stable_sorting(self):
892
892
        # the sort order should be stable even when extra nodes are added
893
893
        self.assertSorted(['b', 'c', 'a'],
894
 
                          {'a':(), 'b':('a',), 'c':('a',)})
895
 
        self.assertSorted(['b', 'c', 'd', 'a'],
896
 
                          {'a':(), 'b':('a',), 'c':('a',), 'd':('a',)})
897
 
        self.assertSorted(['b', 'c', 'd', 'a'],
898
 
                          {'a':(), 'b':('a',), 'c':('a',), 'd':('a',)})
 
894
                          {'a': (), 'b': ('a',), 'c': ('a',)})
 
895
        self.assertSorted(['b', 'c', 'd', 'a'],
 
896
                          {'a': (), 'b': ('a',), 'c': ('a',), 'd': ('a',)})
 
897
        self.assertSorted(['b', 'c', 'd', 'a'],
 
898
                          {'a': (), 'b': ('a',), 'c': ('a',), 'd': ('a',)})
899
899
        self.assertSorted(['Z', 'b', 'c', 'd', 'a'],
900
 
                          {'a':(), 'b':('a',), 'c':('a',), 'd':('a',),
901
 
                           'Z':('a',)})
 
900
                          {'a': (), 'b': ('a',), 'c': ('a',), 'd': ('a',),
 
901
                           'Z': ('a',)})
902
902
        self.assertSorted(['e', 'b', 'c', 'f', 'Z', 'd', 'a'],
903
903
                          {'a': (), 'b': ('a',), 'c': ('a',), 'd': ('a',),
904
904
                           'Z': ('a',),
908
908
 
909
909
    def test_skip_ghost(self):
910
910
        self.assertSorted(['b', 'c', 'a'],
911
 
                          {'a':(), 'b':('a', 'ghost'), 'c':('a',)})
 
911
                          {'a': (), 'b': ('a', 'ghost'), 'c': ('a',)})
912
912
 
913
913
    def test_skip_mainline_ghost(self):
914
914
        self.assertSorted(['b', 'c', 'a'],
915
 
                          {'a':(), 'b':('ghost', 'a'), 'c':('a',)})
 
915
                          {'a': (), 'b': ('ghost', 'a'), 'c': ('a',)})