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

Method handle

Lib/unittest/case.py:221–248  ·  view source on GitHub ↗

If args is empty, assertRaises/Warns is being used as a context manager, so check for a 'msg' kwarg and return self. If args is not empty, call a callable passing positional and keyword arguments.

(self, name, args, kwargs)

Source from the content-addressed store, hash-verified

219 self.msg = None
220
221 def handle(self, name, args, kwargs):
222 """
223 If args is empty, assertRaises/Warns is being used as a
224 context manager, so check for a 'msg' kwarg and return self.
225 If args is not empty, call a callable passing positional and keyword
226 arguments.
227 """
228 try:
229 if not _is_subtype(self.expected, self._base_type):
230 raise TypeError('%s() arg 1 must be %s' %
231 (name, self._base_type_str))
232 if not args:
233 self.msg = kwargs.pop('msg', None)
234 if kwargs:
235 raise TypeError('%r is an invalid keyword argument for '
236 'this function' % (next(iter(kwargs)),))
237 return self
238
239 callable_obj, *args = args
240 try:
241 self.obj_name = callable_obj.__name__
242 except AttributeError:
243 self.obj_name = str(callable_obj)
244 with self:
245 callable_obj(*args, **kwargs)
246 finally:
247 # bpo-23890: manually break a reference cycle
248 self = None
249
250
251class _AssertRaisesContext(_AssertRaisesBaseContext):

Callers 5

assertRaisesMethod · 0.45
assertWarnsMethod · 0.45
_assertNotWarnsMethod · 0.45
assertRaisesRegexMethod · 0.45
assertWarnsRegexMethod · 0.45

Calls 3

_is_subtypeFunction · 0.85
strFunction · 0.85
popMethod · 0.45

Tested by

no test coverage detected