@@ -98,6 +98,14 @@ def read_vectors(hash_name):
9898 yield parts
9999
100100
101+ DEPRECATED_STRING_PARAMETER = re .escape (
102+ "the 'string' keyword parameter is deprecated since "
103+ "Python 3.15 and slated for removal in Python 3.19; "
104+ "use the 'data' keyword parameter or pass the data "
105+ "to hash as a positional argument instead"
106+ )
107+
108+
101109class HashLibTestCase (unittest .TestCase ):
102110 supported_hash_names = ( 'md5' , 'MD5' , 'sha1' , 'SHA1' ,
103111 'sha224' , 'SHA224' , 'sha256' , 'SHA256' ,
@@ -255,17 +263,23 @@ def test_clinic_signature(self):
255263 with self .subTest (constructor .__name__ ):
256264 constructor (b'' )
257265 constructor (data = b'' )
258- constructor (string = b'' ) # should be deprecated in the future
266+ with self .assertWarnsRegex (DeprecationWarning ,
267+ DEPRECATED_STRING_PARAMETER ):
268+ constructor (string = b'' )
259269
260270 digest_name = constructor (b'' ).name
261271 with self .subTest (digest_name ):
262272 hashlib .new (digest_name , b'' )
263273 hashlib .new (digest_name , data = b'' )
264- hashlib .new (digest_name , string = b'' )
274+ with self .assertWarnsRegex (DeprecationWarning ,
275+ DEPRECATED_STRING_PARAMETER ):
276+ hashlib .new (digest_name , string = b'' )
265277 if self ._hashlib :
266278 self ._hashlib .new (digest_name , b'' )
267279 self ._hashlib .new (digest_name , data = b'' )
268- self ._hashlib .new (digest_name , string = b'' )
280+ with self .assertWarnsRegex (DeprecationWarning ,
281+ DEPRECATED_STRING_PARAMETER ):
282+ self ._hashlib .new (digest_name , string = b'' )
269283
270284 @unittest .skipIf (get_fips_mode (), "skip in FIPS mode" )
271285 def test_clinic_signature_errors (self ):
0 commit comments