Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d80b1b1
add helper for _hashlib detection
picnixz Feb 13, 2025
73b7756
remove unused function `ignore_warning`
picnixz Feb 13, 2025
fe7a300
cleanup whitespaces
picnixz Feb 13, 2025
72f956f
clean imports and test guards
picnixz Feb 13, 2025
3e827a7
Add mixins for interacting with HMAC
picnixz Feb 13, 2025
7f4fcc8
add mixin for RFC test cases
picnixz Feb 13, 2025
e47dd8b
use RFC mixin classes
picnixz Feb 13, 2025
acda122
refactor `CompareDigestTestCase`
picnixz Feb 13, 2025
d2eb48a
refactor `CopyTestCase`
picnixz Feb 13, 2025
105f6ce
refactor `UpdateTestCase`
picnixz Feb 13, 2025
412f5c2
refactor `SanityTestCase`
picnixz Feb 13, 2025
c682945
refactor `ConstructorTestCase`
picnixz Feb 13, 2025
7e62a58
Merge branch 'main' into test/hmac/refactor-99108
picnixz Feb 15, 2025
c04233d
update comments
picnixz Feb 15, 2025
fb7e577
extend coverage
picnixz Feb 15, 2025
168d018
Merge branch 'main' into test/hmac/refactor-99108
picnixz Feb 24, 2025
4177afa
add regression test for HMAC `repr()`
picnixz Feb 25, 2025
644f577
change a bit the digestmod tests
picnixz Feb 25, 2025
e71f03d
Merge branch 'main' into test/hmac/refactor-99108
picnixz Mar 2, 2025
dbe3ce4
remove mixin that is not yet needed
picnixz Mar 3, 2025
ca0822a
add comments
picnixz Mar 3, 2025
a0b3569
semantics: 'digest' -> 'hexdigest'
picnixz Mar 3, 2025
321a7a9
use `__init_subclass__` instead of `setUpClass`
picnixz Mar 3, 2025
ca7851c
document and reorganize method order in `DigestModTestCaseMixin`
picnixz Mar 3, 2025
a347ee5
use separate factories for creating bad digestmod cases
picnixz Mar 3, 2025
85364b4
minor tweak on `CompareDigestMixin`
picnixz Mar 3, 2025
740fe81
do not allow 'hashfunc' or 'hashname' to be None for RFC tests
picnixz Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use __init_subclass__ instead of setUpClass
  • Loading branch information
picnixz committed Mar 3, 2025
commit 321a7a9b070fc77335274a35ea4626107700d3d0
9 changes: 5 additions & 4 deletions Lib/test/test_hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def hmac_digest_by_name(self, key, msg=None, hashname=None):
class RFCTestCasesMixin(TestVectorsMixin):
"""Test HMAC implementations against test vectors from the RFC.

Subclasses must override the 'md5', 'sha1', and 'sha2_*' attributes
Subclasses must override the 'md5' and other 'sha*' attributes
to test the implementations. Their value can be a string, a callable,
or a PEP-257 module.
"""
Expand All @@ -320,6 +320,8 @@ class RFCTestCasesMixin(TestVectorsMixin):
'sha224', 'sha256', 'sha384', 'sha512',
]

# Those will be automatically set to non-None on subclasses
# as they are set by __init_subclass()__.
md5 = sha1 = sha224 = sha256 = sha384 = sha512 = None

def __init_subclass__(cls, *args, **kwargs):
Expand Down Expand Up @@ -575,9 +577,8 @@ class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin, RFCTestCasesMixin,
unittest.TestCase):
"""OpenSSL implementation of HMAC."""

@classmethod
def setUpClass(cls):
super().setUpClass()
def __init_subclass__(cls, *args, **kwargs):
super().__init_subclass__(*args, **kwargs)

for name in cls.ALGORITHMS:
@property
Expand Down