bpo-43916: Rewrite new hashlib tests, fix typo (GH-25791)

* bpo-43916: Rewrite new hashlib tests, fix typo
* Flag test as cpython only
This commit is contained in:
Christian Heimes 2021-05-01 22:42:36 +02:00 committed by GitHub
parent 55e5c680dd
commit ddbef71a2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -901,31 +901,13 @@ class HashLibTestCase(unittest.TestCase):
if fips_mode is not None: if fips_mode is not None:
self.assertIsInstance(fips_mode, int) self.assertIsInstance(fips_mode, int)
def test_disallow_instanciation(self): @support.cpython_only
constructors = [] def test_disallow_instantiation(self):
try: for algorithm, constructors in self.constructors_to_test.items():
import _md5 if algorithm.startswith(("sha3_", "shake", "blake")):
constructors.append(_md5.md5) # _sha3 and _blake types can be instantiated
except ImportError: continue
pass # all other types have DISALLOW_INSTANTIATION
try:
import _sha1
constructors.append(_sha1.sha1)
except ImportError:
pass
try:
import _sha256
constructors.append(_sha256.sha224)
constructors.append(_sha256.sha256)
except ImportError:
pass
try:
import _sha512
constructors.append(_sha512.sha384)
constructors.append(_sha512.sha512)
except ImportError:
pass
for constructor in constructors: for constructor in constructors:
h = constructor() h = constructor()
with self.subTest(constructor=constructor): with self.subTest(constructor=constructor):