MCPcopy Index your code
hub / github.com/RustPython/RustPython / _AssertRaisesContext

Class _AssertRaisesContext

Lib/unittest/case.py:258–294  ·  view source on GitHub ↗

A context manager used to implement TestCase.assertRaises* methods.

Source from the content-addressed store, hash-verified

256
257
258class _AssertRaisesContext(_AssertRaisesBaseContext):
259 """A context manager used to implement TestCase.assertRaises* methods."""
260
261 _base_type = BaseException
262 _base_type_str = 'an exception type or tuple of exception types'
263
264 def __enter__(self):
265 return self
266
267 def __exit__(self, exc_type, exc_value, tb):
268 if exc_type is None:
269 try:
270 exc_name = self.expected.__name__
271 except AttributeError:
272 exc_name = str(self.expected)
273 if self.obj_name:
274 self._raiseFailure("{} not raised by {}".format(exc_name,
275 self.obj_name))
276 else:
277 self._raiseFailure("{} not raised".format(exc_name))
278 else:
279 traceback.clear_frames(tb)
280 if not issubclass(exc_type, self.expected):
281 # let unexpected exceptions pass through
282 return False
283 # store exception, without traceback, for later retrieval
284 self.exception = exc_value.with_traceback(None)
285 if self.expected_regex is None:
286 return True
287
288 expected_regex = self.expected_regex
289 if not expected_regex.search(str(exc_value)):
290 self._raiseFailure('"{}" does not match "{}"'.format(
291 expected_regex.pattern, str(exc_value)))
292 return True
293
294 __class_getitem__ = classmethod(types.GenericAlias)
295
296
297class _AssertWarnsContext(_AssertRaisesBaseContext):

Callers 2

assertRaisesMethod · 0.85
assertRaisesRegexMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected