Example #1
0
def test_zio_raise() -> None:
    with pytest.raises(Bippy):
        _raise(Bippy())
Example #2
0
def test_environment_2() -> None:
    assert Environment[int]().provide(42)._run(()) == Right(42)


def test_environment_3() -> None:
    assert Environment[int]().provide(42).provide("asdf")._run(()) == Right(42)


@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"))),
Example #3
0
def _q6(do: ZIOMonad[object, Bippy]) -> ZIO[object, Bippy, int]:
    result = do << ZIO.effect_catch(lambda: _raise(Bippy()), Bippy)  # type: ignore
    return ZIO.succeed(result)
Example #4
0
def _q5(do: ZIOMonad[object, Exception]) -> ZIO[object, Exception, int]:
    do << ZIO.effect(lambda: _raise(Bippy()))  # type: ignore
    return ZIO.succeed(42)
Example #5
0
def _q7(do: ZIOMonad[object, NotBippy]) -> ZIO[object, NotBippy, int]:
    result: int = do << (
        ZIO.effect_catch(lambda: _raise(Bippy()), NotBippy).catch(Bippy)  # type: ignore
    )
    return ZIO.succeed(result)
Example #6
0
@monadic
def _q4(do: ZIOMonad[object, Exception]) -> ZIO[object, Exception, int]:
    result = do << ZIO.effect(lambda: 42)
    return ZIO.succeed(result)


EQ4: Final = Equiv(ZIO.effect(lambda: 42), _q4(), (), Right(42))


@monadic
def _q5(do: ZIOMonad[object, Exception]) -> ZIO[object, Exception, int]:
    do << ZIO.effect(lambda: _raise(Bippy()))  # type: ignore
    return ZIO.succeed(42)


EQ5: Final = Equiv(ZIO.effect(lambda: _raise(Bippy())), _q5(), (), Left(Bippy()))


@monadic
def _q6(do: ZIOMonad[object, Bippy]) -> ZIO[object, Bippy, int]:
    result = do << ZIO.effect_catch(lambda: _raise(Bippy()), Bippy)  # type: ignore
    return ZIO.succeed(result)


EQ6: Final = Equiv(ZIO.effect_catch(lambda: _raise(Bippy()), Bippy), _q6(), None, Left(Bippy()))


@monadic
def _q7(do: ZIOMonad[object, NotBippy]) -> ZIO[object, NotBippy, int]:
    result: int = do << (
        ZIO.effect_catch(lambda: _raise(Bippy()), NotBippy).catch(Bippy)  # type: ignore