コード例 #1
0
def test_requires_context_aliases():
    """Ensures that ReaderResult correctly typecast."""
    container: ReaderResultE[float, int] = _function(1)
    container2: ReaderResult[float, Exception, int] = _function(1)
    container3: ReaderResultE[float, int] = ReaderResultE.from_value(10.0, )
    container4: ReaderResultE[float, int] = ReaderResult.from_value(10.0)

    assert container(0) == container2(0) == container3(0) == container4(0)
    assert container(0) == RequiresContextResult.from_value(10.0)(0)
コード例 #2
0
    assert Fold.collect(iterable, sequence.from_value(())) == sequence


@pytest.mark.parametrize(
    ('iterable', 'sequence'),
    [
        # Regular types:
        ([], Reader.from_value(())),
        ([Reader.from_value(1)], Reader.from_value((1, ))),
        (
            [Reader.from_value(1), Reader.from_value(2)],
            Reader.from_value((1, 2)),
        ),

        # Can fail:
        ([], ReaderResult.from_value(())),
        ([ReaderResult.from_value(1)], ReaderResult.from_value((1, ))),
        (
            [ReaderResult.from_value(1),
             ReaderResult.from_value(2)],
            ReaderResult.from_value((1, 2)),
        ),
        (
            [
                ReaderResult.from_failure('a'),
                ReaderResult.from_value(1),
                ReaderResult.from_value(2),
            ],
            ReaderResult.from_failure('a'),
        ),
        (
コード例 #3
0
from returns.result import Result

_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)
コード例 #4
0
ファイル: test_loop.py プロジェクト: timqsh/returns
    assert Fold.loop(iterable, sequence.from_value(10), _sum_two) == sequence


@pytest.mark.parametrize(
    ('iterable', 'sequence'),
    [
        # Regular types:
        ([], Reader.from_value(10)),
        ([Reader.from_value(1)], Reader.from_value(11)),
        (
            [Reader.from_value(1), Reader.from_value(2)],
            Reader.from_value(13),
        ),

        # Can fail:
        ([], ReaderResult.from_value(10)),
        ([ReaderResult.from_value(1)], ReaderResult.from_value(11)),
        (
            [ReaderResult.from_value(1),
             ReaderResult.from_value(2)],
            ReaderResult.from_value(13),
        ),
        (
            [
                ReaderResult.from_failure('a'),
                ReaderResult.from_value(1),
                ReaderResult.from_value(2),
            ],
            ReaderResult.from_failure('a'),
        ),
        (
コード例 #5
0
def test_collect_all_reader_result(iterable, sequence):
    """Iterable for ``ReaderResult`` and ``CollectAll``."""
    assert ReaderResult.from_iterable(
        iterable,
        CollectAll,
    )(...) == sequence(...)
コード例 #6
0
ファイル: test_fail_fast.py プロジェクト: timgates42/returns
def test_fail_fast_reader_result(iterable, sequence):
    """Iterable for ``ReaderResult`` and ``FailFast``."""
    assert ReaderResult.from_iterable(
        iterable,
        FailFast,
    )(...) == sequence(...)