85
85
(8, [0, 1, 4, 5, 6])]),
86
86
[0, 1, 2, 3, 4, 5, 6, 7, 8])
89
class MergeSortTests(TestCase):
91
def assertSortAndIterate(self, graph, branch_tip, result_list,
92
mainline_revisions=None):
93
"""Check that merge based sorting and iter_topo_order on graph works."""
94
self.assertEquals(result_list,
95
merge_sort(graph, branch_tip, mainline_revisions=mainline_revisions))
96
self.assertEqual(result_list,
100
mainline_revisions=mainline_revisions).iter_topo_order()))
102
def test_merge_sort_empty(self):
103
# sorting of an emptygraph does not error
104
self.assertSortAndIterate({}, None, [])
106
def test_merge_sort_not_empty_no_tip(self):
107
# merge sorting of a branch starting with None should result
108
# in an empty list: no revisions are dragged in.
109
self.assertSortAndIterate({0: []}.items(), None, [])
111
def test_merge_sort_one_revision(self):
112
# sorting with one revision as the tip returns the correct fields:
113
# sequence - 0, revision id, merge depth - 0, end_of_merge
114
self.assertSortAndIterate({'id': []}.items(),
116
[(0, 'id', 0, True)])
118
def test_sequence_numbers_increase_no_merges(self):
119
# emit a few revisions with no merges to check the sequence
120
# numbering works in trivial cases
121
self.assertSortAndIterate(
132
def test_sequence_numbers_increase_with_merges(self):
133
# test that sequence numbers increase across merges
134
self.assertSortAndIterate(
137
'C': ['A', 'B']}.items(),
145
def test_merge_depth_with_nested_merges(self):
146
# the merge depth marker should reflect the depth of the revision
147
# in terms of merges out from the mainline
148
# revid, depth, parents:
157
self.assertSortAndIterate(
179
def test_end_of_merge_not_last_revision_in_branch(self):
180
# within a branch only the last revision gets an
181
# end of merge marker.
182
self.assertSortAndIterate(
192
def test_end_of_merge_multiple_revisions_merged_at_once(self):
193
# when multiple branches are merged at once, both of their
194
# branch-endpoints should be listed as end-of-merge.
195
# Also, the order of the multiple merges should be
196
# left-right shown top to bottom.
197
# * means end of merge
206
self.assertSortAndIterate(
207
{'A': ['H', 'B', 'E'],
228
def test_mainline_revs_partial(self):
229
# when a mainline_revisions list is passed this must
230
# override the graphs idea of mainline, and must also
231
# truncate the output to the specified range, if needed.
232
# so we test both at once: a mainline_revisions list that
233
# disagrees with the graph about which revs are 'mainline'
234
# and also truncates the output.
241
# with a mainline of NONE,E,A (the inferred one) this will show the merge
243
# with a overriden mainline of NONE,E,D,B,A it should show:
249
# and thus when truncated to D,B,A it should show
253
# because C is brought in by B in this view and D
254
# is the terminating revision id
255
self.assertSortAndIterate(
267
mainline_revisions=['D', 'B', 'A']
270
def test_mainline_revs_with_none(self):
271
# a simple test to ensure that a mainline_revs
272
# list which goes all the way to None works
273
self.assertSortAndIterate(
279
mainline_revisions=[None, 'A']