33from collections .abc import AsyncGenerator
44from collections .abc import Generator
55from contextlib import suppress
6+ from inspect import iscoroutine
67
78import pytest
89import pytest_asyncio
910import ydb
1011import ydb_dbapi as dbapi
11- from sqlalchemy .util import await_only , greenlet_spawn
12- from inspect import iscoroutine
12+ from sqlalchemy .util import await_only
13+ from sqlalchemy . util import greenlet_spawn
1314
1415
15- def maybe_await (obj ) :
16+ def maybe_await (obj : callable ) -> any :
1617 if not iscoroutine (obj ):
1718 return obj
1819 return await_only (obj )
@@ -66,7 +67,9 @@ def _test_connection(self, connection: dbapi.Connection) -> None:
6667 with pytest .raises (dbapi .ProgrammingError ):
6768 maybe_await (connection .describe ("/local/foo" ))
6869
69- maybe_await (cur .execute ("CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))" ))
70+ maybe_await (cur .execute (
71+ "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
72+ ))
7073
7174 assert maybe_await (connection .check_exists ("/local/foo" ))
7275
@@ -113,7 +116,11 @@ def _test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
113116
114117 maybe_await (cur .close ())
115118
116- def _test_errors (self , connection : dbapi .Connection , connect_method = dbapi .connect ) -> None :
119+ def _test_errors (
120+ self ,
121+ connection : dbapi .Connection ,
122+ connect_method : callable = dbapi .connect
123+ ) -> None :
117124 with pytest .raises (dbapi .InterfaceError ):
118125 maybe_await (connect_method (
119126 "localhost:2136" , # type: ignore
@@ -137,7 +144,9 @@ def _test_errors(self, connection: dbapi.Connection, connect_method=dbapi.connec
137144 with pytest .raises (dbapi .ProgrammingError ):
138145 maybe_await (cur .execute ("SELECT * FROM test" ))
139146
140- maybe_await (cur .execute ("CREATE TABLE test(id Int64, PRIMARY KEY (id))" ))
147+ maybe_await (cur .execute (
148+ "CREATE TABLE test(id Int64, PRIMARY KEY (id))"
149+ ))
141150
142151 maybe_await (cur .execute ("INSERT INTO test(id) VALUES(1)" ))
143152
@@ -195,7 +204,7 @@ class TestAsyncConnection(BaseDBApiTestSuit):
195204 async def connection (
196205 self , connection_kwargs : dict
197206 ) -> AsyncGenerator [dbapi .AsyncConnection ]:
198- def connect ():
207+ def connect () -> dbapi . AsyncConnection :
199208 return maybe_await (dbapi .async_connect (** connection_kwargs ))
200209
201210 conn = await greenlet_spawn (connect )
0 commit comments