2828
2929from adbc_drivers_validation import compare , model
3030from adbc_drivers_validation .model import Query
31- from adbc_drivers_validation .utils import scoped_trace
31+ from adbc_drivers_validation .utils import scoped_trace , setup_statement
3232
3333
3434def generate_tests (all_quirks : list [model .DriverQuirks ], metafunc ) -> None :
@@ -112,7 +112,7 @@ def test_query(
112112 cursor .adbc_statement .execute_update ()
113113
114114 with conn .cursor () as cursor :
115- with _setup_statement (query , cursor ):
115+ with setup_statement (query , cursor ):
116116 cursor .adbc_statement .set_sql_query (sql )
117117 handle , _ = cursor .adbc_statement .execute_query ()
118118 with pyarrow .RecordBatchReader ._import_from_c (handle .address ) as reader :
@@ -135,7 +135,7 @@ def test_execute_schema(
135135 _setup_query (driver , conn , query )
136136
137137 with conn .cursor () as cursor :
138- with _setup_statement (query , cursor ):
138+ with setup_statement (query , cursor ):
139139 schema = cursor .adbc_execute_schema (sql )
140140
141141 compare .compare_schemas (expected_schema , schema )
@@ -227,31 +227,3 @@ def _setup_query(
227227 with scoped_trace (f"setup statement: { statement } " ):
228228 cursor .adbc_statement .set_sql_query (statement )
229229 cursor .adbc_statement .execute_update ()
230-
231-
232- @contextlib .contextmanager
233- def _setup_statement (query : Query , cursor : adbc_driver_manager .dbapi .Cursor ) -> None :
234- md = query .metadata ()
235- if "statement" not in md :
236- yield
237- return
238-
239- statement_md = md ["statement" ]
240- if "options" not in statement_md :
241- yield
242- return
243-
244- options = {}
245- options_revert = {}
246- for key , value in statement_md ["options" ].items ():
247- if isinstance (value , dict ):
248- assert "apply" in value
249- assert "revert" in value
250- options [key ] = value ["apply" ]
251- options_revert [key ] = value ["revert" ]
252- else :
253- options [key ] = value
254-
255- cursor .adbc_statement .set_options (** options )
256- yield
257- cursor .adbc_statement .set_options (** options_revert )
0 commit comments