f٥ T d dl mZ d dlmZmZ ddlmZ dZdd
Z G d d Z dS ) )annotations)IterableAny )log_failureFexpected_exceptiontype | Iterable[type]argsr kwargsobjectreturnc x d}t | t r| f}n| }t d |D sJ | dd }|s|r
J d| t |d|iS |d }t | sJ t |d|i5 ||dd i | ddd dS # 1 swxY w Y dS )a7
Check that a given callable or context raises an error of a given type.
Can be used as either a context manager:
>>> with raises(AssertionError):
>>> raise AssertionError
or as a function:
>>> def raises_assert():
>>> raise AssertionError
>>> raises(AssertionError, raises_assert)
`expected_exception` follows the same format rules as the second argument
to `issubclass`, so multiple possible exception types can be used.
When args[0] is callable, the remainder of args and all of kwargs except
for any called `msg` are passed to args[0] as arguments.
Note that because `raises` is implemented using a context manager, the
usual control flow warnings apply: within the context, execution stops on
the first error encountered *and does not resume after this error has been
logged*. Therefore, the line you expect to raise an error must be the last
line of the context: any subsequent lines won't be executed. Pull such
lines out of the context if they don't raise errors, or use more calls to
`raises` if they do.
This function is modeled loosely after Pytest's own `raises`, except for
the latter's `match`-ing logic. We should strive to keep the call
signature of this `raises` as close as possible to the other `raises`.
Tc 3 j K | ].}t |t pt |t V /d S N)
isinstancetype
issubclass
BaseException).0excs k/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pytest_check/check_raises.py