Skip to content

Commit 1b7468f

Browse files
committed
Add test for api parity between sync and async classes
1 parent 4242a39 commit 1b7468f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# VortexDB and AsyncVortexDB should expose the same public methods
2+
# with the same signatures
3+
import inspect
4+
5+
from vortexdb.client import VortexDB
6+
from vortexdb.async_client import AsyncVortexDB
7+
8+
9+
def public_methods(cls):
10+
return {
11+
name: value
12+
for name, value in vars(cls).items()
13+
if callable(value) and not name.startswith("_")
14+
}
15+
16+
17+
def test_sync_async_client_api_parity():
18+
sync_methods = public_methods(VortexDB)
19+
async_methods = public_methods(AsyncVortexDB)
20+
21+
sync_names = set(sync_methods)
22+
async_names = set(async_methods)
23+
24+
assert sync_names == async_names, (
25+
"Sync and async clients expose different methods. "
26+
f"Only sync: {sorted(sync_names - async_names)}. "
27+
f"Only async: {sorted(async_names - sync_names)}."
28+
)
29+
30+
mismatches = [
31+
f" {name}: sync{inspect.signature(sync_methods[name])}"
32+
f" != async{inspect.signature(async_methods[name])}"
33+
for name in sync_names
34+
if inspect.signature(sync_methods[name])
35+
!= inspect.signature(async_methods[name])
36+
]
37+
38+
assert not mismatches, (
39+
"Sync and async methods have mismatched signatures:\n" + "\n".join(mismatches)
40+
)

0 commit comments

Comments
 (0)