Skip to content
Closed
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@
# limitations under the License.
import logging

from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode
from sqlalchemy import Engine, create_engine
from sqlalchemy.testing.plugin.plugin_base import fixtures
import google.cloud.spanner_v1.types.type as spanner_type
import google.cloud.spanner_v1.types.result_set as result_set
import google.cloud.spanner_v1.types.type as spanner_type
import grpc
from google.api_core.client_options import ClientOptions
from google.auth.credentials import AnonymousCredentials
from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode
from google.cloud.spanner_v1 import (
Client,
ResultSet,
TypeCode,
)
from google.cloud.spanner_v1.database import Database
from google.cloud.spanner_v1.instance import Instance
import grpc
from sqlalchemy import Engine, create_engine
from sqlalchemy.testing.plugin.plugin_base import fixtures
Comment on lines 16 to +30
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The import block is disorganized and does not follow PEP 8 alphabetical sorting. Additionally, NullPool should be imported at the top level rather than locally within a method to improve readability and maintainability.

Suggested change
import google.cloud.spanner_v1.types.result_set as result_set
import google.cloud.spanner_v1.types.type as spanner_type
import grpc
from google.api_core.client_options import ClientOptions
from google.auth.credentials import AnonymousCredentials
from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode
from google.cloud.spanner_v1 import (
Client,
ResultSet,
TypeCode,
)
from google.cloud.spanner_v1.database import Database
from google.cloud.spanner_v1.instance import Instance
import grpc
from sqlalchemy import Engine, create_engine
from sqlalchemy.testing.plugin.plugin_base import fixtures
from google.api_core.client_options import ClientOptions
from google.auth.credentials import AnonymousCredentials
from google.cloud.spanner_dbapi.parsed_statement import AutocommitDmlMode
from google.cloud.spanner_v1 import (
Client,
ResultSet,
TypeCode,
)
from google.cloud.spanner_v1.database import Database
from google.cloud.spanner_v1.instance import Instance
import google.cloud.spanner_v1.types.result_set as result_set
import google.cloud.spanner_v1.types.type as spanner_type
import grpc
from sqlalchemy import Engine, NullPool, create_engine
from sqlalchemy.testing.plugin.plugin_base import fixtures


from tests.mockserver_tests.mock_database_admin import DatabaseAdminServicer

# TODO: Replace this with the mock server in the Spanner client lib
from tests.mockserver_tests.mock_spanner import SpannerServicer, start_mock_server
from tests.mockserver_tests.mock_database_admin import DatabaseAdminServicer


def add_result(sql: str, result: ResultSet):
Expand Down Expand Up @@ -161,9 +162,11 @@ def teardown_method(self):
MockServerTestBase.database_admin_service.clear_requests()

def create_engine(self) -> Engine:
from sqlalchemy.pool import NullPool
return create_engine(
Comment on lines +165 to 166
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Remove the local import of NullPool as it has been moved to the top-level imports.

        return create_engine(

"spanner:///projects/p/instances/i/databases/d",
connect_args={"client": self.client, "logger": MockServerTestBase.logger},
poolclass=NullPool, # Disable pooling to force new sessions for every test
)

@property
Expand Down