66
77from decoy import Decoy , errors
88from decoy .spy import AsyncSpy , Spy
9+ from decoy .warnings import IncorrectCallWarning
910
1011from .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+
2231def 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+
3156def 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" )
0 commit comments