bpo-45042: Now test classes decorated with requires_hashdigest
are not skipped (GH-28060)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
a1ba3597d2
commit
dd7b816ac8
@ -3773,6 +3773,7 @@ class _TestSharedMemory(BaseTestCase):
|
|||||||
local_sms.buf[:len(binary_data)] = binary_data
|
local_sms.buf[:len(binary_data)] = binary_data
|
||||||
local_sms.close()
|
local_sms.close()
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.platform == "win32", "test is broken on Windows")
|
||||||
def test_shared_memory_basics(self):
|
def test_shared_memory_basics(self):
|
||||||
sms = shared_memory.SharedMemory('test01_tsmb', create=True, size=512)
|
sms = shared_memory.SharedMemory('test01_tsmb', create=True, size=512)
|
||||||
self.addCleanup(sms.unlink)
|
self.addCleanup(sms.unlink)
|
||||||
|
@ -21,8 +21,21 @@ def requires_hashdigest(digestname, openssl=None, usedforsecurity=True):
|
|||||||
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
|
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
|
||||||
ValueError: unsupported hash type md4
|
ValueError: unsupported hash type md4
|
||||||
"""
|
"""
|
||||||
def decorator(func):
|
def decorator(func_or_class):
|
||||||
@functools.wraps(func)
|
if isinstance(func_or_class, type):
|
||||||
|
setUpClass = func_or_class.__dict__.get('setUpClass')
|
||||||
|
if setUpClass is None:
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(func_or_class, cls).setUpClass()
|
||||||
|
setUpClass.__qualname__ = func_or_class.__qualname__ + '.setUpClass'
|
||||||
|
setUpClass.__module__ = func_or_class.__module__
|
||||||
|
else:
|
||||||
|
setUpClass = setUpClass.__func__
|
||||||
|
setUpClass = classmethod(decorator(setUpClass))
|
||||||
|
func_or_class.setUpClass = setUpClass
|
||||||
|
return func_or_class
|
||||||
|
|
||||||
|
@functools.wraps(func_or_class)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
if openssl and _hashlib is not None:
|
if openssl and _hashlib is not None:
|
||||||
@ -33,6 +46,6 @@ def requires_hashdigest(digestname, openssl=None, usedforsecurity=True):
|
|||||||
raise unittest.SkipTest(
|
raise unittest.SkipTest(
|
||||||
f"hash digest '{digestname}' is not available."
|
f"hash digest '{digestname}' is not available."
|
||||||
)
|
)
|
||||||
return func(*args, **kwargs)
|
return func_or_class(*args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Tests for the md5sum script in the Tools directory."""
|
"""Tests for the md5sum script in the Tools directory."""
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
@ -15,8 +16,8 @@ class MD5SumTests(unittest.TestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
cls.script = os.path.join(scriptsdir, 'md5sum.py')
|
cls.script = os.path.join(scriptsdir, 'md5sum.py')
|
||||||
os.mkdir(os_helper.TESTFN)
|
os.mkdir(os_helper.TESTFN_ASCII)
|
||||||
cls.fodder = os.path.join(os_helper.TESTFN, 'md5sum.fodder')
|
cls.fodder = os.path.join(os_helper.TESTFN_ASCII, 'md5sum.fodder')
|
||||||
with open(cls.fodder, 'wb') as f:
|
with open(cls.fodder, 'wb') as f:
|
||||||
f.write(b'md5sum\r\ntest file\r\n')
|
f.write(b'md5sum\r\ntest file\r\n')
|
||||||
cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
|
cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
|
||||||
@ -24,7 +25,7 @@ class MD5SumTests(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
os_helper.rmtree(os_helper.TESTFN)
|
os_helper.rmtree(os_helper.TESTFN_ASCII)
|
||||||
|
|
||||||
def test_noargs(self):
|
def test_noargs(self):
|
||||||
rc, out, err = assert_python_ok(self.script)
|
rc, out, err = assert_python_ok(self.script)
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
Fixes that test classes decorated with ``@hashlib_helper.requires_hashdigest`` were skipped all the time.
|
Loading…
x
Reference in New Issue
Block a user