-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interfaces.py
More file actions
49 lines (39 loc) · 1.64 KB
/
test_interfaces.py
File metadata and controls
49 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from inspect import signature
from typing import Protocol, runtime_checkable
from sqlalchemy_bind_manager.repository import (
SQLAlchemyAsyncRepository,
SQLAlchemyAsyncRepositoryInterface,
SQLAlchemyRepository,
SQLAlchemyRepositoryInterface,
)
@runtime_checkable
class RuntimeRepoProtocol(SQLAlchemyRepositoryInterface, Protocol): ...
@runtime_checkable
class RuntimeAsyncRepoProtocol(SQLAlchemyAsyncRepositoryInterface, Protocol): ...
def test_interfaces():
assert issubclass(SQLAlchemyRepository, RuntimeRepoProtocol)
assert issubclass(SQLAlchemyAsyncRepository, RuntimeAsyncRepoProtocol)
sync_methods = [
method
for method in dir(SQLAlchemyRepositoryInterface)
if method.startswith("_") is False
]
async_methods = [
method
for method in dir(SQLAlchemyAsyncRepositoryInterface)
if method.startswith("_") is False
]
assert sync_methods == async_methods
for method in sync_methods:
# Concrete sync signature is the same as sync protocol signature
assert signature(getattr(SQLAlchemyRepository, method)) == signature(
getattr(SQLAlchemyRepositoryInterface, method)
)
# Concrete async signature is the same as async protocol signature
assert signature(getattr(SQLAlchemyAsyncRepository, method)) == signature(
getattr(SQLAlchemyAsyncRepositoryInterface, method)
)
# Sync protocol signature is the same as async protocol signature
assert signature(
getattr(SQLAlchemyAsyncRepositoryInterface, method)
) == signature(getattr(SQLAlchemyRepositoryInterface, method))