Skip to content

Commit ae38619

Browse files
committed
Add regression test
1 parent af19777 commit ae38619

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Lib/test/test_marshal.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ def test_eof(self):
344344
for i in range(len(data)):
345345
self.assertRaises(EOFError, marshal.loads, data[0: i])
346346

347+
def test_deterministic_sets(self):
348+
# bpo-37596: sets and frozensets must always marshal deterministically!
349+
# Test this by seeding string hashes:
350+
elements = "(float('nan'), b'a', b'b', b'c', 'x', 'y', 'z')"
351+
for kind in ("set", "frozenset"):
352+
script = f"import marshal; print(marshal.dumps({kind}({elements})))"
353+
with self.subTest(kind):
354+
# {nan, b"b", "x", b'a', b'c', 'y', 'z'}
355+
_, a, _ = assert_python_ok("-c", script, PYTHONHASHSEED="0")
356+
# {nan, 'x', b'a', 'z', b'b', 'y', b'c'}
357+
_, b, _ = assert_python_ok("-c", script, PYTHONHASHSEED="1")
358+
self.assertEqual(a, b)
359+
360+
347361
LARGE_SIZE = 2**31
348362
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
349363

0 commit comments

Comments
 (0)