@@ -1504,42 +1504,33 @@ def test_with_fallback(self):
15041504 cache .pop ('foo' )
15051505
15061506 @hashlib_helper .requires_openssl_hashdigest ("md5" )
1507- @bigmemtest (size = _4G , memuse = 2 , dry_run = False )
1507+ @bigmemtest (size = _4G + 5 , memuse = 2 , dry_run = False )
15081508 def test_hmac_digest_overflow_error_openssl_only (self , size ):
1509- self .do_test_hmac_digest_overflow_error_fast (size , openssl = True )
1509+ hmac = import_fresh_module ("hmac" , blocked = ["_hmac" ])
1510+ self .do_test_hmac_digest_overflow_error_switch_to_slow (hmac , size )
15101511
15111512 @hashlib_helper .requires_builtin_hashdigest ("_md5" , "md5" )
1512- @bigmemtest (size = _4G , memuse = 2 , dry_run = False )
1513+ @bigmemtest (size = _4G + 5 , memuse = 2 , dry_run = False )
15131514 def test_hmac_digest_overflow_error_builtin_only (self , size ):
1514- self .do_test_hmac_digest_overflow_error_fast (size , openssl = False )
1515-
1516- def do_test_hmac_digest_overflow_error_fast (self , size , * , openssl ):
1517- """Check that C hmac.digest() works for large inputs."""
1518-
1519- if openssl :
1520- hmac = import_fresh_module ("hmac" , blocked = ["_hashlib" ])
1521- c_module_name , c_method_name = "_hmac" , "new"
1522- else :
1523- hmac = import_fresh_module ("hmac" , blocked = ["_hmac" ])
1524- c_module_name , c_method_name = "_hashlib" , "hmac_new"
1515+ hmac = import_fresh_module ("hmac" , blocked = ["_hashlib" ])
1516+ self .do_test_hmac_digest_overflow_error_switch_to_slow (hmac , size )
15251517
1526- cext = import_helper . import_module ( c_module_name )
1527- cnew = getattr ( cext , c_method_name )
1518+ def do_test_hmac_digest_overflow_error_switch_to_slow ( self , hmac , size ):
1519+ """Check that hmac.digest() falls back to pure Python."""
15281520
15291521 bigkey = b'K' * size
15301522 bigmsg = b'M' * size
15311523
15321524 with patch .object (hmac , "_compute_digest_fallback" ) as slow :
1533- with patch .object (cext , c_method_name , wraps = cnew ) as new :
1534- self .assertIsInstance (hmac .digest (bigkey , b'm' , "md5" ), bytes )
1535- new .assert_called_once ()
1536- with patch .object (cext , c_method_name , wraps = cnew ) as new :
1537- self .assertIsInstance (hmac .digest (b'k' , bigmsg , "md5" ), bytes )
1538- new .assert_called_once ()
1539- slow .assert_not_called ()
1525+ self .assertIsInstance (hmac .digest (bigkey , b'm' , "md5" ), bytes )
1526+ slow .assert_called_once ()
1527+
1528+ with patch .object (hmac , "_compute_digest_fallback" ) as slow :
1529+ self .assertIsInstance (hmac .digest (b'k' , bigmsg , "md5" ), bytes )
1530+ slow .assert_called_once ()
15401531
15411532 @hashlib_helper .requires_hashdigest ("md5" , openssl = True )
1542- @bigmemtest (size = _4G , memuse = 2 , dry_run = False )
1533+ @bigmemtest (size = _4G + 5 , memuse = 2 , dry_run = False )
15431534 def test_hmac_digest_no_overflow_error_in_fallback (self , size ):
15441535 hmac = import_fresh_module ("hmac" , blocked = ["_hashlib" , "_hmac" ])
15451536
0 commit comments