Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7401694

Browse files
authored
bpo-45624: make test_graphlib not depend on the iteration order of sets (pythonGH-29233)
the current test depended on integer sets being iterated on in a certainfixed order. That order is different on PyPy (insertion based) and couldchange in CPython in the future in theory. Make the test robust againsta different iteration order by sorting.
1 parent03db1bb commit7401694

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

‎Lib/test/test_graphlib.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ def static_order_with_groups(ts):
1313
nodes=ts.get_ready()
1414
fornodeinnodes:
1515
ts.done(node)
16-
yieldnodes
16+
yieldtuple(sorted(nodes))
1717

1818
ts=graphlib.TopologicalSorter(graph)
1919
self.assertEqual(list(static_order_with_groups(ts)),list(expected))
2020

2121
ts=graphlib.TopologicalSorter(graph)
22-
self.assertEqual(list(ts.static_order()),list(chain(*expected)))
22+
# need to be a bit careful comparing the result of ts.static_order and
23+
# expected, because the order within a group is dependent on set
24+
# iteration order
25+
it=iter(ts.static_order())
26+
forgroupinexpected:
27+
tsgroup= {next(it)forelementingroup}
28+
self.assertEqual(set(group),tsgroup)
2329

2430
def_assert_cycle(self,graph,cycle):
2531
ts=graphlib.TopologicalSorter()
@@ -36,7 +42,7 @@ def _assert_cycle(self, graph, cycle):
3642
deftest_simple_cases(self):
3743
self._test_graph(
3844
{2: {11},9: {11,8},10: {11,3},11: {7,5},8: {7,3}},
39-
[(3,5,7), (11,8), (2,10,9)],
45+
[(3,5,7), (8,11), (2,9,10)],
4046
)
4147

4248
self._test_graph({1: {}}, [(1,)])
@@ -80,7 +86,7 @@ def test_no_dependencies(self):
8086

8187
deftest_the_node_multiple_times(self):
8288
# Test same node multiple times in dependencies
83-
self._test_graph({1: {2},3: {4},0: [2,4,4,4,4,4]}, [(2,4), (1,3,0)])
89+
self._test_graph({1: {2},3: {4},0: [2,4,4,4,4,4]}, [(2,4), (0,1,3)])
8490

8591
# Test adding the same dependency multiple times
8692
ts=graphlib.TopologicalSorter()
@@ -242,3 +248,6 @@ def check_order_with_hash_seed(seed):
242248
self.assertNotEqual(run1,"")
243249
self.assertNotEqual(run2,"")
244250
self.assertEqual(run1,run2)
251+
252+
if__name__=="__main__":
253+
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp