MCPcopy Index your code
hub / github.com/python/cpython / test_legacy_block_size_warnings

Method test_legacy_block_size_warnings

Lib/test/test_hmac.py:1480–1500  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1478
1479 @hashlib_helper.requires_hashdigest('sha256')
1480 def test_legacy_block_size_warnings(self):
1481 class MockCrazyHash(object):
1482 """Ain't no block_size attribute here."""
1483 def __init__(self, *args):
1484 self._x = hashlib.sha256(*args)
1485 self.digest_size = self._x.digest_size
1486 def update(self, v):
1487 self._x.update(v)
1488 def digest(self):
1489 return self._x.digest()
1490
1491 with warnings.catch_warnings():
1492 warnings.simplefilter('error', RuntimeWarning)
1493 with self.assertRaises(RuntimeWarning):
1494 hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
1495 self.fail('Expected warning about missing block_size')
1496
1497 MockCrazyHash.block_size = 1
1498 with self.assertRaises(RuntimeWarning):
1499 hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
1500 self.fail('Expected warning about small block_size')
1501
1502 @hashlib_helper.requires_hashdigest('sha256')
1503 def test_with_fallback(self):

Callers

nothing calls this directly

Calls 3

assertRaisesMethod · 0.45
HMACMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected