diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index e9def9adb..1743a5db5 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -88,7 +88,7 @@ __all__ = [ "create_empty_file", "can_symlink", "fs_is_case_insensitive", # unittest "is_resource_enabled", "requires", "requires_freebsd_version", - "requires_linux_version", "requires_mac_ver", "requires_hashdigest", + "requires_linux_version", "requires_mac_ver", "check_syntax_error", "check_syntax_warning", "TransientResource", "time_out", "socket_peer_reset", "ioerror_peer_reset", "transient_internet", "BasicTestRunner", "run_unittest", "run_doctest", @@ -588,35 +588,6 @@ def skip_if_buildbot(reason=None): isbuildbot = os.environ.get('USER') == 'buildbot' return unittest.skipIf(isbuildbot, reason) -def requires_hashdigest(digestname, openssl=None): - """Decorator raising SkipTest if a hashing algorithm is not available - - The hashing algorithm could be missing or blocked by a strict crypto - policy. - - If 'openssl' is True, then the decorator checks that OpenSSL provides - the algorithm. Otherwise the check falls back to built-in - implementations. - - 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: - if openssl and _hashlib is not None: - _hashlib.new(digestname) - else: - 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" diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index f58284434..96ff5a68d 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -11,7 +11,8 @@ import unittest.mock import tarfile from test import support -from test.support import script_helper, requires_hashdigest, os_helper +from test.support import os_helper +from test.support import script_helper # Check for our compression modules. try: diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 5a207ae41..21bc91afc 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -9,6 +9,7 @@ import unittest import hashlib from test import support +from test.support import hashlib_helper try: import ssl @@ -315,6 +316,7 @@ class BasicAuthTests(unittest.TestCase): self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, self.server_url) +@hashlib_helper.requires_hashdigest("md5", openssl=True) class ProxyAuthTests(unittest.TestCase): URL = "http://localhost" @@ -322,7 +324,6 @@ class ProxyAuthTests(unittest.TestCase): PASSWD = "test123" REALM = "TestRealm" - @support.requires_hashdigest("md5") def setUp(self): super(ProxyAuthTests, self).setUp() # Ignore proxy bypass settings in the environment.