]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-135571: Guard `_hashlib` usage in `test_hashlib.py` (#135572)
authorWill Childs-Klein <willck93@gmail.com>
Fri, 27 Jun 2025 15:01:16 +0000 (11:01 -0400)
committerGitHub <noreply@github.com>
Fri, 27 Jun 2025 15:01:16 +0000 (17:01 +0200)
Lib/test/test_hashlib.py

index 7b378c45e71563bcd1feff4ecd441690c7caf2bd..5bad483ae9dafc35a259535833ef7faa4abea686 100644 (file)
@@ -279,7 +279,10 @@ class HashLibTestCase(unittest.TestCase):
                 with self.assertWarnsRegex(DeprecationWarning,
                                            DEPRECATED_STRING_PARAMETER):
                     hashlib.new(digest_name, string=b'')
-                if self._hashlib:
+                # Make sure that _hashlib contains the constructor
+                # to test when using a combination of libcrypto and
+                # interned hash implementations.
+                if self._hashlib and digest_name in self._hashlib._constructors:
                     self._hashlib.new(digest_name, b'')
                     self._hashlib.new(digest_name, data=b'')
                     with self.assertWarnsRegex(DeprecationWarning,
@@ -333,7 +336,8 @@ class HashLibTestCase(unittest.TestCase):
                 with self.subTest(digest_name, args=args, kwds=kwds):
                     with self.assertRaisesRegex(TypeError, errmsg):
                         hashlib.new(digest_name, *args, **kwds)
-                    if self._hashlib:
+                    if (self._hashlib and
+                            digest_name in self._hashlib._constructors):
                         with self.assertRaisesRegex(TypeError, errmsg):
                             self._hashlib.new(digest_name, *args, **kwds)