コード例 #1
0
ファイル: test_flatten.py プロジェクト: tewe/returns
        (Some(Some([])), Some([])),

        # Nope:
        (Failure(Failure('a')), Failure(Failure('a'))),
        (IOFailure(IOFailure('a')), IOFailure(IOFailure('a'))),
    ])
def test_flatten(container, merged):
    """Ensures that `flatten` is always returning the correct type."""
    assert flatten(container) == merged


@pytest.mark.parametrize(('container', 'merged'), [
    (
        RequiresContextResult.from_success(
            RequiresContextResult.from_success(1), ),
        RequiresContextResult.from_success(1),
    ),
    (
        RequiresContextIOResult.from_success(
            RequiresContextIOResult.from_success(1), ),
        RequiresContextIOResult.from_success(1),
    ),
    (
        RequiresContext.from_value(RequiresContext.from_value(1)),
        RequiresContext.from_value(1),
    ),
])
def test_flatten_context(container, merged):
    """Ensures that `flatten` is always returning the correct type."""
    assert flatten(container)(...) == merged(...)
コード例 #2
0
ファイル: test_context_utils.py プロジェクト: tewe/returns
def test_requires_context_from_value():
    """Ensures that ``from_value`` method works correctly."""
    assert RequiresContext.from_value(1)(RequiresContext.empty) == 1
    assert RequiresContext.from_value(2)(1) == 2
コード例 #3
0
def test_nonequality():
    """Ensures that containers can be compared."""
    assert RequiresContext(_same_function) != RequiresContext(str)
    assert RequiresContext.from_value(1) != RequiresContext.from_value(1)
コード例 #4
0
ファイル: test_apply.py プロジェクト: t94j0/returns
def test_apply_with_context():
    """Ensures that functions can be composed and return type is correct."""
    applied = apply(RequiresContext.from_value(_function))

    assert applied(RequiresContext.from_value(1))(...) == '2'
コード例 #5
0
def test_requires_context_immutable():
    """Ensures that Context is immutable."""
    with pytest.raises(ImmutableStateError):
        RequiresContext.from_value(1).abc = 1
コード例 #6
0
def test_requires_context_immutable_deepcopy():
    """Ensures that Context returns it self when passed to deepcopy function."""
    context = RequiresContext.from_value(1)
    assert context is deepcopy(context)