Skip to content

Commit 029b181

Browse files
author
Ilya Gurov
authored
feat: support SQLAlchemy 1.4 (#191)
* WIP: update tests for SQLAlchemy 1.4 * feat: support SQLAlchemy 1.4 * fix migration bugs * test: update yaml * install 1.4 * fix the dialect name * fix caching * fix temp tables * update test suite * fix pytest * del unused * fix user agent * fix test * fix reflection test * fix test * fix tests * lint fix * fix test * migration fix * fix migration * check * fix test * fix migrations * fix migrations test * change default py version * minor fixes * test workflow changes * new tests skip * kokoro session fix
1 parent 417b8b8 commit 029b181

File tree

11 files changed

+2229
-23
lines changed

11 files changed

+2229
-23
lines changed

.github/sync-repo-settings.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ branchProtectionRules:
99
requiredStatusCheckContexts:
1010
- 'lint'
1111
- 'unit'
12-
- 'compliance_tests'
12+
- 'compliance_tests_13'
13+
- 'compliance_tests_14'
1314
- 'migration_tests'
1415
- 'cla/google'
1516
- 'Kokoro'

.github/workflows/test_suite.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
SPANNER_EMULATOR_HOST: localhost:9010
3939
GOOGLE_CLOUD_PROJECT: appdev-soda-spanner-staging
4040

41-
compliance_tests:
41+
compliance_tests_13:
4242
runs-on: ubuntu-latest
4343

4444
services:
@@ -57,7 +57,31 @@ jobs:
5757
- name: Install nox
5858
run: python -m pip install nox
5959
- name: Run Compliance Tests
60-
run: nox -s compliance_test
60+
run: nox -s compliance_test_13
61+
env:
62+
SPANNER_EMULATOR_HOST: localhost:9010
63+
GOOGLE_CLOUD_PROJECT: appdev-soda-spanner-staging
64+
65+
compliance_tests_14:
66+
runs-on: ubuntu-latest
67+
68+
services:
69+
emulator-0:
70+
image: gcr.io/cloud-spanner-emulator/emulator:latest
71+
ports:
72+
- 9010:9010
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v2
77+
- name: Setup Python
78+
uses: actions/setup-python@v2
79+
with:
80+
python-version: 3.8
81+
- name: Install nox
82+
run: python -m pip install nox
83+
- name: Run Compliance Tests
84+
run: nox -s compliance_test_14
6185
env:
6286
SPANNER_EMULATOR_HOST: localhost:9010
6387
GOOGLE_CLOUD_PROJECT: appdev-soda-spanner-staging

.kokoro/presubmit/compliance.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# Only run this nox session.
44
env_vars: {
55
key: "NOX_SESSION"
6-
value: "compliance_test"
6+
value: "compliance_test_13"
77
}

create_test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def set_test_config(project, instance):
2222
config = configparser.ConfigParser()
2323
url = (
24-
f"spanner:///projects/{project}/instances/{instance}/"
24+
f"spanner+spanner:///projects/{project}/instances/{instance}/"
2525
"databases/compliance-test"
2626
)
2727
config.add_section("db")
@@ -38,4 +38,4 @@ def main(argv):
3838

3939

4040
if __name__ == "__main__":
41-
main(sys.argv[1:])
41+
main(sys.argv[1:])

create_test_database.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,18 @@ def create_test_instance():
8282

8383
instance = CLIENT.instance(instance_id, instance_config, labels=labels)
8484

85-
8685
try:
87-
created_op = instance.create()
88-
created_op.result(1800) # block until completion
86+
created_op = instance.create()
87+
created_op.result(1800) # block until completion
8988
except AlreadyExists:
90-
pass # instance was already created
89+
pass # instance was already created
9190

9291
try:
93-
database = instance.database("compliance-test")
94-
created_op = database.create()
95-
created_op.result(1800)
92+
database = instance.database("compliance-test")
93+
created_op = database.create()
94+
created_op.result(1800)
9695
except AlreadyExists:
97-
pass # instance was already created
96+
pass # instance was already created
9897

9998
set_test_config(PROJECT, instance_id)
10099

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class SpannerDialect(DefaultDialect):
495495
Represents an API layer to control Cloud Spanner database with SQLAlchemy API.
496496
"""
497497

498-
name = "spanner"
498+
name = "spanner+spanner"
499499
driver = "spanner"
500500
positional = False
501501
paramstyle = "format"
@@ -512,6 +512,7 @@ class SpannerDialect(DefaultDialect):
512512
supports_native_enum = True
513513
supports_native_boolean = True
514514
supports_native_decimal = True
515+
supports_statement_cache = True
515516

516517
ddl_compiler = SpannerDDLCompiler
517518
preparer = SpannerIdentifierPreparer

noxfile.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class = StreamHandler
6464
op.alter_column(
6565
'account',
6666
'name',
67-
existing_type=sa.String(50),
68-
nullable=True,
67+
existing_type=sa.String(70),
6968
)"""
7069

7170

@@ -114,7 +113,7 @@ def lint_setup_py(session):
114113

115114

116115
@nox.session(python=DEFAULT_PYTHON_VERSION)
117-
def compliance_test(session):
116+
def compliance_test_13(session):
118117
"""Run SQLAlchemy dialect compliance test suite."""
119118

120119
# Check the value of `RUN_COMPLIANCE_TESTS` env var. It defaults to true.
@@ -132,7 +131,6 @@ def compliance_test(session):
132131
"pytest", "pytest-cov", "pytest-asyncio",
133132
)
134133

