diff options
author | Brandt Bucher <brandt@python.org> | 2021-09-04 14:14:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-04 14:14:27 (GMT) |
commit | 3beef86e22ade0ec629fcc349885fcec5ab43402 (patch) | |
tree | 6f29caf17c67ae9b83d6f931864ec2bebf159009 /Lib/test/test_marshal.py | |
parent | 0b58e863df9970b290a4de90c67f9ac30c443817 (diff) | |
download | cpython-3beef86e22ade0ec629fcc349885fcec5ab43402.zip cpython-3beef86e22ade0ec629fcc349885fcec5ab43402.tar.gz cpython-3beef86e22ade0ec629fcc349885fcec5ab43402.tar.bz2 |
Handle different string hash algorithms correctly (#28147)
Diffstat (limited to 'Lib/test/test_marshal.py')
-rw-r--r-- | Lib/test/test_marshal.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index bdfe79f..8d55382 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -352,17 +352,20 @@ class BugsTestCase(unittest.TestCase): for elements in ( "float('nan'), b'a', b'b', b'c', 'x', 'y', 'z'", # Also test for bad interactions with backreferencing: - "('string', 1), ('string', 2), ('string', 3)", + "('Spam', 0), ('Spam', 1), ('Spam', 2)", ): s = f"{kind}([{elements}])" with self.subTest(s): # First, make sure that our test case still has different # orders under hash seeds 0 and 1. If this check fails, we - # need to update this test with different elements: - args = ["-c", f"print({s})"] - _, repr_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0") - _, repr_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1") - self.assertNotEqual(repr_0, repr_1) + # need to update this test with different elements. Skip + # this part if we are configured to use any other hash + # algorithm (for example, using Py_HASH_EXTERNAL): + if sys.hash_info.algorithm in {"fnv", "siphash24"}: + args = ["-c", f"print({s})"] + _, repr_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0") + _, repr_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1") + self.assertNotEqual(repr_0, repr_1) # Then, perform the actual test: args = ["-c", f"import marshal; print(marshal.dumps({s}))"] _, dump_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0") |