Skip to content

Commit b766bf9

Browse files
authored
test: remove and replace redundant tests of internals (#307)
1 parent da67c9c commit b766bf9

14 files changed

+310
-1933
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ test-ci = ["test-once", "coverage-xml"]
8383
[tool.pytest.ini_options]
8484
addopts = "--color=yes --mypy-ini-file=tests/typing/mypy.ini --mypy-only-local-stub"
8585
asyncio_mode = "auto"
86+
filterwarnings = ["error::decoy.warnings.DecoyWarning"]
8687

8788
[tool.mypy]
8889
files = ["decoy", "tests"]

tests/fixtures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Common test fixtures."""
22

33
from functools import lru_cache
4-
from typing import Any, Generic, TypeVar, Optional, Union
4+
from typing import Any, Generic, Optional, TypeVar, Union
55

66

77
class SomeClass:
@@ -114,7 +114,6 @@ async def __call__(self, val: int) -> int:
114114

115115
def noop(*args: Any, **kwargs: Any) -> Any:
116116
"""No-op."""
117-
raise NotImplementedError()
118117

119118

120119
def some_func(val: str) -> str:

tests/test_errors.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

tests/test_mock.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@
66

77
from decoy import Decoy, errors
88
from decoy.spy import AsyncSpy, Spy
9+
from decoy.warnings import IncorrectCallWarning
910

1011
from .fixtures import SomeClass, some_func
1112

1213

13-
def test_decoy_creates_spy(decoy: Decoy) -> None:
14-
"""It should be able to create a Spy from a class."""
14+
def test_create_mock(decoy: Decoy) -> None:
15+
"""It creates a mock from a class."""
1516
subject = decoy.mock(cls=SomeClass)
1617

1718
assert isinstance(subject, SomeClass)
1819
assert isinstance(subject, Spy)
1920
assert repr(subject) == "<Decoy mock `tests.fixtures.SomeClass`>"
2021

2122

23+
def test_method_noop(decoy: Decoy) -> None:
24+
"""A method mock no-ops by default."""
25+
subject = decoy.mock(cls=SomeClass)
26+
result = subject.foo("hello")
27+
28+
assert result is None
29+
30+
2231
def test_decoy_creates_func_spy(decoy: Decoy) -> None:
2332
"""It should be able to create a Spy from a function."""
2433
subject = decoy.mock(func=some_func)
@@ -28,6 +37,22 @@ def test_decoy_creates_func_spy(decoy: Decoy) -> None:
2837
assert repr(subject) == "<Decoy mock `tests.fixtures.some_func`>"
2938

3039

40+
def test_func_noop(decoy: Decoy) -> None:
41+
"""A function mock no-ops by default."""
42+
subject = decoy.mock(func=some_func)
43+
result = subject("hello")
44+
45+
assert result is None
46+
47+
48+
def test_func_bad_call(decoy: Decoy) -> None:
49+
"""It raises an IncorrectCallWarning if call is bad."""
50+
subject = decoy.mock(func=some_func)
51+
52+
with pytest.warns(IncorrectCallWarning):
53+
subject("hello", "world") # type: ignore[call-arg]
54+
55+
3156
def test_decoy_creates_specless_spy(decoy: Decoy) -> None:
3257
"""It should be able to create a spec-less spy."""
3358
subject = decoy.mock(name="subject")

tests/test_prop.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Tests for decoy.prop."""
2+
3+
import pytest
4+
5+
from decoy import Decoy
6+
from decoy.errors import MissingRehearsalError
7+
8+
from .fixtures import SomeClass
9+
10+
11+
def test_property_missing_rehearsal(decoy: Decoy) -> None:
12+
"""It raises an error if no prop rehearsal."""
13+
with pytest.raises(MissingRehearsalError):
14+
decoy.prop("42")
15+
16+
17+
def test_property_missing_rehearsal_after_success(decoy: Decoy) -> None:
18+
"""It raises an error if no prop rehearsal after a successful rehearsal."""
19+
subject = decoy.mock(cls=SomeClass)
20+
21+
decoy.prop(subject.primitive_property)
22+
23+
with pytest.raises(MissingRehearsalError):
24+
decoy.prop("42")

0 commit comments

Comments
 (0)