summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 46d646f..e401090 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -12,6 +12,7 @@ import fnmatch
import functools
import gc
import glob
+import hashlib
import importlib
import importlib.util
import locale
@@ -648,6 +649,29 @@ def requires_mac_ver(*min_version):
return decorator
+def requires_hashdigest(digestname):
+ """Decorator raising SkipTest if a hashing algorithm is not available
+
+ The hashing algorithm could be missing or blocked by a strict crypto
+ policy.
+
+ ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
+ ValueError: unsupported hash type md4
+ """
+ def decorator(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ try:
+ hashlib.new(digestname)
+ except ValueError:
+ raise unittest.SkipTest(
+ f"hash digest '{digestname}' is not available."
+ )
+ return func(*args, **kwargs)
+ return wrapper
+ return decorator
+
+
HOST = "localhost"
HOSTv4 = "127.0.0.1"
HOSTv6 = "::1"