|
19 | 19 | pytest_generate_tests hook, call generate_tests. |
20 | 20 | """ |
21 | 21 |
|
22 | | -import typing |
23 | | - |
24 | 22 | import adbc_driver_manager.dbapi |
25 | 23 | import pyarrow |
26 | 24 | import pytest |
@@ -140,35 +138,34 @@ def test_execute_schema( |
140 | 138 | def test_get_table_schema( |
141 | 139 | self, |
142 | 140 | driver: model.DriverQuirks, |
143 | | - conn_factory: typing.Callable[[], adbc_driver_manager.dbapi.Connection], |
| 141 | + conn: adbc_driver_manager.dbapi.Connection, |
144 | 142 | query: model.Query, |
145 | 143 | ) -> None: |
146 | 144 | subquery = query.query |
147 | 145 |
|
148 | 146 | expected_schema = subquery.expected_schema() |
149 | 147 |
|
150 | | - with conn_factory() as conn: |
151 | | - with setup_connection(query, conn): |
152 | | - _setup_query(driver, conn, query) |
153 | | - |
154 | | - table_name = None |
155 | | - md = query.metadata() |
156 | | - table_name = md.setup.drop |
157 | | - if not table_name and isinstance(subquery, model.SelectQuery): |
158 | | - # XXX: rather hacky, but extract the table name from the SELECT query |
159 | | - # that would normally be executed |
160 | | - query_str = subquery.query().split() |
161 | | - for i, word in enumerate(query_str): |
162 | | - if word.upper() == "FROM": |
163 | | - table_name = query_str[i + 1] |
164 | | - break |
165 | | - |
166 | | - assert table_name, "Could not determine table name" |
167 | | - |
168 | | - schema = conn.adbc_get_table_schema(table_name) |
169 | | - # Ignore the first column which is normally used to sort the table |
170 | | - schema = pyarrow.schema(list(schema)[1:]) |
171 | | - compare.compare_schemas(expected_schema, schema) |
| 148 | + with setup_connection(query, conn): |
| 149 | + _setup_query(driver, conn, query) |
| 150 | + |
| 151 | + table_name = None |
| 152 | + md = query.metadata() |
| 153 | + table_name = md.setup.drop |
| 154 | + if not table_name and isinstance(subquery, model.SelectQuery): |
| 155 | + # XXX: rather hacky, but extract the table name from the SELECT query |
| 156 | + # that would normally be executed |
| 157 | + query_str = subquery.query().split() |
| 158 | + for i, word in enumerate(query_str): |
| 159 | + if word.upper() == "FROM": |
| 160 | + table_name = query_str[i + 1] |
| 161 | + break |
| 162 | + |
| 163 | + assert table_name, "Could not determine table name" |
| 164 | + |
| 165 | + schema = conn.adbc_get_table_schema(table_name) |
| 166 | + # Ignore the first column which is normally used to sort the table |
| 167 | + schema = pyarrow.schema(list(schema)[1:]) |
| 168 | + compare.compare_schemas(expected_schema, schema) |
172 | 169 |
|
173 | 170 | def test_show_queries( |
174 | 171 | self, |
|
0 commit comments