Skip to content

test: enable tests to run on kokoro #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .circleci/config.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .kokoro/presubmit/presubmit.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Disable system tests.
env_vars: {
key: "RUN_SYSTEM_TESTS"
value: "false"
}
4 changes: 2 additions & 2 deletions create_test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def create_test_instance():
instance = CLIENT.instance(instance_id, instance_config, labels=labels)

created_op = instance.create()
created_op.result(120) # block until completion
created_op.result(1800) # block until completion

database = instance.database("compliance-test")
created_op = database.create()
created_op.result(120)
created_op.result(1800)

config = configparser.ConfigParser()
url = "spanner:///projects/{project}/instances/{instance_id}/databases/compliance-test".format(
Expand Down
8 changes: 8 additions & 0 deletions google/cloud/sqlalchemy_spanner/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@


class Requirements(SuiteRequirements):
@property
def sane_rowcount(self):
return exclusions.closed()

@property
def sane_multi_rowcount(self):
return exclusions.closed()

@property
def foreign_key_constraint_name_reflection(self):
return exclusions.open()
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class SpannerDialect(DefaultDialect):
execute_sequence_format = list

supports_alter = True
supports_sane_rowcount = True
supports_sane_rowcount = False
supports_sane_multi_rowcount = False
supports_default_values = False
supports_sequences = True
Expand Down
11 changes: 10 additions & 1 deletion migration_test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@

from google.cloud import spanner

project = os.getenv(
"GOOGLE_CLOUD_PROJECT",
os.getenv("PROJECT_ID", "emulator-test-project"),
)
db_url = (
f"spanner:///projects/{project}/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)

config = configparser.ConfigParser()
if os.path.exists("test.cfg"):
config.read("test.cfg")
else:
config.read("setup.cfg")
db_url = config.get("db", "default")
db_url = config.get("db", "default", fallback=db_url)

project = re.findall(r"projects(.*?)instances", db_url)
instance_id = re.findall(r"instances(.*?)databases", db_url)
Expand Down
10 changes: 9 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@ def migration_test(session):
session.install("-e", ".")
session.install("alembic")

project = os.getenv(
"GOOGLE_CLOUD_PROJECT", os.getenv("PROJECT_ID", "emulator-test-project"),
)
db_url = (
f"spanner:///projects/{project}/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)

config = configparser.ConfigParser()
if os.path.exists("test.cfg"):
config.read("test.cfg")
else:
config.read("setup.cfg")
db_url = config.get("db", "default")
db_url = config.get("db", "default", fallback=db_url)

session.run("alembic", "init", "test_migration")

Expand Down
16 changes: 14 additions & 2 deletions samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import configparser
import datetime
import os
import uuid

import pytest
Expand All @@ -30,11 +32,21 @@

@pytest.fixture
def db_url():
return (
"spanner:///projects/appdev-soda-spanner-staging/instances/"
project = os.getenv(
"GOOGLE_CLOUD_PROJECT", os.getenv("PROJECT_ID", "emulator-test-project"),
)
db_url = (
f"spanner:///projects/{project}/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)

config = configparser.ConfigParser()
if os.path.exists("test.cfg"):
config.read("test.cfg")
else:
config.read("setup.cfg")
return config.get("db", "default", fallback=db_url)


@pytest.fixture
def table_id():
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ python_files=test/*test_*.py
[sqla_testing]
requirement_cls=google.cloud.sqlalchemy_spanner.requirements:Requirements
profile_file=test/profiles.txt

[db]
default=spanner:///projects/appdev-soda-spanner-staging/instances/sqlalchemy-dialect-test/databases/compliance-test
36 changes: 23 additions & 13 deletions test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import configparser
from datetime import timezone
import decimal
import operator
Expand Down Expand Up @@ -115,6 +116,24 @@
config.test_schema = ""


PROJECT = os.getenv(
"GOOGLE_CLOUD_PROJECT", os.getenv("PROJECT_ID", "emulator-test-project"),
)
DB_URL = (
f"spanner:///projects/{PROJECT}/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)


def get_db_url():
config = configparser.ConfigParser()
if os.path.exists("test.cfg"):
config.read("test.cfg")
else:
config.read("setup.cfg")
return config.get("db", "default", fallback=DB_URL)


class EscapingTest(_EscapingTest):
@provide_metadata
def test_percent_sign_round_trip(self):
Expand Down Expand Up @@ -678,7 +697,7 @@ def define_temp_tables(cls, metadata):
Column("foo", sqlalchemy.INT),
sqlalchemy.Index("user_tmp_uq", "name", unique=True),
sqlalchemy.Index("user_tmp_ix", "foo"),
**kw
**kw,
)
if (
testing.requires.view_reflection.enabled
Expand Down Expand Up @@ -1508,10 +1527,7 @@ class InterleavedTablesTest(fixtures.TestBase):
"""

def setUp(self):
self._engine = create_engine(
"spanner:///projects/appdev-soda-spanner-staging/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)
self._engine = create_engine(get_db_url())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An argument could be made to make a base test class that sets up the engine and metadata that these other test classes inherit but I don't think it's necessary for this PR

self._metadata = MetaData(bind=self._engine)

def test_interleave(self):
Expand Down Expand Up @@ -1560,10 +1576,7 @@ class UserAgentTest(fixtures.TestBase):
"""Check that SQLAlchemy dialect uses correct user agent."""

def setUp(self):
self._engine = create_engine(
"spanner:///projects/appdev-soda-spanner-staging/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)
self._engine = create_engine(get_db_url())
self._metadata = MetaData(bind=self._engine)

def test_user_agent(self):
Expand All @@ -1583,10 +1596,7 @@ class ExecutionOptionsTest(fixtures.TestBase):
"""

def setUp(self):
self._engine = create_engine(
"spanner:///projects/appdev-soda-spanner-staging/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)
self._engine = create_engine(get_db_url())
self._metadata = MetaData(bind=self._engine)

self._table = Table(
Expand Down