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

Method test_clinic_signature_errors

Lib/test/test_hashlib.py:297–346  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

295
296 @unittest.skipIf(get_fips_mode(), "skip in FIPS mode")
297 def test_clinic_signature_errors(self):
298 nomsg = b''
299 mymsg = b'msg'
300 conflicting_call = re.escape(
301 "'data' and 'string' are mutually exclusive "
302 "and support for 'string' keyword parameter "
303 "is slated for removal in a future version."
304 )
305 duplicated_param = re.escape("given by name ('data') and position")
306 unexpected_param = re.escape("got an unexpected keyword argument '_'")
307 for args, kwds, errmsg in [
308 # Reject duplicated arguments before unknown keyword arguments.
309 ((nomsg,), dict(data=nomsg, _=nomsg), duplicated_param),
310 ((mymsg,), dict(data=nomsg, _=nomsg), duplicated_param),
311 # Reject duplicated arguments before conflicting ones.
312 *itertools.product(
313 [[nomsg], [mymsg]],
314 [dict(data=nomsg), dict(data=nomsg, string=nomsg)],
315 [duplicated_param]
316 ),
317 # Reject unknown keyword arguments before conflicting ones.
318 *itertools.product(
319 [()],
320 [
321 dict(_=None),
322 dict(data=nomsg, _=None),
323 dict(string=nomsg, _=None),
324 dict(string=nomsg, data=nomsg, _=None),
325 ],
326 [unexpected_param]
327 ),
328 ((nomsg,), dict(_=None), unexpected_param),
329 ((mymsg,), dict(_=None), unexpected_param),
330 # Reject conflicting arguments.
331 [(nomsg,), dict(string=nomsg), conflicting_call],
332 [(mymsg,), dict(string=nomsg), conflicting_call],
333 [(), dict(data=nomsg, string=nomsg), conflicting_call],
334 ]:
335 for constructor in self.hash_constructors:
336 digest_name = constructor(b'').name
337 with self.subTest(constructor.__name__, args=args, kwds=kwds):
338 with self.assertRaisesRegex(TypeError, errmsg):
339 constructor(*args, **kwds)
340 with self.subTest(digest_name, args=args, kwds=kwds):
341 with self.assertRaisesRegex(TypeError, errmsg):
342 hashlib.new(digest_name, *args, **kwds)
343 if (self._hashlib and
344 digest_name in self._hashlib._constructors):
345 with self.assertRaisesRegex(TypeError, errmsg):
346 self._hashlib.new(digest_name, *args, **kwds)
347
348 def test_unknown_hash(self):
349 self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')

Callers

nothing calls this directly

Calls 5

constructorFunction · 0.85
escapeMethod · 0.80
assertRaisesRegexMethod · 0.80
subTestMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected