|
20 | 20 | ConnectStrategy) |
21 | 21 | from ld_eventsource.sse_client import SSEClient |
22 | 22 |
|
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 | | - |
56 | 23 |
|
57 | 24 | def _public_names(cls): |
58 | 25 | return {name for name in dir(cls) if not name.startswith("_")} - set(dir(object)) |
59 | 26 |
|
60 | 27 |
|
| 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. |
61 | 32 | @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 | + ], |
65 | 40 | ) |
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) |
69 | 44 |
|
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 |
72 | 47 |
|
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 " |
76 | 51 | f"async class, or allowlist it in 'sync_only' with a justification." |
77 | 52 | ) |
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 " |
81 | 56 | f"sync class, or allowlist it in 'async_only' with a justification." |
82 | 57 | ) |
0 commit comments