Ejemplo n.º 1
0
def test_warn_if_called_incorrectly() -> None:
    """It should trigger a warning if bound_args is called incorrectly."""
    subject = Spec(source=some_func, name=None)

    with pytest.warns(IncorrectCallWarning,
                      match="missing a required argument"):
        subject.bind_args(wrong_arg_name="1")
Ejemplo n.º 2
0
def test_spy_calls(
    decoy: Decoy,
    call_handler: CallHandler,
    spy_creator: SpyCreator,
    spec: Spec,
) -> None:
    """It should send any calls to the call handler."""
    subject = Spy(spec=spec,
                  call_handler=call_handler,
                  spy_creator=spy_creator)

    decoy.when(spec.get_name()).then_return("spy_name")
    decoy.when(spec.bind_args(1, 2, three=3)).then_return(
        BoundArgs(args=(1, 2, 3), kwargs={}))
    decoy.when(
        call_handler.handle(
            SpyEvent(
                spy_id=id(subject),
                spy_name="spy_name",
                payload=SpyCall(args=(1, 2, 3), kwargs={}),
            ))).then_return(CallHandlerResult(42))

    result = subject(1, 2, three=3)

    assert result == 42
Ejemplo n.º 3
0
def test_bind_args(
    subject: Spec,
    input_args: Tuple[Any, ...],
    input_kwargs: Dict[str, Any],
    expected_args: Tuple[Any, ...],
    expected_kwargs: Dict[str, Any],
) -> None:
    """It should bind arguments to the spec's callable signature."""
    result = subject.bind_args(*input_args, **input_kwargs)

    assert result == BoundArgs(args=expected_args, kwargs=expected_kwargs)