https://github.com/python/cpython/commit/273d5062ca17ac47354486f3fc6e672a04cf22e0
commit: 273d5062ca17ac47354486f3fc6e672a04cf22e0
branch: main
author: Rafael Santos <[email protected]>
committer: gpshead <[email protected]>
date: 2026-02-20T20:57:29-08:00
summary:
gh-145028: Fix blake2 tests in test_hashlib when it is missing due to build
config (GH-145029)
specifically configure --without-builtin-hashlib-hashes means the otherwise
guaranteed available blake2 family will not exist. this allows the test suite
to still pass.
files:
M Lib/test/test_hashlib.py
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 489bb049d2fadb..f0e2d527af2615 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -134,8 +134,11 @@ def __init__(self, *args, **kwargs):
algorithms.add(algorithm.lower())
_blake2 = self._conditional_import_module('_blake2')
+ blake2_hashes = {'blake2b', 'blake2s'}
if _blake2:
- algorithms.update({'blake2b', 'blake2s'})
+ algorithms.update(blake2_hashes)
+ else:
+ algorithms.difference_update(blake2_hashes)
self.constructors_to_test = {}
for algorithm in algorithms:
@@ -232,7 +235,12 @@ def test_algorithms_available(self):
# all available algorithms must be loadable, bpo-47101
self.assertNotIn("undefined", hashlib.algorithms_available)
for name in hashlib.algorithms_available:
- digest = hashlib.new(name, usedforsecurity=False)
+ with self.subTest(name):
+ try:
+ _ = hashlib.new(name, usedforsecurity=False)
+ except ValueError as exc:
+ self.skip_if_blake2_not_builtin(name, exc)
+ raise
def test_usedforsecurity_true(self):
hashlib.new("sha256", usedforsecurity=True)
@@ -504,6 +512,7 @@ def test_sha3_256_update_over_4gb(self):
self.assertEqual(h.hexdigest(),
"e2d4535e3b613135c14f2fe4e026d7ad8d569db44901740beffa30d430acb038")
@requires_resource('cpu')
+ @requires_blake2
def test_blake2_update_over_4gb(self):
# blake2s or blake2b doesn't matter based on how our C code is
structured, this tests the
# common loop macro logic.
@@ -798,6 +807,12 @@ def test_case_sha512_3(self):
"e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+
"de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b")
+ def skip_if_blake2_not_builtin(self, name, skip_reason):
+ # blake2 builtins may be absent if python built with
+ # a subset of --with-builtin-hashlib-hashes or none.
+ if "blake2" in name and "blake2" not in builtin_hashes:
+ self.skipTest(skip_reason)
+
def check_blake2(self, constructor, salt_size, person_size, key_size,
digest_size, max_offset):
self.assertEqual(constructor.SALT_SIZE, salt_size)
@@ -1080,10 +1095,16 @@ def test_sha256_gil(self):
def test_threaded_hashing_fast(self):
# Same as test_threaded_hashing_slow() but only tests some functions
# since otherwise test_hashlib.py becomes too slow during development.
- for name in ['md5', 'sha1', 'sha256', 'sha3_256', 'blake2s']:
+ algos = ['md5', 'sha1', 'sha256', 'sha3_256', 'blake2s']
+ for name in algos:
if constructor := getattr(hashlib, name, None):
with self.subTest(name):
- self.do_test_threaded_hashing(constructor, is_shake=False)
+ try:
+ self.do_test_threaded_hashing(constructor,
is_shake=False)
+ except ValueError as exc:
+ self.skip_if_blake2_not_builtin(name, exc)
+ raise
+
if shake_128 := getattr(hashlib, 'shake_128', None):
self.do_test_threaded_hashing(shake_128, is_shake=True)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]