Skip to content

Commit e72a25b

Browse files
committed
Handle different string hash algorithms correctly
1 parent 85ea2d6 commit e72a25b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: Lib/test/test_marshal.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,20 @@ def test_deterministic_sets(self):
352352
for elements in (
353353
"float('nan'), b'a', b'b', b'c', 'x', 'y', 'z'",
354354
# Also test for bad interactions with backreferencing:
355-
"('string', 1), ('string', 2), ('string', 3)",
355+
"('Spam', 0), ('Spam', 1), ('Spam', 2)",
356356
):
357357
s = f"{kind}([{elements}])"
358358
with self.subTest(s):
359359
# First, make sure that our test case still has different
360360
# orders under hash seeds 0 and 1. If this check fails, we
361-
# need to update this test with different elements:
362-
args = ["-c", f"print({s})"]
363-
_, repr_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0")
364-
_, repr_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1")
365-
self.assertNotEqual(repr_0, repr_1)
361+
# need to update this test with different elements. Skip
362+
# this part if we are configured to use any other hash
363+
# algorithm (for example, using Py_HASH_EXTERNAL):
364+
if sys.hash_info.algorithm in {"fnv", "siphash24"}:
365+
args = ["-c", f"print({s})"]
366+
_, repr_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0")
367+
_, repr_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1")
368+
self.assertNotEqual(repr_0, repr_1)
366369
# Then, perform the actual test:
367370
args = ["-c", f"import marshal; print(marshal.dumps({s}))"]
368371
_, dump_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0")

0 commit comments

Comments
 (0)