@@ -728,37 +728,50 @@ def test_hmac_digest_digestmod_parameter(self):
728
728
729
729
730
730
class SanityTestCaseMixin (CreatorMixin ):
731
+
731
732
hmac_class = None
733
+ digestname = None
732
734
733
- @hashlib_helper .requires_hashdigest ('sha256' )
734
735
def test_methods (self ):
735
- h = self .hmac_new (b"my secret key" , digestmod = "sha256" )
736
- self .check (h )
737
-
738
- def check (self , h ):
736
+ h = self .hmac_new (b"my secret key" , digestmod = self .digestname )
739
737
self .assertIsInstance (h , self .hmac_class )
740
738
self .assertIsNone (h .update (b"compute the hash of this text!" ))
741
739
self .assertIsInstance (h .digest (), bytes )
742
740
self .assertIsInstance (h .hexdigest (), str )
743
741
self .assertIsInstance (h .copy (), self .hmac_class )
744
742
743
+ def test_repr (self ):
744
+ raise NotImplementedError
745
+
745
746
747
+ @hashlib_helper .requires_hashdigest ('sha256' )
746
748
class PySanityTestCase (ThroughObjectMixin , PyModuleMixin , SanityTestCaseMixin ,
747
749
unittest .TestCase ):
748
750
749
751
@classmethod
750
752
def setUpClass (cls ):
751
753
super ().setUpClass ()
752
754
cls .hmac_class = cls .hmac .HMAC
755
+ cls .digestname = 'sha256'
756
+
757
+ def test_repr (self ):
758
+ h = self .hmac_new (b"my secret key" , digestmod = self .digestname )
759
+ self .assertStartsWith (repr (h ), "<hmac.HMAC object at" )
753
760
754
761
762
+ @hashlib_helper .requires_hashdigest ('sha256' , openssl = True )
755
763
class OpenSSLSanityTestCase (ThroughOpenSSLAPIMixin , SanityTestCaseMixin ,
756
764
unittest .TestCase ):
757
765
758
766
@classmethod
759
767
def setUpClass (cls ):
760
768
super ().setUpClass ()
761
769
cls .hmac_class = _hashlib .HMAC
770
+ cls .digestname = 'sha256'
771
+
772
+ def test_repr (self ):
773
+ h = self .hmac_new (b"my secret key" , digestmod = self .digestname )
774
+ self .assertStartsWith (repr (h ), f"<{ self .digestname } HMAC object @" )
762
775
763
776
764
777
class UpdateTestCaseMixin :
0 commit comments