@@ -611,20 +611,38 @@ def test_with_sha2(self):
611611        self .assertEqual (digest , binascii .unhexlify (self .expected ))
612612
613613
614- class  SanityTestCase (unittest .TestCase ):
614+ class  SanityTestCaseMixin (CreatorMixin ):
615+     hmac_class  =  None 
615616
616617    @hashlib_helper .requires_hashdigest ('sha256' ) 
617-     def  test_exercise_all_methods (self ):
618-         # Exercising all methods once. 
619-         # This must not raise any exceptions 
620-         try :
621-             h  =  hmac .HMAC (b"my secret key" , digestmod = "sha256" )
622-             h .update (b"compute the hash of this text!" )
623-             h .digest ()
624-             h .hexdigest ()
625-             h .copy ()
626-         except  Exception :
627-             self .fail ("Exception raised during normal usage of HMAC class." )
618+     def  test_methods (self ):
619+         h  =  self .hmac_new (b"my secret key" , digestmod = "sha256" )
620+         self .check (h )
621+ 
622+     def  check (self , h ):
623+         self .assertIsInstance (h , self .hmac_class )
624+         self .assertIsNone (h .update (b"compute the hash of this text!" ))
625+         self .assertIsInstance (h .digest (), bytes )
626+         self .assertIsInstance (h .hexdigest (), str )
627+         self .assertIsInstance (h .copy (), self .hmac_class )
628+ 
629+ 
630+ class  PySanityTestCase (ThroughObjectMixin , PyModuleMixin , SanityTestCaseMixin ,
631+                        unittest .TestCase ):
632+ 
633+     @classmethod  
634+     def  setUpClass (cls ):
635+         super ().setUpClass ()
636+         cls .hmac_class  =  cls .hmac .HMAC 
637+ 
638+ 
639+ class  OpenSSLSanityTestCase (ThroughOpenSSLAPIMixin , SanityTestCaseMixin ,
640+                             unittest .TestCase ):
641+ 
642+     @classmethod  
643+     def  setUpClass (cls ):
644+         super ().setUpClass ()
645+         cls .hmac_class  =  _hashlib .HMAC 
628646
629647
630648class  UpdateTestCaseMixin :
0 commit comments