Exemple #1
0
def test_zio_catch_3() -> None:
    def _impure_function() -> int:
        raise Bippy

    program = ZIO.effect_total(_impure_function).catch(NotBippy)
    with pytest.raises(Bippy):
        program._run(())
Exemple #2
0
def test_zio_effect_total() -> None:
    x: Optional[int] = None

    def _impure_function() -> None:
        nonlocal x
        x = 42

    program = ZIO.effect_total(_impure_function)
    assert x is None

    program._run(())
    assert x == 42
Exemple #3
0
 def exit(
         self,
         exit_code: Optional[int] = None
 ) -> ZIO[object, NoReturn, NoReturn]:
     return ZIO.effect_total(lambda: sys.exit(exit_code))  # type: ignore
Exemple #4
0
 def print(self, line: str) -> ZIO[object, NoReturn, None]:
     return ZIO.effect_total(lambda: builtins.print(line))
Exemple #5
0
 (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
     None,
     Left(Bippy)),
 (ZIO.succeed(1) << ZIO.succeed(2), None, Right(2)),
 (ZIO.fail(Bippy()) << ZIO.succeed(2), None, Left(Bippy)),