Пример #1
0
 def __call__(
     self,
     inner_value: str,
     use_result: Result[str, str],
 ) -> ReaderIOResult[None, str, NoDeps]:
     self._logs.append((inner_value, use_result))
     return ReaderIOResult.from_value(None)
Пример #2
0
def test_requires_context_io_aliases():
    """Ensures that ReaderIOResult correctly typecast."""
    container: ReaderIOResultE[int, float] = _function(1)
    container2: ReaderIOResult[int, float, Exception] = _function(1)
    container3: ReaderIOResultE[int,
                                float] = ReaderIOResultE.from_value(10.0, )
    container4: ReaderIOResultE[int, float] = ReaderIOResult.from_value(10.0)

    assert container(0) == container2(0) == container3(0) == container4(0)
    assert container(0) == RequiresContextIOResult.from_value(10.0)(0)
Пример #3
0
def _use_success(inner_value: str) -> ReaderIOResult[str, str, NoDeps]:
    return ReaderIOResult.from_value('use success')
Пример #4
0
from typing import List, Tuple

import pytest

from returns.context import NoDeps, ReaderIOResult
from returns.io import IOFailure, IOSuccess
from returns.pipeline import managed
from returns.result import Failure, Result, Success

_acquire_success = ReaderIOResult.from_value('acquire success')
_acquire_failure = ReaderIOResult.from_failure('acquire failure')


def _use_success(inner_value: str) -> ReaderIOResult[str, str, NoDeps]:
    return ReaderIOResult.from_value('use success')


def _use_failure(inner_value: str) -> ReaderIOResult[str, str, NoDeps]:
    return ReaderIOResult.from_failure('use failure')


class _ReleaseSuccess(object):
    def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None:
        self._logs = logs

    def __call__(
        self,
        inner_value: str,
        use_result: Result[str, str],
    ) -> ReaderIOResult[None, str, NoDeps]:
        self._logs.append((inner_value, use_result))
Пример #5
0
     ReaderResult.from_value((1, 2)),
 ),
 (
     [
         ReaderResult.from_failure('a'),
         ReaderResult.from_value(1),
         ReaderResult.from_value(2),
     ],
     ReaderResult.from_failure('a'),
 ),
 (
     [ReaderResult.from_failure('a'),
      ReaderResult.from_failure('b')],
     ReaderResult.from_failure('a'),
 ),
 ([], ReaderIOResult.from_value(())),
 ([ReaderIOResult.from_value(1)], ReaderIOResult.from_value((1, ))),
 (
     [ReaderIOResult.from_value(1),
      ReaderIOResult.from_value(2)],
     ReaderIOResult.from_value((1, 2)),
 ),
 (
     [
         ReaderIOResult.from_failure('a'),
         ReaderIOResult.from_value(1),
         ReaderIOResult.from_value(2),
     ],
     ReaderIOResult.from_failure('a'),
 ),
 (
Пример #6
0
_containers: Sequence[BaseContainer] = (
    Result.from_failure(1),
    Result.from_value(1),
    IO(1),
    IOResult.from_failure(1),
    IOResult.from_value(1),
    Maybe.from_value(1),
    Maybe.from_value(None),
    Maybe.from_optional(None),
    Future.from_value(1),
    FutureResult.from_value(1),
    FutureResult.from_failure(1),
    Reader.from_value(1),
    ReaderResult.from_value(1),
    ReaderResult.from_failure(1),
    ReaderIOResult.from_value(1),
    ReaderIOResult.from_failure(1),
    ReaderFutureResult.from_value(1),
    ReaderFutureResult.from_failure(1),
)


@pytest.mark.parametrize('container', _containers)
def test_assert_equal(container, anyio_backend_name: str):
    """Ensure that containers can be equal."""
    assert_equal(container, container, backend=anyio_backend_name)


@pytest.mark.parametrize('container', _containers)
def test_assert_equal_plugin(
    container,
Пример #7
0
     ReaderResult.from_value(13),
 ),
 (
     [
         ReaderResult.from_failure('a'),
         ReaderResult.from_value(1),
         ReaderResult.from_value(2),
     ],
     ReaderResult.from_failure('a'),
 ),
 (
     [ReaderResult.from_failure('a'),
      ReaderResult.from_failure('b')],
     ReaderResult.from_failure('a'),
 ),
 ([], ReaderIOResult.from_value(10)),
 ([ReaderIOResult.from_value(1)], ReaderIOResult.from_value(11)),
 (
     [ReaderIOResult.from_value(1),
      ReaderIOResult.from_value(2)],
     ReaderIOResult.from_value(13),
 ),
 (
     [
         ReaderIOResult.from_failure('a'),
         ReaderIOResult.from_value(1),
         ReaderIOResult.from_value(2),
     ],
     ReaderIOResult.from_failure('a'),
 ),
 (