8000 gh-135571: Guard `_hashlib` usage in `test_hashlib.py` (#135572) · python/cpython@065194c · GitHub
[go: up one dir, main page]

Skip to content

Commit 065194c

Browse files
gh-135571: Guard _hashlib usage in test_hashlib.py (#135572)
1 parent 731f5b8 commit 065194c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_hashlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ def test_clinic_signature(self):
279279
with self.assertWarnsRegex(DeprecationWarning,
280280
DEPRECATED_STRING_PARAMETER):
281281
hashlib.new(digest_name, string=b'')
282-
if self._hashlib:
282+
# Make sure that _hashlib contains the constructor
283+
# to test when using a combination of libcrypto and
284+
# interned hash implementations.
285+
if self._hashlib and digest_name in self._hashlib._constructors:
283286
self._hashlib.new(digest_name, b'')
284287
self._hashlib.new(digest_name, data=b'')
285288
with self.assertWarnsRegex(DeprecationWarning,
@@ -333,7 +336,8 @@ def test_clinic_signature_errors(self):
333336
with self.subTest(digest_name, args=args, kwds=kwds):
334337
with self.assertRaisesRegex(TypeError, errmsg):
335338
hashlib.new(digest_name, *args, **kwds)
336-
if self._hashlib:
339+
if (self._hashlib and
340+
digest_name in self._hashlib._constructors):
337341
with self.assertRaisesRegex(TypeError, errmsg):
338342
self._hashlib.new(digest_name, *args, **kwds)
339343

0 commit comments

Comments
 (0)
0