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