Skip to content

Commit

Permalink
revert: remove missing stub warning; it's a little broken
Browse files Browse the repository at this point in the history
This reverts commit 5fd4e6d.
  • Loading branch information
mcous committed May 4, 2021
1 parent b6b9df6 commit 338961e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 149 deletions.
16 changes: 1 addition & 15 deletions decoy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
"""Decoy test double stubbing and verification library."""
from os import linesep
from typing import cast, Any, Optional, Sequence, Type
from warnings import warn

from .registry import Registry
from .spy import create_spy, SpyCall
from .stub import Stub
from .types import ClassT, FuncT, ReturnT
from .warnings import MissingStubWarning


class Decoy:
"""Decoy test double state container."""

_registry: Registry
_warn_on_missing_stubs: bool

def __init__(
self,
warn_on_missing_stubs: bool = True,
) -> None:
def __init__(self) -> None:
"""Initialize the state container for test doubles and stubs.
You should initialize a new Decoy instance for every test.
Arguments:
warn_on_missing_stubs: Trigger a warning if a stub is called
with arguments that do not match any of its rehearsals.
Example:
```python
import pytest
Expand All @@ -39,7 +29,6 @@ def decoy() -> Decoy:
```
"""
self._registry = Registry()
self._warn_on_missing_stubs = warn_on_missing_stubs

def create_decoy(self, spec: Type[ClassT], *, is_async: bool = False) -> ClassT:
"""Create a class decoy for `spec`.
Expand Down Expand Up @@ -189,9 +178,6 @@ def _handle_spy_call(self, call: SpyCall) -> Any:
if stub._rehearsal == call:
return stub._act()

if self._warn_on_missing_stubs and len(stubs) > 0:
warn(MissingStubWarning(call, stubs))

return None

def _build_verify_error(
Expand Down
6 changes: 3 additions & 3 deletions decoy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_stubs_by_spy_id(self, spy_id: int) -> List[Stub[Any]]:
"""Get a spy's stub list by identifier.
Arguments:
spy_id: The unique identifier of the Spy to look up.
spy_id: The unique identifer of the Spy to look up.
Returns:
The list of stubs matching the given Spy.
Expand All @@ -51,7 +51,7 @@ def get_calls_by_spy_id(self, *spy_id: int) -> List[SpyCall]:
"""Get a spy's call list by identifier.
Arguments:
spy_id: The unique identifier of the Spy to look up.
spy_id: The unique identifer of the Spy to look up.
Returns:
The list of calls matching the given Spy.
Expand Down Expand Up @@ -83,7 +83,7 @@ def register_stub(self, spy_id: int, stub: Stub[Any]) -> None:
"""Register a stub for tracking.
Arguments:
spy_id: The unique identifier of the Spy to look up.
spy_id: The unique identifer of the Spy to look up.
stub: The stub to track.
"""
stub_list = self.get_stubs_by_spy_id(spy_id)
Expand Down
30 changes: 0 additions & 30 deletions decoy/warnings.py

This file was deleted.

2 changes: 0 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
::: decoy.stub.Stub

::: decoy.matchers

::: decoy.warnings
15 changes: 1 addition & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,5 @@

@pytest.fixture
def decoy() -> Decoy:
"""Get a new instance of the Decoy state container.
Warnings are disabled for more quiet tests.
"""
return Decoy(warn_on_missing_stubs=False)


@pytest.fixture
def strict_decoy() -> Decoy:
"""Get a new instance of the Decoy state container.
Warnings are left in the default enabled state. Use this fixture
to test warning behavior.
"""
"""Get a new instance of the Decoy state container."""
return Decoy()
64 changes: 0 additions & 64 deletions tests/test_warnings.py

This file was deleted.

22 changes: 1 addition & 21 deletions tests/test_when.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for the Decoy double creator."""
import pytest

from decoy import Decoy, matchers, warnings
from decoy import Decoy, matchers
from .common import some_func, SomeClass, SomeAsyncClass, SomeNestedClass


Expand Down Expand Up @@ -159,23 +159,3 @@ def _async_child(self) -> SomeAsyncClass:
decoy.when(await stub._async_child.foo("hello")).then_return("world")

assert await stub._async_child.foo("hello") == "world"


def test_no_stubbing_found_warning(strict_decoy: Decoy) -> None:
"""It should raise a warning if a stub is configured and then called incorrectly."""
stub = strict_decoy.create_decoy_func(spec=some_func)

strict_decoy.when(stub("hello")).then_return("world")

with pytest.warns(warnings.MissingStubWarning):
stub("h3110")


@pytest.mark.filterwarnings("error::UserWarning")
def test_no_stubbing_found_warnings_disabled(decoy: Decoy) -> None:
"""It should not raise a warning if warn_on_missing_stub is disabled."""
stub = decoy.create_decoy_func(spec=some_func)

decoy.when(stub("hello")).then_return("world")

stub("h3110")

0 comments on commit 338961e

Please sign in to comment.