[3.13] gh-135571: Guard _hashlib usage in test_hashlib.py (GH-135572) (#136041)

(cherry picked from commit 065194c1a9)

Co-authored-by: Will Childs-Klein <willck93@gmail.com>
This commit is contained in:
Bénédikt Tran 2025-06-28 10:15:49 +02:00 committed by GitHub
parent ad1b0c942d
commit d3bcecdcdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -264,7 +264,10 @@ def test_clinic_signature(self):
hashlib.new(digest_name, b'')
hashlib.new(digest_name, data=b'')
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'')
self._hashlib.new(digest_name, string=b'')
@ -316,7 +319,8 @@ def test_clinic_signature_errors(self):
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)