Skip to content

Commit c65ad37

Browse files
committed
test: Add DBAPI 2.0 compliance test suite including a base test class, SQL factory, helper utilities, and nox integration.
1 parent 1db7aa3 commit c65ad37

6 files changed

Lines changed: 1372 additions & 0 deletions

File tree

packages/google-cloud-spanner-dbapi-driver/noxfile.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
SYSTEM_TEST_EXTRAS: List[str] = []
8585
SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}
8686

87+
COMPLIANCE_TEST_STANDARD_DEPENDENCIES = [
88+
"pytest",
89+
"spannerlib-python",
90+
"google-cloud-spanner",
91+
]
92+
8793
VERBOSE = False
8894
MODE = "--verbose" if VERBOSE else "--quiet"
8995

@@ -337,6 +343,31 @@ def system(session):
337343
)
338344

339345

346+
@nox.session(python=DEFAULT_PYTHON_VERSION)
347+
def compliance(session):
348+
"""Run compliance tests."""
349+
350+
# Sanity check: Only run tests if the environment variable is set.
351+
if not os.environ.get("SPANNER_EMULATOR_HOST", ""):
352+
session.skip(
353+
"Emulator host must be set via SPANNER_EMULATOR_HOST environment variable"
354+
)
355+
356+
session.install(*COMPLIANCE_TEST_STANDARD_DEPENDENCIES)
357+
session.install("-e", ".")
358+
359+
test_paths = (
360+
session.posargs if session.posargs else [os.path.join("tests", "compliance")]
361+
)
362+
session.run(
363+
"py.test",
364+
MODE,
365+
f"--junitxml=compliance_{session.python}_sponge_log.xml",
366+
*test_paths,
367+
env={},
368+
)
369+
370+
340371
@nox.session(python=DEFAULT_PYTHON_VERSION)
341372
def cover(session):
342373
"""Run the final coverage report.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This file is intentionally left blank to mark this directory as a package.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Helper functions for compliance tests."""
15+
16+
import os
17+
18+
SPANNER_EMULATOR_HOST = os.environ.get("SPANNER_EMULATOR_HOST")
19+
20+
PROJECT_ID = "test-project"
21+
INSTANCE_ID = "test-instance"
22+
DATABASE_ID = "test-db"
23+
24+
EMULATOR_TEST_CONNECTION_STRING = (
25+
f"{SPANNER_EMULATOR_HOST}"
26+
f"projects/{PROJECT_ID}"
27+
f"/instances/{INSTANCE_ID}"
28+
f"/databases/{DATABASE_ID}"
29+
"?autoConfigEmulator=true"
30+
)
31+
32+
33+
def setup_test_env() -> None:
34+
print(f"Set SPANNER_EMULATOR_HOST to {os.environ['SPANNER_EMULATOR_HOST']}")
35+
print(f"Using Connection String: {get_test_connection_string()}")
36+
37+
38+
def get_test_connection_string() -> str:
39+
return EMULATOR_TEST_CONNECTION_STRING

0 commit comments

Comments
 (0)