示例#1
0
from copy import copy, deepcopy

import pytest

from returns.context import Context, RequiresContext
from returns.primitives.exceptions import ImmutableStateError
from returns.primitives.interfaces import Bindable, Instanceable, Mappable


@pytest.mark.parametrize('container', [
    RequiresContext(lambda deps: deps),
    RequiresContext.from_value(1),
    Context.ask(),
])
@pytest.mark.parametrize('protocol', [
    Bindable,
    Mappable,
    Instanceable,
])
def test_protocols(container, protocol):
    """Ensures that RequiresContext has all the right protocols."""
    assert isinstance(container, protocol)


def test_context_immutable():
    """Ensures that Context is immutable."""
    with pytest.raises(ImmutableStateError):
        Context().abc = 1


def test_context_immutable_copy():
示例#2
0
def test_equality():
    """Ensures that containers can be compared."""
    assert RequiresContext(_same_function) == RequiresContext(_same_function)
    assert Context[int].ask() == Context[int].ask()
    assert Context[int].ask() == Context.ask()
    assert Context.ask() == Context.ask()