Skip to content

Commit b476c87

Browse files
committed
feat: add tests for changing current catalog/schema
1 parent 94ecc43 commit b476c87

4 files changed

Lines changed: 52 additions & 12 deletions

File tree

adbc_drivers_validation/model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class DriverSetup:
7878
@dataclasses.dataclass
7979
class DriverFeatures:
8080
connection_get_table_schema: bool = False
81+
connection_set_current_catalog: bool = False
82+
connection_set_current_schema: bool = False
8183
connection_transactions: bool = False
8284
statement_bulk_ingest: bool = False
8385
statement_bulk_ingest_catalog: bool = False
@@ -97,6 +99,8 @@ def __init__(
9799
self,
98100
*,
99101
connection_get_table_schema=False,
102+
connection_set_current_catalog=False,
103+
connection_set_current_schema=False,
100104
connection_transactions=False,
101105
statement_bulk_ingest=False,
102106
statement_bulk_ingest_catalog=False,
@@ -113,6 +117,8 @@ def __init__(
113117
supported_xdbc_fields=None,
114118
):
115119
self.connection_get_table_schema = connection_get_table_schema
120+
self.connection_set_current_catalog = connection_set_current_catalog
121+
self.connection_set_current_schema = connection_set_current_schema
116122
self.connection_transactions = connection_transactions
117123
self.statement_bulk_ingest = statement_bulk_ingest
118124
self.statement_bulk_ingest_catalog = statement_bulk_ingest_catalog

adbc_drivers_validation/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def manual_test() -> None:
6767
pytest.skip("Skipping manual test, set RUN_MANUAL_TESTS=1")
6868

6969

70-
@pytest.fixture(scope="module")
70+
@pytest.fixture(scope="session")
7171
def conn_factory(
7272
request,
7373
driver: model.DriverQuirks,

adbc_drivers_validation/tests/connection.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
pytest_generate_tests hook, call generate_tests.
2020
"""
2121

22+
import typing
23+
2224
import adbc_driver_manager.dbapi
2325
import pyarrow
2426
import pytest
@@ -60,15 +62,49 @@ def generate_tests(quirks: model.DriverQuirks, metafunc) -> None:
6062

6163
class TestConnection:
6264
def test_current_catalog(
63-
self, conn: adbc_driver_manager.dbapi.Connection, driver: model.DriverQuirks
65+
self,
66+
driver: model.DriverQuirks,
67+
conn: adbc_driver_manager.dbapi.Connection,
6468
) -> None:
6569
assert conn.adbc_current_catalog == driver.features.current_catalog
6670

6771
def test_current_db_schema(
68-
self, conn: adbc_driver_manager.dbapi.Connection, driver: model.DriverQuirks
72+
self,
73+
driver: model.DriverQuirks,
74+
conn: adbc_driver_manager.dbapi.Connection,
6975
) -> None:
7076
assert conn.adbc_current_db_schema == driver.features.current_schema
7177

78+
def test_set_current_catalog(
79+
self,
80+
driver: model.DriverQuirks,
81+
conn_factory: typing.Callable[[], adbc_driver_manager.dbapi.Connection],
82+
):
83+
if not driver.features.connection_set_current_catalog:
84+
pytest.skip("not implemented")
85+
86+
with conn_factory() as conn:
87+
assert conn.adbc_current_catalog == driver.features.current_catalog
88+
conn.adbc_current_catalog = driver.features.secondary_catalog
89+
assert conn.adbc_current_catalog == driver.features.secondary_catalog
90+
conn.adbc_current_catalog = driver.features.current_catalog
91+
assert conn.adbc_current_catalog == driver.features.current_catalog
92+
93+
def test_set_current_schema(
94+
self,
95+
driver: model.DriverQuirks,
96+
conn_factory: typing.Callable[[], adbc_driver_manager.dbapi.Connection],
97+
):
98+
if not driver.features.connection_set_current_schema:
99+
pytest.skip("not implemented")
100+
101+
with conn_factory() as conn:
102+
assert conn.adbc_current_db_schema == driver.features.current_schema
103+
conn.adbc_current_db_schema = driver.features.secondary_schema
104+
assert conn.adbc_current_db_schema == driver.features.secondary_schema
105+
conn.adbc_current_db_schema = driver.features.current_schema
106+
assert conn.adbc_current_db_schema == driver.features.current_schema
107+
72108
def test_get_info(
73109
self, conn: adbc_driver_manager.dbapi.Connection, driver: model.DriverQuirks
74110
) -> None:

adbc_drivers_validation/tests/ingest.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ def generate_tests(quirks: model.DriverQuirks, metafunc) -> None:
3434
"""Parameterize the tests in this module for the given driver."""
3535
combinations = []
3636

37-
if (
38-
enabled := {
39-
"test_not_null": True,
40-
"test_temporary": quirks.features.statement_bulk_ingest_temporary,
41-
"test_schema": quirks.features.statement_bulk_ingest_schema,
42-
"test_catalog": quirks.features.statement_bulk_ingest_catalog,
43-
}.get(metafunc.definition.name, None)
44-
is not None
45-
):
37+
enabled = {
38+
"test_not_null": True,
39+
"test_temporary": quirks.features.statement_bulk_ingest_temporary,
40+
"test_schema": quirks.features.statement_bulk_ingest_schema,
41+
"test_catalog": quirks.features.statement_bulk_ingest_catalog,
42+
}.get(metafunc.definition.name, None)
43+
if enabled is not None:
4644
marks = []
4745
if not enabled:
4846
marks.append(pytest.mark.skip(reason="not implemented"))

0 commit comments

Comments
 (0)