Skip to content

Commit 576b08a

Browse files
committed
Migrate requires_hashdigest() to helper
1 parent 2740675 commit 576b08a

3 files changed

Lines changed: 5 additions & 32 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"create_empty_file", "can_symlink", "fs_is_case_insensitive",
8989
# unittest
9090
"is_resource_enabled", "requires", "requires_freebsd_version",
91-
"requires_linux_version", "requires_mac_ver", "requires_hashdigest",
91+
"requires_linux_version", "requires_mac_ver",
9292
"check_syntax_error", "check_syntax_warning",
9393
"TransientResource", "time_out", "socket_peer_reset", "ioerror_peer_reset",
9494
"transient_internet", "BasicTestRunner", "run_unittest", "run_doctest",
@@ -588,35 +588,6 @@ def skip_if_buildbot(reason=None):
588588
isbuildbot = os.environ.get('USER') == 'buildbot'
589589
return unittest.skipIf(isbuildbot, reason)
590590

591-
def requires_hashdigest(digestname, openssl=None):
592-
"""Decorator raising SkipTest if a hashing algorithm is not available
593-
594-
The hashing algorithm could be missing or blocked by a strict crypto
595-
policy.
596-
597-
If 'openssl' is True, then the decorator checks that OpenSSL provides
598-
the algorithm. Otherwise the check falls back to built-in
599-
implementations.
600-
601-
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
602-
ValueError: unsupported hash type md4
603-
"""
604-
def decorator(func):
605-
@functools.wraps(func)
606-
def wrapper(*args, **kwargs):
607-
try:
608-
if openssl and _hashlib is not None:
609-
_hashlib.new(digestname)
610-
else:
611-
hashlib.new(digestname)
612-
except ValueError:
613-
raise unittest.SkipTest(
614-
f"hash digest '{digestname}' is not available."
615-
)
616-
return func(*args, **kwargs)
617-
return wrapper
618-
return decorator
619-
620591

621592
HOST = "localhost"
622593
HOSTv4 = "127.0.0.1"

Lib/test/test_tarfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import tarfile
1212

1313
from test import support
14-
from test.support import script_helper, requires_hashdigest, os_helper
14+
from test.support import os_helper
15+
from test.support import script_helper
1516

1617
# Check for our compression modules.
1718
try:

Lib/test/test_urllib2_localnet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import hashlib
1010

1111
from test import support
12+
from test.support import hashlib_helper
1213

1314
try:
1415
import ssl
@@ -315,14 +316,14 @@ def test_basic_auth_httperror(self):
315316
self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, self.server_url)
316317

317318

319+
@hashlib_helper.requires_hashdigest("md5", openssl=True)
318320
class ProxyAuthTests(unittest.TestCase):
319321
URL = "http://localhost"
320322

321323
USER = "tester"
322324
PASSWD = "test123"
323325
REALM = "TestRealm"
324326

325-
@support.requires_hashdigest("md5")
326327
def setUp(self):
327328
super(ProxyAuthTests, self).setUp()
328329
# Ignore proxy bypass settings in the environment.

0 commit comments

Comments
 (0)