Пример #1
0
        (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
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
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)