Skip to content

Commit b5a55ab

Browse files
test: compare schema fields instead of strings in alembic test (#384)
* test: failing alembic test compares structured objects instead of strings * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * temporarily cap max sqlalchemy while we debug failing compliance tests * document pin Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 6e2fa49 commit b5a55ab

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

Diff for: setup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ def readme():
8484
# https://github.com/googleapis/google-cloud-python/issues/10566
8585
"google-auth>=1.25.0,<3.0.0dev", # Work around pip wack.
8686
"google-cloud-bigquery>=2.25.2,<3.0.0dev",
87-
"sqlalchemy>=1.2.0,<1.5.0dev",
87+
# Temporarily set maximimum sqlalchemy to a known-working version while
88+
# we debug failing compliance tests. See:
89+
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/386
90+
# and
91+
# https://github.com/googleapis/python-bigquery-sqlalchemy/issues/385
92+
"sqlalchemy>=1.2.0,<=1.4.25",
8893
"future",
8994
],
9095
extras_require=extras,

Diff for: tests/system/test_alembic.py

+18-22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sqlalchemy import Column, DateTime, Integer, String
2424

2525
import google.api_core.exceptions
26+
from google.cloud.bigquery import SchemaField
2627

2728
alembic = pytest.importorskip("alembic")
2829

@@ -43,10 +44,7 @@ def get_table(table_name, data="table"):
4344
if data == "table":
4445
return table
4546
elif data == "schema":
46-
return [
47-
repr(s).replace(", (), None)", ")").replace(", None)", ")")
48-
for s in table.schema
49-
]
47+
return table.schema
5048
else:
5149
raise ValueError(data)
5250
except google.api_core.exceptions.NotFound:
@@ -78,9 +76,9 @@ def test_alembic_scenario(alembic_table):
7876
Column("description", String(200)),
7977
)
8078
assert alembic_table("account", "schema") == [
81-
"SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())",
82-
"SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())",
83-
"SchemaField('description', 'STRING(200)', 'NULLABLE', None, (), ())",
79+
SchemaField("id", "INTEGER", "REQUIRED"),
80+
SchemaField("name", "STRING(50)", "REQUIRED", description="The name"),
81+
SchemaField("description", "STRING(200)"),
8482
]
8583

8684
op.bulk_insert(
@@ -103,11 +101,10 @@ def test_alembic_scenario(alembic_table):
103101
)
104102

105103
assert alembic_table("account", "schema") == [
106-
"SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())",
107-
"SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())",
108-
"SchemaField('description', 'STRING(200)', 'NULLABLE', None, (), ())",
109-
"SchemaField('last_transaction_date', 'DATETIME', 'NULLABLE', 'when updated'"
110-
", (), ())",
104+
SchemaField("id", "INTEGER", "REQUIRED"),
105+
SchemaField("name", "STRING(50)", "REQUIRED", description="The name"),
106+
SchemaField("description", "STRING(200)"),
107+
SchemaField("last_transaction_date", "DATETIME", description="when updated"),
111108
]
112109

113110
op.create_table(
@@ -123,8 +120,8 @@ def test_alembic_scenario(alembic_table):
123120

124121
op.drop_column("account_w_comment", "description")
125122
assert alembic_table("account_w_comment", "schema") == [
126-
"SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())",
127-
"SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())",
123+
SchemaField("id", "INTEGER", "REQUIRED"),
124+
SchemaField("name", "STRING(50)", "REQUIRED", description="The name"),
128125
]
129126

130127
op.drop_table("account_w_comment")
@@ -133,11 +130,10 @@ def test_alembic_scenario(alembic_table):
133130
op.rename_table("account", "accounts")
134131
assert alembic_table("account") is None
135132
assert alembic_table("accounts", "schema") == [
136-
"SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())",
137-
"SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())",
138-
"SchemaField('description', 'STRING(200)', 'NULLABLE', None, (), ())",
139-
"SchemaField('last_transaction_date', 'DATETIME', 'NULLABLE', 'when updated'"
140-
", (), ())",
133+
SchemaField("id", "INTEGER", "REQUIRED"),
134+
SchemaField("name", "STRING(50)", "REQUIRED", description="The name"),
135+
SchemaField("description", "STRING(200)"),
136+
SchemaField("last_transaction_date", "DATETIME", description="when updated"),
141137
]
142138
op.drop_table("accounts")
143139
assert alembic_table("accounts") is None
@@ -157,9 +153,9 @@ def test_alembic_scenario(alembic_table):
157153
# nullable:
158154
op.alter_column("transactions", "amount", True)
159155
assert alembic_table("transactions", "schema") == [
160-
"SchemaField('account', 'INTEGER', 'REQUIRED', None, (), ())",
161-
"SchemaField('transaction_time', 'DATETIME', 'REQUIRED', None, (), ())",
162-
"SchemaField('amount', 'NUMERIC(11, 2)', 'NULLABLE', None, (), ())",
156+
SchemaField("account", "INTEGER", "REQUIRED"),
157+
SchemaField("transaction_time", "DATETIME", "REQUIRED"),
158+
SchemaField("amount", "NUMERIC(11, 2)"),
163159
]
164160

165161
op.create_table_comment("transactions", "Transaction log")

0 commit comments

Comments
 (0)