Skip to content

Commit 396eae2

Browse files
authored
fix(warnings): do not trigger MiscalledStubWarnings from prop events (#126)
Closes #125
1 parent 5db349b commit 396eae2

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

decoy/warning_checker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .spy_events import (
66
AnySpyEvent,
7+
SpyCall,
78
SpyEvent,
89
VerifyRehearsal,
910
WhenRehearsal,
@@ -22,14 +23,15 @@ def check(all_calls: Sequence[AnySpyEvent]) -> None:
2223
_check_no_redundant_verify(all_calls)
2324

2425

25-
def _check_no_miscalled_stubs(all_calls: Sequence[AnySpyEvent]) -> None:
26+
def _check_no_miscalled_stubs(all_events: Sequence[AnySpyEvent]) -> None:
2627
"""Ensure every call matches a rehearsal, if the spy has rehearsals."""
2728
all_calls_by_id: Dict[int, List[AnySpyEvent]] = {}
2829

29-
for call in all_calls:
30-
spy_id = call.spy_id
31-
spy_calls = all_calls_by_id.get(spy_id, [])
32-
all_calls_by_id[spy_id] = spy_calls + [call]
30+
for event in all_events:
31+
if isinstance(event.payload, SpyCall):
32+
spy_id = event.spy_id
33+
spy_calls = all_calls_by_id.get(spy_id, [])
34+
all_calls_by_id[spy_id] = spy_calls + [event]
3335

3436
for spy_calls in all_calls_by_id.values():
3537
unmatched: List[SpyEvent] = []

tests/test_warning_checker.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
AnySpyEvent,
88
SpyCall,
99
SpyEvent,
10+
SpyPropAccess,
11+
PropAccessType,
1012
WhenRehearsal,
1113
VerifyRehearsal,
1214
)
@@ -77,6 +79,31 @@ class WarningCheckerSpec(NamedTuple):
7779
],
7880
expected_warnings=[],
7981
),
82+
# it should not warn due to spy prop access
83+
WarningCheckerSpec(
84+
all_calls=[
85+
WhenRehearsal(
86+
spy_id=1,
87+
spy_name="spy",
88+
payload=SpyPropAccess(
89+
prop_name="prop_name", access_type=PropAccessType.GET
90+
),
91+
),
92+
SpyEvent(
93+
spy_id=1,
94+
spy_name="spy",
95+
payload=SpyPropAccess(
96+
prop_name="other_prop", access_type=PropAccessType.GET
97+
),
98+
),
99+
WhenRehearsal(
100+
spy_id=2,
101+
spy_name="spy.other_prop",
102+
payload=SpyCall(args=(), kwargs={}, ignore_extra_args=False),
103+
),
104+
],
105+
expected_warnings=[],
106+
),
80107
# it should warn if a spy has multiple rehearsals without a matching call
81108
WarningCheckerSpec(
82109
all_calls=[

0 commit comments

Comments
 (0)