Skip to content

Commit 83690dc

Browse files
picnixzseehwan80
authored andcommitted
pythongh-130149: refactor tests for HMAC (python#130150)
Since we plan to introduce a built-in implementation for HMAC based on HACL*, it becomes important for the HMAC tests to be flexible enough to avoid code duplication. In addition to the new layout based on mixin classes, we extend test coverage by also testing the `__repr__` of HMAC objects and the HMAC one-shot functions. We also fix the import to `_sha256` which, since pythongh-101924, resulted in some tests being skipped as the module is no more available (its content was moved to the `_sha2` module).
1 parent e3d0350 commit 83690dc

File tree

2 files changed

+818
-417
lines changed

2 files changed

+818
-417
lines changed

Lib/test/support/hashlib_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
_hashlib = None
99

1010

11+
def requires_hashlib():
12+
return unittest.skipIf(_hashlib is None, "requires _hashlib")
13+
14+
1115
def requires_hashdigest(digestname, openssl=None, usedforsecurity=True):
1216
"""Decorator raising SkipTest if a hashing algorithm is not available
1317
@@ -44,7 +48,7 @@ def wrapper(*args, **kwargs):
4448
hashlib.new(digestname, usedforsecurity=usedforsecurity)
4549
except ValueError:
4650
raise unittest.SkipTest(
47-
f"hash digest '{digestname}' is not available."
51+
f"hash digest {digestname!r} is not available."
4852
)
4953
return func_or_class(*args, **kwargs)
5054
return wrapper

0 commit comments

Comments
 (0)