Custom ``assert`` function to compare two any containers. The important note here is that this ``assert`` should probably used in tests. Not real application code. It will call all ``Reader`` based containers and ``await`` all ``Future`` based ones. It also works recu
(
first,
second,
*,
deps=None,
backend: str = 'asyncio',
)
| 1 | def assert_equal( |
| 2 | first, |
| 3 | second, |
| 4 | *, |
| 5 | deps=None, |
| 6 | backend: str = 'asyncio', |
| 7 | ) -> None: |
| 8 | """ |
| 9 | Custom ``assert`` function to compare two any containers. |
| 10 | |
| 11 | The important note here is that |
| 12 | this ``assert`` should probably used in tests. |
| 13 | Not real application code. |
| 14 | |
| 15 | It will call all ``Reader`` based containers and ``await`` |
| 16 | all ``Future`` based ones. |
| 17 | |
| 18 | It also works recursively. |
| 19 | For example, ``ReaderFutureResult`` will be called and then awaited. |
| 20 | |
| 21 | You can specify different dependencies to call your containers. |
| 22 | And different backends to ``await`` then using ``anyio``. |
| 23 | |
| 24 | By the way, ``anyio`` should be installed separately. |
| 25 | """ |
| 26 | assert _convert( |
| 27 | first, |
| 28 | deps=deps, |
| 29 | backend=backend, |
| 30 | ) == _convert( |
| 31 | second, |
| 32 | deps=deps, |
| 33 | backend=backend, |
| 34 | ), f'{first} == {second}' |
| 35 | |
| 36 | |
| 37 | def _convert(container, *, deps, backend: str): |