def test_zio_access_m_1() -> None: accessor: Callable[[str], ZIO[object, NoReturn, int]] = lambda s: ZIO.succeed(len(s)) assert ZIO.access_m(accessor)._run("hello") == Right(5)
def test_zio_access_m_2() -> None: accessor: Callable[[str], ZIO[object, str, int]] = lambda s: ZIO.fail("oops") assert ZIO.access_m(accessor)._run("hello") == Left("oops")
@pytest.mark.parametrize( "program,environment,expected_result", [ (ZIO.succeed(42), None, Right(42)), (ZIO.fail(Bippy()), None, Left(Bippy)), (ZIO.effect(lambda: 42), None, Right(42)), (ZIO.effect(lambda: _raise(Bippy())), None, Left(Bippy)), # type: ignore (ZIO.effect_catch(lambda: 42, Bippy), None, Right(42)), (ZIO.effect_catch(lambda: _raise(Bippy()), Bippy), None, Left(Bippy)), # type: ignore (ZIO.effect_catch(lambda: _raise(Bippy()), NotBippy), None, Left(Bippy)), # type: ignore (ZIO.succeed(42).catch(Bippy), None, Right(42)), (ZIO.access(len), "hello", Right(5)), (ZIO.access_m(lambda s: ZIO.succeed(len(s))), "hello", Right(5)), # type: ignore (ZIO.access_m(lambda s: ZIO.fail(Bippy())), "hello", Left(Bippy)), # type: ignore (ZIO.effect_total(lambda: 42), None, Right(42)), (ZIO.fail(Bippy()).catch(Bippy).either(), None, Right(Left(Bippy()))), (ZIO.succeed("Yay").catch(Bippy).either(), None, Right(Right("Yay"))), (ZIO.succeed(1).map(lambda x: x + 1).map(lambda x: x + 10), None, Right(12)), (ZIO.succeed(1).map(lambda x: x + 1).fail( Bippy()), None, Left(Bippy)), # type: ignore ((ZIO.succeed(1).flat_map(lambda x: ZIO.succeed(x + 1)).flat_map( lambda x: ZIO.succeed(x + 10))), None, Right(12)), ( ZIO.succeed(1).flat_map(lambda x: ZIO.succeed(x + 1)).fail( Bippy()), # type: ignore