Skip to content

Commit 4ef9bb5

Browse files
committed
test: Restructure parity guard with pytest.param to satisfy mypy
1 parent 2c96aba commit 4ef9bb5

1 file changed

Lines changed: 22 additions & 47 deletions

File tree

‎ld_eventsource/testing/test_sync_async_parity.py‎

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,38 @@
2020
ConnectStrategy)
2121
from ld_eventsource.sse_client import SSEClient
2222

23-
# Each entry pairs a public synchronous class with its asynchronous counterpart, plus
24-
# allowlists of names that are intentionally present on only one side. Every allowlisted
25-
# name must carry a justification; if the test flags a genuinely one-sided member, add it
26-
# here with a comment rather than weakening the comparison.
27-
_PAIRS = [
28-
{
29-
"sync": SSEClient,
30-
"async": AsyncSSEClient,
31-
# Names allowed to exist only on the sync class.
32-
"sync_only": set(),
33-
# Names allowed to exist only on the async class.
34-
"async_only": set(),
35-
},
36-
{
37-
"sync": ConnectStrategy,
38-
"async": AsyncConnectStrategy,
39-
"sync_only": set(),
40-
"async_only": set(),
41-
},
42-
{
43-
"sync": ConnectionClient,
44-
"async": AsyncConnectionClient,
45-
"sync_only": set(),
46-
"async_only": set(),
47-
},
48-
{
49-
"sync": ConnectionResult,
50-
"async": AsyncConnectionResult,
51-
"sync_only": set(),
52-
"async_only": set(),
53-
},
54-
]
55-
5623

5724
def _public_names(cls):
5825
return {name for name in dir(cls) if not name.startswith("_")} - set(dir(object))
5926

6027

28+
# Each param pairs a public synchronous class with its asynchronous counterpart, plus
29+
# allowlists of names intentionally present on only one side. Every allowlisted name must
30+
# carry a justification; if the test flags a genuinely one-sided member, add it here with a
31+
# comment rather than weakening the comparison.
6132
@pytest.mark.parametrize(
62-
"pair",
63-
_PAIRS,
64-
ids=[f"{p['sync'].__name__}/{p['async'].__name__}" for p in _PAIRS],
33+
"sync_cls, async_cls, sync_only, async_only",
34+
[
35+
pytest.param(SSEClient, AsyncSSEClient, set(), set(), id="SSEClient/AsyncSSEClient"),
36+
pytest.param(ConnectStrategy, AsyncConnectStrategy, set(), set(), id="ConnectStrategy/AsyncConnectStrategy"),
37+
pytest.param(ConnectionClient, AsyncConnectionClient, set(), set(), id="ConnectionClient/AsyncConnectionClient"),
38+
pytest.param(ConnectionResult, AsyncConnectionResult, set(), set(), id="ConnectionResult/AsyncConnectionResult"),
39+
],
6540
)
66-
def test_sync_async_public_surface_matches(pair):
67-
sync_names = _public_names(pair["sync"])
68-
async_names = _public_names(pair["async"])
41+
def test_sync_async_public_surface_matches(sync_cls, async_cls, sync_only, async_only):
42+
sync_names = _public_names(sync_cls)
43+
async_names = _public_names(async_cls)
6944

70-
sync_only = sync_names - async_names - pair["sync_only"]
71-
async_only = async_names - sync_names - pair["async_only"]
45+
sync_only_diff = sync_names - async_names - sync_only
46+
async_only_diff = async_names - sync_names - async_only
7247

73-
assert not sync_only, (
74-
f"{pair['sync'].__name__} exposes public names with no counterpart on "
75-
f"{pair['async'].__name__}: {sorted(sync_only)}. Add the missing member to the "
48+
assert not sync_only_diff, (
49+
f"{sync_cls.__name__} exposes public names with no counterpart on "
50+
f"{async_cls.__name__}: {sorted(sync_only_diff)}. Add the missing member to the "
7651
f"async class, or allowlist it in 'sync_only' with a justification."
7752
)
78-
assert not async_only, (
79-
f"{pair['async'].__name__} exposes public names with no counterpart on "
80-
f"{pair['sync'].__name__}: {sorted(async_only)}. Add the missing member to the "
53+
assert not async_only_diff, (
54+
f"{async_cls.__name__} exposes public names with no counterpart on "
55+
f"{sync_cls.__name__}: {sorted(async_only_diff)}. Add the missing member to the "
8156
f"sync class, or allowlist it in 'async_only' with a justification."
8257
)

0 commit comments

Comments
 (0)