Пример #1
0
 def __call__(
     self,
     inner_value: str,
     use_result: Result[str, str],
 ) -> ReaderIOResult[None, str, NoDeps]:
     return ReaderIOResult.from_failure('release failure')
Пример #2
0
def _use_failure(inner_value: str) -> ReaderIOResult[str, str, NoDeps]:
    return ReaderIOResult.from_failure('use failure')
Пример #3
0
        ),
        (
            [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'),
        ),
        (
            [
                ReaderIOResult.from_failure('a'),
                ReaderIOResult.from_failure('b')
            ],
            ReaderIOResult.from_failure('a'),
        ),
    ])
def test_fold_collect_reader(iterable, sequence):
    """Ensures that ``.collect`` works for readers."""
Пример #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
    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,
    anyio_backend_name: str,