Esempio n. 1
0
def test_callable_object_misconfigured():
    """`Callable` object should protect from multiple return values."""
    with pytest.raises(PrimitiveError) as exc_info:
        Callable(1, 2)

    assert str(exc_info.value
               ) == "'Callable' object should have only one return value"
Esempio n. 2
0
def test_callable_object_positional_argument_overflow():
    """Raise error if user passed more arguments than mock specified."""
    func = Callable(Argument("John"))

    with pytest.raises(PrimitiveError) as exc_info:
        func("John", 1)

    assert str(exc_info.value) == "Called with more arguments than expected"
Esempio n. 3
0
def test_callable_object_return_null():
    """Empty `Callable` object should return null.

    A callable object is empty when return value was not specified.

    """
    func = Callable()
    assert func() is None
Esempio n. 4
0
def test_callable_object_positional_argument_not_enough():
    """Raise error if mock specified more arguments than user passed."""
    func = Callable(Argument("John"), Argument("Kate"))

    with pytest.raises(PrimitiveError) as exc_info:
        func("John")

    assert str(exc_info.value) == "Called with less arguments than expected"
Esempio n. 5
0
def test_callable_object_positional_argument_prevent_keyword():
    """Positional `Argument` should provent usage of keyword argument."""
    func = Callable(Argument("John"))

    with pytest.raises(PrimitiveError) as exc_info:
        func(a="John")

    assert str(
        exc_info.value) == "Positional arguments can not be called as keyword"
Esempio n. 6
0
def test_callable_object_return_value_positional_argument():
    """`Callable`object should return value even if `Argument` was passed."""
    func = Callable("Hello, John", Argument("John"))
    assert func("John") == "Hello, John"

    with pytest.raises(PrimitiveError) as exc_info:
        func("Kate")

    assert str(
        exc_info.value) == "Called with argument 'Kate' while expected 'John'"
Esempio n. 7
0
async def test_instance_async_method():
    """`Instance` object should give access to async methods."""
    user = Instance(greet=Callable(Awaitable("Hello, John")))
    assert await user.greet() == "Hello, John"
Esempio n. 8
0
def test_instance_method():
    """`Instance` object should give access to methods."""
    user = Instance(greet=Callable("Hello, John"))
    assert user.greet() == "Hello, John"
Esempio n. 9
0
def test_callable_object_return_value_positional_argument_ignore():
    """Ignore positional argument in callable object with return value."""
    func = Callable("Hello, John", Argument(Ignore()))
    assert func("John") == "Hello, John"
    assert func("Kate") == "Hello, John"
Esempio n. 10
0
def test_callable_object_null_positional_argument_ignore():
    """Ignore positional argument in callable object without return value."""
    func = Callable(Argument(Ignore()))
    assert func("John") is None
    assert func("Kate") is None
Esempio n. 11
0
def test_callable_object_return_value():
    """`Callable` object should return value passed to it constructor."""
    func = Callable("Hello, John")
    assert func() == "Hello, John"