Skip to content

Commit ed8c4ee

Browse files
committed
Use strings for the hash test and compare groups for insertion order
1 parent c0d2ff6 commit ed8c4ee

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

Lib/test/test_functools.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,28 +1379,43 @@ def test_not_hashable_nodes(self):
13791379
self.assertRaises(TypeError, ts.add, 1, dict())
13801380
self.assertRaises(TypeError, ts.add, dict(), dict())
13811381

1382-
def test_order_of_insertion_does_not_matter(self):
1382+
def test_order_of_insertion_does_not_matter_between_groups(self):
1383+
def get_groups(ts):
1384+
ts.prepare()
1385+
while ts.is_active():
1386+
nodes = ts.get_ready()
1387+
for node in nodes:
1388+
ts.done(node)
1389+
yield nodes
1390+
13831391
ts = functools.TopologicalSorter()
13841392
ts.add(3, 2, 1)
1385-
ts.add(2, 1)
13861393
ts.add(1, 0)
1394+
ts.add(4, 5)
1395+
ts.add(6, 7)
1396+
ts.add(4, 7)
13871397

13881398
ts2 = functools.TopologicalSorter()
1389-
ts2.add(2, 1)
13901399
ts2.add(1, 0)
13911400
ts2.add(3, 2, 1)
1401+
ts2.add(4, 7)
1402+
ts2.add(6, 7)
1403+
ts2.add(4, 5)
13921404

1393-
self.assertEqual([*ts.static_order()], [*ts2.static_order()])
1405+
self.assertEqual(
1406+
list(map(set, get_groups(ts))),
1407+
list(map(set, get_groups(ts2)))
1408+
)
13941409

13951410
def test_static_order_does_not_change_with_the_hash_seed(self):
13961411
def check_order_with_hash_seed(seed):
13971412
code = """if 1:
13981413
import functools
13991414
ts = functools.TopologicalSorter()
1400-
ts.add(1, 2, 3, 4, 5)
1401-
ts.add(2, 3, 4, 5, 6)
1402-
ts.add(4, 11, 45, 3)
1403-
ts.add(0, 11, 2, 3, 4)
1415+
ts.add('blech', 'bluch', 'hola')
1416+
ts.add('abcd', 'blech', 'bluch', 'a', 'b')
1417+
ts.add('a', 'a string', 'something', 'b')
1418+
ts.add('bluch', 'hola', 'abcde', 'a', 'b')
14041419
print(list(ts.static_order()))
14051420
"""
14061421
env = os.environ.copy()

0 commit comments

Comments
 (0)