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)
| 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 | |
| 251 | class _AssertRaisesContext(_AssertRaisesBaseContext): |
no test coverage detected