@@ -29,9 +29,11 @@ def _test_isolation_level_read_only(
29
29
cursor = connection .cursor ()
30
30
with suppress (dbapi .DatabaseError ):
31
31
maybe_await (cursor .execute_scheme ("DROP TABLE foo" ))
32
- maybe_await (cursor .execute_scheme (
33
- "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
34
- ))
32
+ maybe_await (
33
+ cursor .execute_scheme (
34
+ "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
35
+ )
36
+ )
35
37
36
38
connection .set_isolation_level (isolation_level )
37
39
cursor = connection .cursor ()
@@ -60,9 +62,11 @@ def _test_connection(self, connection: dbapi.Connection) -> None:
60
62
with pytest .raises (dbapi .ProgrammingError ):
61
63
maybe_await (connection .describe ("/local/foo" ))
62
64
63
- maybe_await (cur .execute_scheme (
64
- "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
65
- ))
65
+ maybe_await (
66
+ cur .execute_scheme (
67
+ "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
68
+ )
69
+ )
66
70
67
71
assert maybe_await (connection .check_exists ("/local/foo" ))
68
72
@@ -84,26 +88,28 @@ def _test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
84
88
"CREATE TABLE test(id Int64 NOT NULL, text Utf8, PRIMARY KEY (id))"
85
89
))
86
90
87
- maybe_await (cur .execute (
88
- """
91
+ maybe_await (
92
+ cur .execute (
93
+ """
89
94
DECLARE $data AS List<Struct<id:Int64, text: Utf8>>;
90
95
91
96
INSERT INTO test SELECT id, text FROM AS_TABLE($data);
92
97
""" ,
93
- {
94
- "$data" : ydb .TypedValue (
95
- [
96
- {"id" : 17 , "text" : "seventeen" },
97
- {"id" : 21 , "text" : "twenty one" },
98
- ],
99
- ydb .ListType (
100
- ydb .StructType ()
101
- .add_member ("id" , ydb .PrimitiveType .Int64 )
102
- .add_member ("text" , ydb .PrimitiveType .Utf8 )
103
- ),
104
- )
105
- },
106
- ))
98
+ {
99
+ "$data" : ydb .TypedValue (
100
+ [
101
+ {"id" : 17 , "text" : "seventeen" },
102
+ {"id" : 21 , "text" : "twenty one" },
103
+ ],
104
+ ydb .ListType (
105
+ ydb .StructType ()
106
+ .add_member ("id" , ydb .PrimitiveType .Int64 )
107
+ .add_member ("text" , ydb .PrimitiveType .Utf8 )
108
+ ),
109
+ )
110
+ },
111
+ )
112
+ )
107
113
108
114
maybe_await (cur .execute_scheme ("DROP TABLE test" ))
109
115
@@ -112,13 +118,15 @@ def _test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
112
118
def _test_errors (
113
119
self ,
114
120
connection : dbapi .Connection ,
115
- connect_method : callable = dbapi .connect
121
+ connect_method : callable = dbapi .connect ,
116
122
) -> None :
117
123
with pytest .raises (dbapi .InterfaceError ):
118
- maybe_await (connect_method (
119
- "localhost:2136" , # type: ignore
120
- database = "/local666" , # type: ignore
121
- ))
124
+ maybe_await (
125
+ connect_method (
126
+ "localhost:2136" , # type: ignore
127
+ database = "/local666" , # type: ignore
128
+ )
129
+ )
122
130
123
131
cur = connection .cursor ()
124
132
@@ -137,9 +145,9 @@ def _test_errors(
137
145
with pytest .raises (dbapi .ProgrammingError ):
138
146
maybe_await (cur .execute ("SELECT * FROM test" ))
139
147
140
- maybe_await (cur . execute_scheme (
141
- "CREATE TABLE test(id Int64, PRIMARY KEY (id))"
142
- ))
148
+ maybe_await (
149
+ cur . execute_scheme ( "CREATE TABLE test(id Int64, PRIMARY KEY (id))" )
150
+ )
143
151
144
152
maybe_await (cur .execute ("INSERT INTO test(id) VALUES(1)" ))
145
153
@@ -154,8 +162,9 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
154
162
with suppress (dbapi .DatabaseError ):
155
163
maybe_await (cursor .execute_scheme ("DROP TABLE pet" ))
156
164
157
- maybe_await (cursor .execute_scheme (
158
- """
165
+ maybe_await (
166
+ cursor .execute_scheme (
167
+ """
159
168
CREATE TABLE pet (
160
169
pet_id INT,
161
170
name TEXT NOT NULL,
@@ -165,7 +174,8 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
165
174
PRIMARY KEY (pet_id)
166
175
);
167
176
"""
168
- ))
177
+ )
178
+ )
169
179
170
180
column_types = (
171
181
ydb .BulkUpsertColumns ()
@@ -182,14 +192,14 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
182
192
"name" : "Lester" ,
183
193
"pet_type" : "Hamster" ,
184
194
"birth_date" : "2020-06-23" ,
185
- "owner" : "Lily"
195
+ "owner" : "Lily" ,
186
196
},
187
197
{
188
198
"pet_id" : 4 ,
189
199
"name" : "Quincy" ,
190
200
"pet_type" : "Parrot" ,
191
201
"birth_date" : "2013-08-11" ,
192
- "owner" : "Anne"
202
+ "owner" : "Anne" ,
193
203
},
194
204
]
195
205
@@ -204,18 +214,19 @@ def _test_error_with_interactive_tx(
204
214
self ,
205
215
connection : dbapi .Connection ,
206
216
) -> None :
207
-
208
217
cur = connection .cursor ()
209
- maybe_await (cur .execute_scheme (
210
- """
218
+ maybe_await (
219
+ cur .execute_scheme (
220
+ """
211
221
DROP TABLE IF EXISTS test;
212
222
CREATE TABLE test (
213
223
id Int64 NOT NULL,
214
224
val Int64,
215
225
PRIMARY KEY(id)
216
226
)
217
227
"""
218
- ))
228
+ )
229
+ )
219
230
220
231
connection .set_isolation_level (dbapi .IsolationLevel .SERIALIZABLE )
221
232
maybe_await (connection .begin ())
@@ -274,8 +285,8 @@ def test_bulk_upsert(self, connection: dbapi.Connection) -> None:
274
285
self ._test_bulk_upsert (connection )
275
286
276
287
def test_errors_with_interactive_tx (
277
- self , connection : dbapi .Connection
278
- ) -> None :
288
+ self , connection : dbapi .Connection
289
+ ) -> None :
279
290
self ._test_error_with_interactive_tx (connection )
280
291
281
292
@@ -291,8 +302,10 @@ def connect() -> dbapi.AsyncConnection:
291
302
try :
292
303
yield conn
293
304
finally :
305
+
294
306
def close () -> None :
295
307
maybe_await (conn .close ())
308
+
296
309
await greenlet_spawn (close )
297
310
298
311
@pytest .mark .asyncio
@@ -315,7 +328,9 @@ async def test_isolation_level_read_only(
315
328
) -> None :
316
329
await greenlet_spawn (
317
330
self ._test_isolation_level_read_only ,
318
- connection , isolation_level , read_only
331
+ connection ,
332
+ isolation_level ,
333
+ read_only ,
319
334
)
320
335
321
336
@pytest .mark .asyncio
0 commit comments