135-
session.install("pytest")
136134
session.install("mock")
137135
session.install("-e", ".[tracing]")
138136
session.run("python", "create_test_database.py")
@@ -145,7 +143,46 @@ def compliance_test(session):
145143
"--cov-config=.coveragerc",
146144
"--cov-report=",
147145
"--cov-fail-under=0",
148-
"test",
146+
"--asyncio-mode=auto",
147+
"test/test_suite_13.py",
148+
)
149+
150+
151+
@nox.session(python=DEFAULT_PYTHON_VERSION)
152+
def compliance_test_14(session):
153+
"""Run SQLAlchemy dialect compliance test suite."""
154+
155+
# Check the value of `RUN_COMPLIANCE_TESTS` env var. It defaults to true.
156+
if os.environ.get("RUN_COMPLIANCE_TESTS", "true") == "false":
157+
session.skip("RUN_COMPLIANCE_TESTS is set to false, skipping")
158+
# Sanity check: Only run tests if the environment variable is set.
159+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get(
160+
"SPANNER_EMULATOR_HOST", ""
161+
):
162+
session.skip(
163+
"Credentials or emulator host must be set via environment variable"
164+
)
165+
166+
session.install(
167+
"pytest", "pytest-cov", "pytest-asyncio",
168+
)
169+
170+
session.install("mock")
171+
session.install("-e", ".[tracing]")
172+
session.run("python", "create_test_database.py")
173+
174+
session.install("sqlalchemy>=1.4")
175+
176+
session.run(
177+
"py.test",
178+
"--cov=google.cloud.sqlalchemy_spanner",
179+
"--cov=tests",
180+
"--cov-append",
181+
"--cov-config=.coveragerc",
182+
"--cov-report=",
183+
"--cov-fail-under=0",
184+
"--asyncio-mode=auto",
185+
"test/test_suite_14.py",
149186
)
150187

151188

@@ -180,7 +217,7 @@ def migration_test(session):
180217
"GOOGLE_CLOUD_PROJECT", os.getenv("PROJECT_ID", "emulator-test-project"),
181218
)
182219
db_url = (
183-
f"spanner:///projects/{project}/instances/"
220+
f"spanner+spanner:///projects/{project}/instances/"
184221
"sqlalchemy-dialect-test/databases/compliance-test"
185222
)
186223

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
description=description,
6161
entry_points={
6262
"sqlalchemy.dialects": [
63-
"spanner = google.cloud.sqlalchemy_spanner:SpannerDialect"
63+
"spanner.spanner = google.cloud.sqlalchemy_spanner:SpannerDialect"
6464
]
6565
},
6666
install_requires=dependencies,
File renamed without changes.

0 commit comments

Comments
 (0)