async def test_flatten_future(subtests): """Ensures that `flatten` is always returning the correct type.""" futures = [ # Flattens: (Future.from_value(Future.from_value(1)), Future.from_value(1)), ( FutureResult.from_success(FutureResult.from_success(1)), FutureResult.from_success(1), ), ] for container, merged in futures: with subtests.test(container=container, merged=merged): assert await flatten(container) == await merged # type: ignore
async def test_inner_value(subtests): """Ensure that coroutine correct value is preserved for all units.""" containers = [ # We have to define these values inside the test, because # otherwise `anyio` will `await` reused coroutines. # And they have to be fresh. That's why we use subtests for it. Future.from_futureresult(FutureResult.from_success(1)), Future.from_futureresult(FutureResult.from_failure(1)), ] for container in containers: with subtests.test(container=container): assert isinstance(await container, IO)
async def test_inner_value(subtests): """Ensure that coroutine correct value is preserved for all units.""" containers = [ # We have to define these values inside the test, because # otherwise `anyio` will `await` reused coroutines. # And they have to be fresh. That's why we use subtests for it. FutureResult.from_success(1), FutureResult.from_failure(1), FutureResult.from_successful_io(IO(1)), FutureResult.from_failed_io(IO(1)), FutureResult.from_ioresult(IOSuccess(1)), FutureResult.from_ioresult(IOFailure(1)), FutureResult.from_result(Success(1)), FutureResult.from_result(Failure(1)), FutureResult.from_successful_future(Future.from_value(1)), FutureResult.from_failed_future(Future.from_value(1)), FutureResult.from_typecast(Future.from_value(Success(1))), ] for container in containers: with subtests.test(container=container): result_inst = await container assert result_inst._inner_value._inner_value == 1 # noqa: WPS437
def test_nonequality(): """Ensures that containers can be compared.""" assert FutureResult.from_success(1) != FutureResult.from_success(1) assert hash(FutureResult.from_success(1))
from returns.future import FutureResult from returns.primitives.interfaces import ( Altable, Bindable, Fixable, Mappable, Rescueable, Unifiable, Unitable, Unwrapable, ) @pytest.mark.parametrize('container', [ FutureResult.from_success(1), FutureResult.from_failure(1), ]) @pytest.mark.parametrize('protocol', [ Bindable, Mappable, Rescueable, Altable, Fixable, Unwrapable, Unifiable, Unitable, ]) def test_protocols(container, protocol): """Ensures that Future has all the right protocols.""" assert isinstance(container, protocol)