async def forward_event(chat_id, **extra_args) -> Response: return await compose( Event.from_dict, logger.debug, filter_event(FILTER_EXPRESION), logger.debug, send_event(extra_args['request'].app['telegram_client'], chat_id), logger.debug, bind(lambda x: x.as_dict()), return_200)(await extra_args['request'].json())
async def test_bind_async(): maybe_sum = bind(async_sum) maybe_sum1 = maybe_sum(1) assert await maybe_sum1(5) == 6 error = await maybe_sum(Exception()) assert isinstance(error, Exception) assert not isinstance(error, int)
def test_bind_curry(): maybe_sum = bind(_sum) maybe_sum1 = maybe_sum(1) assert maybe_sum1(4) == 5 error = maybe_sum1(Exception()) assert isinstance(error, Exception) assert not isinstance(error, int)
def test_bind(): def x5(x: int) -> int: return x * 5 maybe_x5 = bind(x5) assert maybe_x5(1) == 5 error = maybe_x5(Exception()) assert isinstance(error, Exception) assert not isinstance(error, int)
async def test_compose_with_bind_error(): maybe_sum = bind(async_sum) async def return_error(x: int): return Exception() assert await compose(maybe_sum(1), maybe_sum(2))(3) == 6 assert isinstance(await compose(maybe_sum(1), maybe_sum(2))(Exception()), Exception) assert isinstance(await compose(return_error, maybe_sum(1))(3), Exception)
def test_iscoroutinefunction_or_partial_or_bind(): async def foo(boo, woo): return (boo, woo) partial_foo = bind(foo) assert _iscoroutinefunction_or_partial(partial_foo(None)) is True
async def forward_alerts(chat_id, **extra_args) -> Response: return await compose( logger.debug, Alerts.from_dict, logger.debug, send_alerts(extra_args['request'].app['telegram_client'], chat_id), logger.debug, bind(lambda x: x.as_dict()), return_200)(await extra_args['request'].json())