@@ -901,36 +901,18 @@ def test_get_fips_mode(self):
901
901
if fips_mode is not None :
902
902
self .assertIsInstance (fips_mode , int )
903
903
904
- def test_disallow_instanciation (self ):
905
- constructors = []
906
- try :
907
- import _md5
908
- constructors .append (_md5 .md5 )
909
- except ImportError :
910
- pass
911
- try :
912
- import _sha1
913
- constructors .append (_sha1 .sha1 )
914
- except ImportError :
915
- pass
916
- try :
917
- import _sha256
918
- constructors .append (_sha256 .sha224 )
919
- constructors .append (_sha256 .sha256 )
920
- except ImportError :
921
- pass
922
- try :
923
- import _sha512
924
- constructors .append (_sha512 .sha384 )
925
- constructors .append (_sha512 .sha512 )
926
- except ImportError :
927
- pass
928
-
929
- for constructor in constructors :
930
- h = constructor ()
931
- with self .subTest (constructor = constructor ):
932
- hash_type = type (h )
933
- self .assertRaises (TypeError , hash_type )
904
+ @support .cpython_only
905
+ def test_disallow_instantiation (self ):
906
+ for algorithm , constructors in self .constructors_to_test .items ():
907
+ if algorithm .startswith (("sha3_" , "shake" , "blake" )):
908
+ # _sha3 and _blake types can be instantiated
909
+ continue
910
+ # all other types have DISALLOW_INSTANTIATION
911
+ for constructor in constructors :
912
+ h = constructor ()
913
+ with self .subTest (constructor = constructor ):
914
+ hash_type = type (h )
915
+ self .assertRaises (TypeError , hash_type )
934
916
935
917
@unittest .skipUnless (HASH is not None , 'need _hashlib' )
936
918
def test_hash_disallow_instanciation (self ):
0 commit comments