|
12 | 12 | import itertools |
13 | 13 | import logging |
14 | 14 | import os |
| 15 | +import re |
15 | 16 | import sys |
16 | 17 | import sysconfig |
17 | 18 | import tempfile |
@@ -140,11 +141,12 @@ def __init__(self, *args, **kwargs): |
140 | 141 | # of hashlib.new given the algorithm name. |
141 | 142 | for algorithm, constructors in self.constructors_to_test.items(): |
142 | 143 | constructors.add(getattr(hashlib, algorithm)) |
143 | | - def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm, **kwargs): |
144 | | - if data is None: |
| 144 | + def c(_data=None, _alg=algorithm, **kwargs): |
| 145 | + if _data is None: |
145 | 146 | return hashlib.new(_alg, **kwargs) |
146 | | - return hashlib.new(_alg, data, **kwargs) |
147 | | - constructors.add(_test_algorithm_via_hashlib_new) |
| 147 | + return hashlib.new(_alg, _data, **kwargs) |
| 148 | + c.__name__ = f'do_test_algorithm_via_hashlib_new_{algorithm}' |
| 149 | + constructors.add(c) |
148 | 150 |
|
149 | 151 | _hashlib = self._conditional_import_module('_hashlib') |
150 | 152 | self._hashlib = _hashlib |
@@ -251,8 +253,25 @@ def test_usedforsecurity_false(self): |
251 | 253 |
|
252 | 254 | def test_clinic_signature(self): |
253 | 255 | for constructor in self.hash_constructors: |
254 | | - with self.subTest(constructor): |
| 256 | + with self.subTest(constructor.__name__): |
255 | 257 | constructor(data=b'') |
| 258 | + constructor(string=b'') # should be deprecated in the future |
| 259 | + |
| 260 | + def test_clinic_signature_errors(self): |
| 261 | + conflicting_call = re.escape( |
| 262 | + "'data' and 'string' are mutually exclusive " |
| 263 | + "and support for 'string' keyword parameter " |
| 264 | + "is slated for removal in a future version." |
| 265 | + ) |
| 266 | + duplicated_param = re.escape("given by name ('data') and position") |
| 267 | + for constructor in self.hash_constructors: |
| 268 | + with self.subTest(constructor.__name__): |
| 269 | + with self.assertRaisesRegex(TypeError, conflicting_call): |
| 270 | + constructor(b'', string=b'') |
| 271 | + with self.assertRaisesRegex(TypeError, conflicting_call): |
| 272 | + constructor(data=b'', string=b'') |
| 273 | + with self.assertRaisesRegex(TypeError, duplicated_param): |
| 274 | + constructor(b'', data=b'') |
256 | 275 |
|
257 | 276 | def test_unknown_hash(self): |
258 | 277 | self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam') |
@@ -723,7 +742,6 @@ def check_blake2(self, constructor, salt_size, person_size, key_size, |
723 | 742 | self.assertRaises(ValueError, constructor, node_offset=-1) |
724 | 743 | self.assertRaises(OverflowError, constructor, node_offset=max_offset+1) |
725 | 744 |
|
726 | | - self.assertRaises(TypeError, constructor, string=b'') |
727 | 745 | self.assertRaises(TypeError, constructor, '') |
728 | 746 |
|
729 | 747 | constructor( |
|
0 commit comments