diff --git a/docs/spanner/batch-api.rst b/docs/spanner/batch-api.rst index 0d0b927e9654..ecd51b01cdd9 100644 --- a/docs/spanner/batch-api.rst +++ b/docs/spanner/batch-api.rst @@ -1,8 +1,6 @@ Batch API ========= -.. automodule:: google.cloud.spanner.batch +.. automodule:: google.cloud.spanner_v1.batch :members: :show-inheritance: - - diff --git a/docs/spanner/client-api.rst b/docs/spanner/client-api.rst index 0716ee742e3a..3cc5a89b2137 100644 --- a/docs/spanner/client-api.rst +++ b/docs/spanner/client-api.rst @@ -1,7 +1,7 @@ Spanner Client ============== -.. automodule:: google.cloud.spanner.client +.. automodule:: google.cloud.spanner_v1.client :members: :show-inheritance: diff --git a/docs/spanner/database-api.rst b/docs/spanner/database-api.rst index 1eeed674e7d6..f1ce2a6d8e26 100644 --- a/docs/spanner/database-api.rst +++ b/docs/spanner/database-api.rst @@ -1,7 +1,7 @@ Database API ============ -.. automodule:: google.cloud.spanner.database +.. automodule:: google.cloud.spanner_v1.database :members: :show-inheritance: diff --git a/docs/spanner/instance-api.rst b/docs/spanner/instance-api.rst index 181bed686b28..127b4c687372 100644 --- a/docs/spanner/instance-api.rst +++ b/docs/spanner/instance-api.rst @@ -1,7 +1,7 @@ Instance API ============ -.. automodule:: google.cloud.spanner.instance +.. automodule:: google.cloud.spanner_v1.instance :members: :show-inheritance: diff --git a/docs/spanner/keyset-api.rst b/docs/spanner/keyset-api.rst index 3f46c6dc95f6..90137cf87640 100644 --- a/docs/spanner/keyset-api.rst +++ b/docs/spanner/keyset-api.rst @@ -1,7 +1,7 @@ Keyset API ========== -.. automodule:: google.cloud.spanner.keyset +.. automodule:: google.cloud.spanner_v1.keyset :members: :show-inheritance: diff --git a/docs/spanner/session-api.rst b/docs/spanner/session-api.rst index b41c3e6b8c20..1f6d0ac60261 100644 --- a/docs/spanner/session-api.rst +++ b/docs/spanner/session-api.rst @@ -1,7 +1,7 @@ Session API =========== -.. automodule:: google.cloud.spanner.session +.. automodule:: google.cloud.spanner_v1.session :members: :show-inheritance: @@ -9,7 +9,7 @@ Session API Session Pools API ================= -.. automodule:: google.cloud.spanner.pool +.. automodule:: google.cloud.spanner_v1.pool :members: :show-inheritance: diff --git a/docs/spanner/snapshot-api.rst b/docs/spanner/snapshot-api.rst index b28d55a19feb..26b697ae20e5 100644 --- a/docs/spanner/snapshot-api.rst +++ b/docs/spanner/snapshot-api.rst @@ -1,7 +1,7 @@ Snapshot API ============ -.. automodule:: google.cloud.spanner.snapshot +.. automodule:: google.cloud.spanner_v1.snapshot :members: :show-inheritance: diff --git a/docs/spanner/streamed-api.rst b/docs/spanner/streamed-api.rst index e17180accf8b..53bab89ba491 100644 --- a/docs/spanner/streamed-api.rst +++ b/docs/spanner/streamed-api.rst @@ -1,7 +1,7 @@ StreamedResultSet API ===================== -.. automodule:: google.cloud.spanner.streamed +.. automodule:: google.cloud.spanner_v1.streamed :members: :show-inheritance: diff --git a/docs/spanner/transaction-api.rst b/docs/spanner/transaction-api.rst index c16213de54bd..6657676db199 100644 --- a/docs/spanner/transaction-api.rst +++ b/docs/spanner/transaction-api.rst @@ -1,7 +1,7 @@ Transaction API =============== -.. automodule:: google.cloud.spanner.transaction +.. automodule:: google.cloud.spanner_v1.transaction :members: :show-inheritance: diff --git a/spanner/google/cloud/spanner.py b/spanner/google/cloud/spanner.py new file mode 100644 index 000000000000..1c49d22b406a --- /dev/null +++ b/spanner/google/cloud/spanner.py @@ -0,0 +1,42 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Cloud Spanner API package.""" + +from __future__ import absolute_import + +from google.cloud.spanner_v1 import __version__ +from google.cloud.spanner_v1 import AbstractSessionPool +from google.cloud.spanner_v1 import BurstyPool +from google.cloud.spanner_v1 import Client +from google.cloud.spanner_v1 import enums +from google.cloud.spanner_v1 import FixedSizePool +from google.cloud.spanner_v1 import KeyRange +from google.cloud.spanner_v1 import KeySet +from google.cloud.spanner_v1 import param_types +from google.cloud.spanner_v1 import types + + +__all__ = ( + '__version__', + 'AbstractSessionPool', + 'BurstyPool', + 'Client', + 'enums', + 'FixedSizePool', + 'KeyRange', + 'KeySet', + 'param_types', + 'types', +) diff --git a/spanner/google/cloud/spanner/__init__.py b/spanner/google/cloud/spanner/__init__.py deleted file mode 100644 index 244bdb868f9a..000000000000 --- a/spanner/google/cloud/spanner/__init__.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2016 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Cloud Spanner API package.""" - - -import pkg_resources -__version__ = pkg_resources.get_distribution('google-cloud-spanner').version - -from google.cloud.spanner.client import Client - -from google.cloud.spanner.keyset import KeyRange -from google.cloud.spanner.keyset import KeySet - -from google.cloud.spanner.pool import AbstractSessionPool -from google.cloud.spanner.pool import BurstyPool -from google.cloud.spanner.pool import FixedSizePool - -from google.cloud.spanner.types import ArrayParamType -from google.cloud.spanner.types import BOOL_PARAM_TYPE -from google.cloud.spanner.types import BYTES_PARAM_TYPE -from google.cloud.spanner.types import DATE_PARAM_TYPE -from google.cloud.spanner.types import FLOAT64_PARAM_TYPE -from google.cloud.spanner.types import INT64_PARAM_TYPE -from google.cloud.spanner.types import STRING_PARAM_TYPE -from google.cloud.spanner.types import StructField -from google.cloud.spanner.types import StructParamType -from google.cloud.spanner.types import TIMESTAMP_PARAM_TYPE - - -__all__ = [ - '__version__', - 'AbstractSessionPool', - 'ArrayParamType', - 'BOOL_PARAM_TYPE', - 'BYTES_PARAM_TYPE', - 'BurstyPool', - 'Client', - 'DATE_PARAM_TYPE', - 'FLOAT64_PARAM_TYPE', - 'FixedSizePool', - 'INT64_PARAM_TYPE', - 'KeyRange', - 'KeySet', - 'STRING_PARAM_TYPE', - 'StructField', - 'StructParamType', - 'TIMESTAMP_PARAM_TYPE', -] diff --git a/spanner/google/cloud/spanner_v1/__init__.py b/spanner/google/cloud/spanner_v1/__init__.py index 732ad4de3b21..9a41ff872a84 100644 --- a/spanner/google/cloud/spanner_v1/__init__.py +++ b/spanner/google/cloud/spanner_v1/__init__.py @@ -14,17 +14,38 @@ from __future__ import absolute_import +import pkg_resources +__version__ = pkg_resources.get_distribution('google-cloud-spanner').version + +from google.cloud.spanner_v1 import param_types from google.cloud.spanner_v1 import types +from google.cloud.spanner_v1.client import Client from google.cloud.spanner_v1.gapic import enums -from google.cloud.spanner_v1.gapic import spanner_client +from google.cloud.spanner_v1.keyset import KeyRange +from google.cloud.spanner_v1.keyset import KeySet +from google.cloud.spanner_v1.pool import AbstractSessionPool +from google.cloud.spanner_v1.pool import BurstyPool +from google.cloud.spanner_v1.pool import FixedSizePool -class SpannerClient(spanner_client.SpannerClient): - __doc__ = spanner_client.SpannerClient.__doc__ - enums = enums +__all__ = ( + # google.cloud.spanner_v1 + '__version__', + 'param_types', + 'types', + # google.cloud.spanner_v1.client + 'Client', -__all__ = ( + # google.cloud.spanner_v1.keyset + 'KeyRange', + 'KeySet', + + # google.cloud.spanner_v1.pool + 'AbstractSessionPool', + 'BurstyPool', + 'FixedSizePool', + + # google.cloud.spanner_v1.gapic 'enums', - 'types', - 'SpannerClient', ) +) diff --git a/spanner/google/cloud/spanner/_helpers.py b/spanner/google/cloud/spanner_v1/_helpers.py similarity index 99% rename from spanner/google/cloud/spanner/_helpers.py rename to spanner/google/cloud/spanner_v1/_helpers.py index 1ec019dd7737..362a042e9ef8 100644 --- a/spanner/google/cloud/spanner/_helpers.py +++ b/spanner/google/cloud/spanner_v1/_helpers.py @@ -251,7 +251,7 @@ def _parse_list_value_pbs(rows, row_type): class _SessionWrapper(object): """Base class for objects wrapping a session. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session used to perform the commit """ def __init__(self, session): diff --git a/spanner/google/cloud/spanner/batch.py b/spanner/google/cloud/spanner_v1/batch.py similarity index 94% rename from spanner/google/cloud/spanner/batch.py rename to spanner/google/cloud/spanner_v1/batch.py index 7ce25d99a0ac..f8faa873edaa 100644 --- a/spanner/google/cloud/spanner/batch.py +++ b/spanner/google/cloud/spanner_v1/batch.py @@ -19,16 +19,16 @@ # pylint: disable=ungrouped-imports from google.cloud._helpers import _pb_timestamp_to_datetime -from google.cloud.spanner._helpers import _SessionWrapper -from google.cloud.spanner._helpers import _make_list_value_pbs -from google.cloud.spanner._helpers import _options_with_prefix +from google.cloud.spanner_v1._helpers import _SessionWrapper +from google.cloud.spanner_v1._helpers import _make_list_value_pbs +from google.cloud.spanner_v1._helpers import _options_with_prefix # pylint: enable=ungrouped-imports class _BatchBase(_SessionWrapper): """Accumulate mutations for transmission during :meth:`commit`. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session used to perform the commit """ def __init__(self, session): @@ -111,7 +111,7 @@ def delete(self, table, keyset): :type table: str :param table: Name of the table to be modified. - :type keyset: :class:`~google.cloud.spanner.keyset.Keyset` + :type keyset: :class:`~google.cloud.spanner_v1.keyset.Keyset` :param keyset: Keys/ranges identifying rows to delete. """ delete = Mutation.Delete( diff --git a/spanner/google/cloud/spanner/client.py b/spanner/google/cloud/spanner_v1/client.py similarity index 92% rename from spanner/google/cloud/spanner/client.py rename to spanner/google/cloud/spanner_v1/client.py index 61cac4197f74..f0cc1ea6e9cd 100644 --- a/spanner/google/cloud/spanner/client.py +++ b/spanner/google/cloud/spanner_v1/client.py @@ -18,10 +18,10 @@ In the hierarchy of API concepts -* a :class:`~google.cloud.spanner.client.Client` owns an - :class:`~google.cloud.spanner.instance.Instance` -* a :class:`~google.cloud.spanner.instance.Instance` owns a - :class:`~google.cloud.spanner.database.Database` +* a :class:`~google.cloud.spanner_v1.client.Client` owns an + :class:`~google.cloud.spanner_v1.instance.Instance` +* a :class:`~google.cloud.spanner_v1.instance.Instance` owns a + :class:`~google.cloud.spanner_v1.database.Database` """ from google.api.core import page_iterator @@ -35,10 +35,10 @@ from google.cloud._http import DEFAULT_USER_AGENT from google.cloud.client import ClientWithProject -from google.cloud.spanner import __version__ -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner.instance import DEFAULT_NODE_COUNT -from google.cloud.spanner.instance import Instance +from google.cloud.spanner_v1 import __version__ +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1.instance import DEFAULT_NODE_COUNT +from google.cloud.spanner_v1.instance import Instance SPANNER_ADMIN_SCOPE = 'https://www.googleapis.com/auth/spanner.admin' @@ -197,7 +197,7 @@ def list_instance_configs(self, page_size=None, page_token=None): :rtype: :class:`~google.api.core.page_iterator.Iterator` :returns: Iterator of - :class:`~google.cloud.spanner.instance.InstanceConfig` + :class:`~google.cloud.spanner_v1.instance.InstanceConfig` resources within the client's project. """ if page_token is None: @@ -236,7 +236,7 @@ def instance(self, instance_id, :param node_count: (Optional) The number of nodes in the instance's cluster; used to set up the instance's cluster. - :rtype: :class:`~google.cloud.spanner.instance.Instance` + :rtype: :class:`~google.cloud.spanner_v1.instance.Instance` :returns: an instance owned by this client. """ return Instance( @@ -260,7 +260,7 @@ def list_instances(self, filter_='', page_size=None, page_token=None): :rtype: :class:`~google.api.core.page_iterator.Iterator` :returns: - Iterator of :class:`~google.cloud.spanner.instance.Instance` + Iterator of :class:`~google.cloud.spanner_v1.instance.Instance` resources within the client's project. """ if page_token is None: @@ -285,7 +285,7 @@ def _item_to_instance_config( :class:`~google.spanner.admin.instance.v1.InstanceConfig` :param config_pb: An instance config returned from the API. - :rtype: :class:`~google.cloud.spanner.instance.InstanceConfig` + :rtype: :class:`~google.cloud.spanner_v1.instance.InstanceConfig` :returns: The next instance config in the page. """ return InstanceConfig.from_pb(config_pb) @@ -300,7 +300,7 @@ def _item_to_instance(iterator, instance_pb): :type instance_pb: :class:`~google.spanner.admin.instance.v1.Instance` :param instance_pb: An instance returned from the API. - :rtype: :class:`~google.cloud.spanner.instance.Instance` + :rtype: :class:`~google.cloud.spanner_v1.instance.Instance` :returns: The next instance in the page. """ return Instance.from_pb(instance_pb, iterator.client) diff --git a/spanner/google/cloud/spanner/database.py b/spanner/google/cloud/spanner_v1/database.py similarity index 93% rename from spanner/google/cloud/spanner/database.py rename to spanner/google/cloud/spanner_v1/database.py index abf0b3a1579c..0b708094fdb3 100644 --- a/spanner/google/cloud/spanner/database.py +++ b/spanner/google/cloud/spanner_v1/database.py @@ -27,13 +27,13 @@ # pylint: disable=ungrouped-imports from google.cloud.exceptions import Conflict from google.cloud.exceptions import NotFound -from google.cloud.spanner import __version__ -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner.batch import Batch -from google.cloud.spanner.session import Session -from google.cloud.spanner.pool import BurstyPool -from google.cloud.spanner.snapshot import Snapshot -from google.cloud.spanner.pool import SessionCheckout +from google.cloud.spanner_v1 import __version__ +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1.batch import Batch +from google.cloud.spanner_v1.pool import BurstyPool +from google.cloud.spanner_v1.pool import SessionCheckout +from google.cloud.spanner_v1.session import Session +from google.cloud.spanner_v1.snapshot import Snapshot # pylint: enable=ungrouped-imports @@ -60,7 +60,7 @@ class Database(object): :type database_id: str :param database_id: The ID of the database. - :type instance: :class:`~google.cloud.spanner.instance.Instance` + :type instance: :class:`~google.cloud.spanner_v1.instance.Instance` :param instance: The instance that owns the database. :type ddl_statements: list of string @@ -68,10 +68,10 @@ class Database(object): CREATE DATABASE statement. :type pool: concrete subclass of - :class:`~google.cloud.spanner.pool.AbstractSessionPool`. + :class:`~google.cloud.spanner_v1.pool.AbstractSessionPool`. :param pool: (Optional) session pool to be used by database. If not passed, the database will construct an instance of - :class:`~google.cloud.spanner.pool.BurstyPool`. + :class:`~google.cloud.spanner_v1.pool.BurstyPool`. """ _spanner_api = None @@ -96,11 +96,11 @@ def from_pb(cls, database_pb, instance, pool=None): :class:`google.spanner.v2.spanner_instance_admin_pb2.Instance` :param database_pb: A instance protobuf object. - :type instance: :class:`~google.cloud.spanner.instance.Instance` + :type instance: :class:`~google.cloud.spanner_v1.instance.Instance` :param instance: The instance that owns the database. :type pool: concrete subclass of - :class:`~google.cloud.spanner.pool.AbstractSessionPool`. + :class:`~google.cloud.spanner_v1.pool.AbstractSessionPool`. :param pool: (Optional) session pool to be used by database. :rtype: :class:`Database` @@ -310,7 +310,7 @@ def drop(self): def session(self): """Factory to create a session for this database. - :rtype: :class:`~google.cloud.spanner.session.Session` + :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: a session bound to this database. """ return Session(self) @@ -327,9 +327,9 @@ def snapshot(self, **kw): :type kw: dict :param kw: Passed through to - :class:`~google.cloud.spanner.snapshot.Snapshot` constructor. + :class:`~google.cloud.spanner_v1.snapshot.Snapshot` constructor. - :rtype: :class:`~google.cloud.spanner.database.SnapshotCheckout` + :rtype: :class:`~google.cloud.spanner_v1.database.SnapshotCheckout` :returns: new wrapper """ return SnapshotCheckout(self, **kw) @@ -340,7 +340,7 @@ def batch(self): The wrapper *must* be used as a context manager, with the batch as the value returned by the wrapper. - :rtype: :class:`~google.cloud.spanner.database.BatchCheckout` + :rtype: :class:`~google.cloud.spanner_v1.database.BatchCheckout` :returns: new wrapper """ return BatchCheckout(self) @@ -426,7 +426,7 @@ class SnapshotCheckout(object): :type kw: dict :param kw: Passed through to - :class:`~google.cloud.spanner.snapshot.Snapshot` constructor. + :class:`~google.cloud.spanner_v1.snapshot.Snapshot` constructor. """ def __init__(self, database, **kw): self._database = database diff --git a/spanner/google/cloud/spanner/instance.py b/spanner/google/cloud/spanner_v1/instance.py similarity index 95% rename from spanner/google/cloud/spanner/instance.py rename to spanner/google/cloud/spanner_v1/instance.py index bd1a6ac0982a..f43e201db475 100644 --- a/spanner/google/cloud/spanner/instance.py +++ b/spanner/google/cloud/spanner_v1/instance.py @@ -28,9 +28,9 @@ # pylint: disable=ungrouped-imports from google.cloud.exceptions import Conflict from google.cloud.exceptions import NotFound -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner.database import Database -from google.cloud.spanner.pool import BurstyPool +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1.database import Database +from google.cloud.spanner_v1.pool import BurstyPool # pylint: enable=ungrouped-imports @@ -54,7 +54,7 @@ class Instance(object): :type instance_id: str :param instance_id: The ID of the instance. - :type client: :class:`~google.cloud.spanner.client.Client` + :type client: :class:`~google.cloud.spanner_v1.client.Client` :param client: The client that owns the instance. Provides authorization and a project ID. @@ -104,7 +104,7 @@ def from_pb(cls, instance_pb, client): :class:`google.spanner.v2.spanner_instance_admin_pb2.Instance` :param instance_pb: A instance protobuf object. - :type client: :class:`~google.cloud.spanner.client.Client` + :type client: :class:`~google.cloud.spanner_v1.client.Client` :param client: The client that owns the instance. :rtype: :class:`Instance` @@ -167,7 +167,7 @@ def copy(self): Copies the local data stored as simple types and copies the client attached to this instance. - :rtype: :class:`~google.cloud.spanner.instance.Instance` + :rtype: :class:`~google.cloud.spanner_v1.instance.Instance` :returns: A copy of the current instance. """ new_client = self._client.copy() @@ -353,10 +353,10 @@ def database(self, database_id, ddl_statements=(), pool=None): 'CREATE DATABSE' statement. :type pool: concrete subclass of - :class:`~google.cloud.spanner.pool.AbstractSessionPool`. + :class:`~google.cloud.spanner_v1.pool.AbstractSessionPool`. :param pool: (Optional) session pool to be used by database. - :rtype: :class:`~google.cloud.spanner.database.Database` + :rtype: :class:`~google.cloud.spanner_v1.database.Database` :returns: a database owned by this instance. """ return Database( @@ -376,7 +376,7 @@ def list_databases(self, page_size=None, page_token=None): :rtype: :class:`~google.api.core.page_iterator.Iterator` :returns: - Iterator of :class:`~google.cloud.spanner.database.Database` + Iterator of :class:`~google.cloud.spanner_v1.database.Database` resources within the current instance. """ if page_token is None: @@ -399,7 +399,7 @@ def _item_to_database(iterator, database_pb): :type database_pb: :class:`~google.spanner.admin.database.v1.Database` :param database_pb: A database returned from the API. - :rtype: :class:`~google.cloud.spanner.database.Database` + :rtype: :class:`~google.cloud.spanner_v1.database.Database` :returns: The next database in the page. """ return Database.from_pb(database_pb, iterator.instance, pool=BurstyPool()) diff --git a/spanner/google/cloud/spanner/keyset.py b/spanner/google/cloud/spanner_v1/keyset.py similarity index 96% rename from spanner/google/cloud/spanner/keyset.py rename to spanner/google/cloud/spanner_v1/keyset.py index 89e95fc26d89..43e41d0d27b4 100644 --- a/spanner/google/cloud/spanner/keyset.py +++ b/spanner/google/cloud/spanner_v1/keyset.py @@ -17,8 +17,8 @@ from google.cloud.spanner_v1.proto.keys_pb2 import KeyRange as KeyRangePB from google.cloud.spanner_v1.proto.keys_pb2 import KeySet as KeySetPB -from google.cloud.spanner._helpers import _make_list_value_pb -from google.cloud.spanner._helpers import _make_list_value_pbs +from google.cloud.spanner_v1._helpers import _make_list_value_pb +from google.cloud.spanner_v1._helpers import _make_list_value_pbs class KeyRange(object): diff --git a/spanner/google/cloud/spanner/types.py b/spanner/google/cloud/spanner_v1/param_types.py similarity index 73% rename from spanner/google/cloud/spanner/types.py rename to spanner/google/cloud/spanner_v1/param_types.py index 2930940ef143..0e7869e01a78 100644 --- a/spanner/google/cloud/spanner/types.py +++ b/spanner/google/cloud/spanner_v1/param_types.py @@ -17,17 +17,17 @@ from google.cloud.spanner_v1.proto import type_pb2 -# Scalar paramter types -STRING_PARAM_TYPE = type_pb2.Type(code=type_pb2.STRING) -BYTES_PARAM_TYPE = type_pb2.Type(code=type_pb2.BYTES) -BOOL_PARAM_TYPE = type_pb2.Type(code=type_pb2.BOOL) -INT64_PARAM_TYPE = type_pb2.Type(code=type_pb2.INT64) -FLOAT64_PARAM_TYPE = type_pb2.Type(code=type_pb2.FLOAT64) -DATE_PARAM_TYPE = type_pb2.Type(code=type_pb2.DATE) -TIMESTAMP_PARAM_TYPE = type_pb2.Type(code=type_pb2.TIMESTAMP) +# Scalar parameter types +STRING = type_pb2.Type(code=type_pb2.STRING) +BYTES = type_pb2.Type(code=type_pb2.BYTES) +BOOE = type_pb2.Type(code=type_pb2.BOOL) +INT64 = type_pb2.Type(code=type_pb2.INT64) +FLOAT64 = type_pb2.Type(code=type_pb2.FLOAT64) +DATE = type_pb2.Type(code=type_pb2.DATE) +TIMESTAMP = type_pb2.Type(code=type_pb2.TIMESTAMP) -def ArrayParamType(element_type): # pylint: disable=invalid-name +def Array(element_type): # pylint: disable=invalid-name """Construct an array paramter type description protobuf. :type element_type: :class:`type_pb2.Type` @@ -49,12 +49,12 @@ def StructField(name, field_type): # pylint: disable=invalid-name :param field_type: the type of the field :rtype: :class:`type_pb2.StructType.Field` - :returns: the appropriate array-type protobuf + :returns: the appropriate struct-field-type protobuf """ return type_pb2.StructType.Field(name=name, type=field_type) -def StructParamType(fields): # pylint: disable=invalid-name +def Struct(fields): # pylint: disable=invalid-name """Construct a struct paramter type description protobuf. :type fields: list of :class:`type_pb2.StructType.Field` @@ -65,4 +65,5 @@ def StructParamType(fields): # pylint: disable=invalid-name """ return type_pb2.Type( code=type_pb2.STRUCT, - struct_type=type_pb2.StructType(fields=fields)) + struct_type=type_pb2.StructType(fields=fields), + ) diff --git a/spanner/google/cloud/spanner/pool.py b/spanner/google/cloud/spanner_v1/pool.py similarity index 92% rename from spanner/google/cloud/spanner/pool.py rename to spanner/google/cloud/spanner_v1/pool.py index a0c1a49104df..9998426ee60b 100644 --- a/spanner/google/cloud/spanner/pool.py +++ b/spanner/google/cloud/spanner_v1/pool.py @@ -33,7 +33,7 @@ class AbstractSessionPool(object): def bind(self, database): """Associate the pool with a database. - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. @@ -58,7 +58,7 @@ def get(self): def put(self, session): """Return a session to the pool. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session being returned. Concrete implementations of this method are allowed to raise an @@ -87,7 +87,7 @@ def session(self, **kwargs): :param kwargs: (optional) keyword arguments, passed through to the returned checkout. - :rtype: :class:`~google.cloud.spanner.session.SessionCheckout` + :rtype: :class:`~google.cloud.spanner_v1.session.SessionCheckout` :returns: a checkout instance, to be used as a context manager for accessing the session and returning it to the pool. """ @@ -127,7 +127,7 @@ def __init__(self, size=DEFAULT_SIZE, default_timeout=DEFAULT_TIMEOUT): def bind(self, database): """Associate the pool with a database. - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. """ @@ -144,7 +144,7 @@ def get(self, timeout=None): # pylint: disable=arguments-differ :type timeout: int :param timeout: seconds to block waiting for an available session - :rtype: :class:`~google.cloud.spanner.session.Session` + :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: an existing session from the pool, or a newly-created session. :raises: :exc:`six.moves.queue.Empty` if the queue is empty. @@ -165,7 +165,7 @@ def put(self, session): Never blocks: if the pool is full, raises. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session being returned. :raises: :exc:`six.moves.queue.Full` if the queue is full. @@ -208,7 +208,7 @@ def __init__(self, target_size=10): def bind(self, database): """Associate the pool with a database. - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. """ @@ -217,7 +217,7 @@ def bind(self, database): def get(self): """Check a session out from the pool. - :rtype: :class:`~google.cloud.spanner.session.Session` + :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: an existing session from the pool, or a newly-created session. """ @@ -238,7 +238,7 @@ def put(self, session): Never blocks: if the pool is full, the returned session is discarded. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session being returned. """ try: @@ -301,7 +301,7 @@ def __init__(self, size=10, default_timeout=10, ping_interval=3000): def bind(self, database): """Associate the pool with a database. - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. """ @@ -318,7 +318,7 @@ def get(self, timeout=None): # pylint: disable=arguments-differ :type timeout: int :param timeout: seconds to block waiting for an available session - :rtype: :class:`~google.cloud.spanner.session.Session` + :rtype: :class:`~google.cloud.spanner_v1.session.Session` :returns: an existing session from the pool, or a newly-created session. :raises: :exc:`six.moves.queue.Empty` if the queue is empty. @@ -340,7 +340,7 @@ def put(self, session): Never blocks: if the pool is full, raises. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session being returned. :raises: :exc:`six.moves.queue.Full` if the queue is full. @@ -413,7 +413,7 @@ def __init__(self, size=10, default_timeout=10, ping_interval=3000): def bind(self, database): """Associate the pool with a database. - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. """ @@ -425,7 +425,7 @@ def put(self, session): Never blocks: if the pool is full, raises. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session being returned. :raises: :exc:`six.moves.queue.Full` if the queue is full. @@ -452,7 +452,7 @@ class SessionCheckout(object): """Context manager: hold session checked out from a pool. :type pool: concrete subclass of - :class:`~google.cloud.spanner.session.AbstractSessionPool` + :class:`~google.cloud.spanner_v1.session.AbstractSessionPool` :param pool: Pool from which to check out a session. :type kwargs: dict diff --git a/spanner/google/cloud/spanner/session.py b/spanner/google/cloud/spanner_v1/session.py similarity index 93% rename from spanner/google/cloud/spanner/session.py rename to spanner/google/cloud/spanner_v1/session.py index 94fd0f092366..103fb4aafae5 100644 --- a/spanner/google/cloud/spanner/session.py +++ b/spanner/google/cloud/spanner_v1/session.py @@ -25,10 +25,10 @@ # pylint: disable=ungrouped-imports from google.cloud.exceptions import NotFound from google.cloud.exceptions import GrpcRendezvous -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner.batch import Batch -from google.cloud.spanner.snapshot import Snapshot -from google.cloud.spanner.transaction import Transaction +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1.batch import Batch +from google.cloud.spanner_v1.snapshot import Snapshot +from google.cloud.spanner_v1.transaction import Transaction # pylint: enable=ungrouped-imports @@ -46,7 +46,7 @@ class Session(object): * Use :meth:`exists` to check for the existence of the session * :meth:`drop` the session - :type database: :class:`~google.cloud.spanner.database.Database` + :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: The database to which the session is bound. """ @@ -154,9 +154,9 @@ def snapshot(self, **kw): :type kw: dict :param kw: Passed through to - :class:`~google.cloud.spanner.snapshot.Snapshot` ctor. + :class:`~google.cloud.spanner_v1.snapshot.Snapshot` ctor. - :rtype: :class:`~google.cloud.spanner.snapshot.Snapshot` + :rtype: :class:`~google.cloud.spanner_v1.snapshot.Snapshot` :returns: a snapshot bound to this session :raises ValueError: if the session has not yet been created. """ @@ -174,7 +174,7 @@ def read(self, table, columns, keyset, index='', limit=0): :type columns: list of str :param columns: names of columns to be retrieved - :type keyset: :class:`~google.cloud.spanner.keyset.KeySet` + :type keyset: :class:`~google.cloud.spanner_v1.keyset.KeySet` :param keyset: keys / ranges identifying rows to be retrieved :type index: str @@ -184,7 +184,7 @@ def read(self, table, columns, keyset, index='', limit=0): :type limit: int :param limit: (Optional) maxiumn number of rows to return - :rtype: :class:`~google.cloud.spanner.streamed.StreamedResultSet` + :rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet` :returns: a result set instance which can be used to consume rows. """ return self.snapshot().read(table, columns, keyset, index, limit) @@ -210,7 +210,7 @@ def execute_sql(self, sql, params=None, param_types=None, query_mode=None): :param query_mode: Mode governing return of results / query plan. See https://cloud.google.com/spanner/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest.QueryMode1 - :rtype: :class:`~google.cloud.spanner.streamed.StreamedResultSet` + :rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet` :returns: a result set instance which can be used to consume rows. """ return self.snapshot().execute_sql( @@ -219,7 +219,7 @@ def execute_sql(self, sql, params=None, param_types=None, query_mode=None): def batch(self): """Factory to create a batch for this session. - :rtype: :class:`~google.cloud.spanner.batch.Batch` + :rtype: :class:`~google.cloud.spanner_v1.batch.Batch` :returns: a batch bound to this session :raises ValueError: if the session has not yet been created. """ @@ -231,7 +231,7 @@ def batch(self): def transaction(self): """Create a transaction to perform a set of reads with shared staleness. - :rtype: :class:`~google.cloud.spanner.transaction.Transaction` + :rtype: :class:`~google.cloud.spanner_v1.transaction.Transaction` :returns: a transaction bound to this session :raises ValueError: if the session has not yet been created. """ diff --git a/spanner/google/cloud/spanner/snapshot.py b/spanner/google/cloud/spanner_v1/snapshot.py similarity index 94% rename from spanner/google/cloud/spanner/snapshot.py rename to spanner/google/cloud/spanner_v1/snapshot.py index 3fcb386a2b10..8f2a8ca8d9d4 100644 --- a/spanner/google/cloud/spanner/snapshot.py +++ b/spanner/google/cloud/spanner_v1/snapshot.py @@ -23,10 +23,10 @@ from google.api.core.exceptions import ServiceUnavailable from google.cloud._helpers import _datetime_to_pb_timestamp from google.cloud._helpers import _timedelta_to_duration_pb -from google.cloud.spanner._helpers import _make_value_pb -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner._helpers import _SessionWrapper -from google.cloud.spanner.streamed import StreamedResultSet +from google.cloud.spanner_v1._helpers import _make_value_pb +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1._helpers import _SessionWrapper +from google.cloud.spanner_v1.streamed import StreamedResultSet def _restart_on_unavailable(restart): @@ -64,7 +64,7 @@ class _SnapshotBase(_SessionWrapper): Allows reuse of API request methods with different transaction selector. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session used to perform the commit """ _multi_use = False @@ -91,7 +91,7 @@ def read(self, table, columns, keyset, index='', limit=0): :type columns: list of str :param columns: names of columns to be retrieved - :type keyset: :class:`~google.cloud.spanner.keyset.KeySet` + :type keyset: :class:`~google.cloud.spanner_v1.keyset.KeySet` :param keyset: keys / ranges identifying rows to be retrieved :type index: str @@ -101,7 +101,7 @@ def read(self, table, columns, keyset, index='', limit=0): :type limit: int :param limit: (Optional) maxiumn number of rows to return - :rtype: :class:`~google.cloud.spanner.streamed.StreamedResultSet` + :rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet` :returns: a result set instance which can be used to consume rows. :raises ValueError: for reuse of single-use snapshots, or if a transaction ID is @@ -153,7 +153,7 @@ def execute_sql(self, sql, params=None, param_types=None, query_mode=None): :param query_mode: Mode governing return of results / query plan. See https://cloud.google.com/spanner/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest.QueryMode1 - :rtype: :class:`~google.cloud.spanner.streamed.StreamedResultSet` + :rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet` :returns: a result set instance which can be used to consume rows. :raises ValueError: for reuse of single-use snapshots, or if a transaction ID is @@ -204,7 +204,7 @@ class Snapshot(_SnapshotBase): If no options are passed, reads will use the ``strong`` model, reading at a timestamp where all previously committed transactions are visible. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session used to perform the commit. :type read_timestamp: :class:`datetime.datetime` diff --git a/spanner/google/cloud/spanner/streamed.py b/spanner/google/cloud/spanner_v1/streamed.py similarity index 98% rename from spanner/google/cloud/spanner/streamed.py rename to spanner/google/cloud/spanner_v1/streamed.py index adb2399de884..4e989e29cb72 100644 --- a/spanner/google/cloud/spanner/streamed.py +++ b/spanner/google/cloud/spanner_v1/streamed.py @@ -21,7 +21,7 @@ import six # pylint: disable=ungrouped-imports -from google.cloud.spanner._helpers import _parse_value_pb +from google.cloud.spanner_v1._helpers import _parse_value_pb # pylint: enable=ungrouped-imports @@ -34,7 +34,7 @@ class StreamedResultSet(object): :class:`google.cloud.spanner_v1.proto.result_set_pb2.PartialResultSet` instances. - :type source: :class:`~google.cloud.spanner.snapshot.Snapshot` + :type source: :class:`~google.cloud.spanner_v1.snapshot.Snapshot` :param source: Snapshot from which the result set was fetched. """ def __init__(self, response_iterator, source=None): diff --git a/spanner/google/cloud/spanner/transaction.py b/spanner/google/cloud/spanner_v1/transaction.py similarity index 95% rename from spanner/google/cloud/spanner/transaction.py rename to spanner/google/cloud/spanner_v1/transaction.py index c6a8e639dce7..1f260293f2ef 100644 --- a/spanner/google/cloud/spanner/transaction.py +++ b/spanner/google/cloud/spanner_v1/transaction.py @@ -18,15 +18,15 @@ from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionOptions from google.cloud._helpers import _pb_timestamp_to_datetime -from google.cloud.spanner._helpers import _options_with_prefix -from google.cloud.spanner.snapshot import _SnapshotBase -from google.cloud.spanner.batch import _BatchBase +from google.cloud.spanner_v1._helpers import _options_with_prefix +from google.cloud.spanner_v1.snapshot import _SnapshotBase +from google.cloud.spanner_v1.batch import _BatchBase class Transaction(_SnapshotBase, _BatchBase): """Implement read-write transaction semantics for a session. - :type session: :class:`~google.cloud.spanner.session.Session` + :type session: :class:`~google.cloud.spanner_v1.session.Session` :param session: the session used to perform the commit :raises ValueError: if session has an existing transaction diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index 2393fd82b608..26ee0ee34aac 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -33,11 +33,11 @@ from google.cloud._helpers import UTC from google.cloud.exceptions import GrpcRendezvous -from google.cloud.spanner._helpers import TimestampWithNanoseconds -from google.cloud.spanner.client import Client -from google.cloud.spanner.keyset import KeyRange -from google.cloud.spanner.keyset import KeySet -from google.cloud.spanner.pool import BurstyPool +from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds +from google.cloud.spanner import Client +from google.cloud.spanner import KeyRange +from google.cloud.spanner import KeySet +from google.cloud.spanner import BurstyPool from test_utils.retry import RetryErrors from test_utils.retry import RetryInstanceState diff --git a/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py b/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py index fac97a7fe8e5..5d012ce0fe55 100644 --- a/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py +++ b/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py @@ -18,7 +18,13 @@ from google.gax import errors -from google.cloud import spanner_v1 +# ----------------------------------------------------------------------------- +# Manual change to the GAPIC unit tests because we do not export +# the `SpannerClient` at the usual location because there is a thick wrapper +# around it. +from google.cloud.spanner_v1.gapic import spanner_client as spanner_v1 +# ----------------------------------------------------------------------------- + from google.cloud.spanner_v1.proto import keys_pb2 from google.cloud.spanner_v1.proto import result_set_pb2 from google.cloud.spanner_v1.proto import spanner_pb2 diff --git a/spanner/tests/unit/test__helpers.py b/spanner/tests/unit/test__helpers.py index 78e710d9697d..421852163241 100644 --- a/spanner/tests/unit/test__helpers.py +++ b/spanner/tests/unit/test__helpers.py @@ -19,7 +19,7 @@ class TestTimestampWithNanoseconds(unittest.TestCase): def _get_target_class(self): - from google.cloud.spanner._helpers import TimestampWithNanoseconds + from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds return TimestampWithNanoseconds @@ -114,7 +114,7 @@ def test_from_rfc3339_w_full_precision(self): class Test_make_value_pb(unittest.TestCase): def _callFUT(self, *args, **kw): - from google.cloud.spanner._helpers import _make_value_pb + from google.cloud.spanner_v1._helpers import _make_value_pb return _make_value_pb(*args, **kw) @@ -211,7 +211,7 @@ def test_w_date(self): def test_w_timestamp_w_nanos(self): from google.protobuf.struct_pb2 import Value from google.cloud._helpers import UTC - from google.cloud.spanner._helpers import TimestampWithNanoseconds + from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds when = TimestampWithNanoseconds( 2016, 12, 20, 21, 13, 47, nanosecond=123456789, tzinfo=UTC) @@ -237,7 +237,7 @@ def test_w_unknown_type(self): class Test_make_list_value_pb(unittest.TestCase): def _callFUT(self, *args, **kw): - from google.cloud.spanner._helpers import _make_list_value_pb + from google.cloud.spanner_v1._helpers import _make_list_value_pb return _make_list_value_pb(*args, **kw) @@ -272,7 +272,7 @@ def test_w_multiple_values(self): class Test_make_list_value_pbs(unittest.TestCase): def _callFUT(self, *args, **kw): - from google.cloud.spanner._helpers import _make_list_value_pbs + from google.cloud.spanner_v1._helpers import _make_list_value_pbs return _make_list_value_pbs(*args, **kw) @@ -307,7 +307,7 @@ def test_w_multiple_values(self): class Test_parse_value_pb(unittest.TestCase): def _callFUT(self, *args, **kw): - from google.cloud.spanner._helpers import _parse_value_pb + from google.cloud.spanner_v1._helpers import _parse_value_pb return _parse_value_pb(*args, **kw) @@ -385,7 +385,7 @@ def test_w_timestamp_wo_nanos(self): from google.protobuf.struct_pb2 import Value from google.cloud.spanner_v1.proto.type_pb2 import Type, TIMESTAMP from google.cloud._helpers import UTC, _datetime_to_rfc3339 - from google.cloud.spanner._helpers import TimestampWithNanoseconds + from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds VALUE = TimestampWithNanoseconds( 2016, 12, 20, 21, 13, 47, microsecond=123456, tzinfo=UTC) @@ -400,7 +400,7 @@ def test_w_timestamp_w_nanos(self): from google.protobuf.struct_pb2 import Value from google.cloud.spanner_v1.proto.type_pb2 import Type, TIMESTAMP from google.cloud._helpers import UTC, _datetime_to_rfc3339 - from google.cloud.spanner._helpers import TimestampWithNanoseconds + from google.cloud.spanner_v1._helpers import TimestampWithNanoseconds VALUE = TimestampWithNanoseconds( 2016, 12, 20, 21, 13, 47, nanosecond=123456789, tzinfo=UTC) @@ -437,7 +437,7 @@ def test_w_struct(self): from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType from google.cloud.spanner_v1.proto.type_pb2 import ( STRUCT, STRING, INT64) - from google.cloud.spanner._helpers import _make_list_value_pb + from google.cloud.spanner_v1._helpers import _make_list_value_pb VALUES = [u'phred', 32] struct_type_pb = StructType(fields=[ @@ -465,7 +465,7 @@ def test_w_unknown_type(self): class Test_parse_list_value_pbs(unittest.TestCase): def _callFUT(self, *args, **kw): - from google.cloud.spanner._helpers import _parse_list_value_pbs + from google.cloud.spanner_v1._helpers import _parse_list_value_pbs return _parse_list_value_pbs(*args, **kw) @@ -483,7 +483,7 @@ def test_empty(self): def test_non_empty(self): from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 - from google.cloud.spanner._helpers import _make_list_value_pbs + from google.cloud.spanner_v1._helpers import _make_list_value_pbs VALUES = [ [u'phred', 32], @@ -502,7 +502,7 @@ def test_non_empty(self): class Test_SessionWrapper(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner._helpers import _SessionWrapper + from google.cloud.spanner_v1._helpers import _SessionWrapper return _SessionWrapper @@ -518,7 +518,7 @@ def test_ctor(self): class Test_options_with_prefix(unittest.TestCase): def _call_fut(self, *args, **kw): - from google.cloud.spanner._helpers import _options_with_prefix + from google.cloud.spanner_v1._helpers import _options_with_prefix return _options_with_prefix(*args, **kw) diff --git a/spanner/tests/unit/test_batch.py b/spanner/tests/unit/test_batch.py index 0d8257bc5b8b..a6f2e7346e17 100644 --- a/spanner/tests/unit/test_batch.py +++ b/spanner/tests/unit/test_batch.py @@ -43,7 +43,7 @@ def _make_one(self, *args, **kwargs): class Test_BatchBase(_BaseTest): def _getTargetClass(self): - from google.cloud.spanner.batch import _BatchBase + from google.cloud.spanner_v1.batch import _BatchBase return _BatchBase @@ -144,7 +144,7 @@ def test_replace(self): def test_delete(self): from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet keys = [[0], [1], [2]] keyset = KeySet(keys=keys) @@ -170,7 +170,7 @@ def test_delete(self): class TestBatch(_BaseTest): def _getTargetClass(self): - from google.cloud.spanner.batch import Batch + from google.cloud.spanner_v1.batch import Batch return Batch @@ -180,7 +180,7 @@ def test_ctor(self): self.assertIs(batch._session, session) def test_commit_already_committed(self): - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet keys = [[0], [1], [2]] keyset = KeySet(keys=keys) @@ -199,7 +199,7 @@ def test_commit_grpc_error(self): TransactionOptions) from google.cloud.spanner_v1.proto.mutation_pb2 import ( Mutation as MutationPB) - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet keys = [[0], [1], [2]] keyset = KeySet(keys=keys) diff --git a/spanner/tests/unit/test_client.py b/spanner/tests/unit/test_client.py index 1173b2ba5fcb..1020985657e1 100644 --- a/spanner/tests/unit/test_client.py +++ b/spanner/tests/unit/test_client.py @@ -42,9 +42,9 @@ class TestClient(unittest.TestCase): USER_AGENT = 'you-sir-age-int' def _get_target_class(self): - from google.cloud.spanner.client import Client + from google.cloud import spanner - return Client + return spanner.Client def _make_one(self, *args, **kwargs): return self._get_target_class()(*args, **kwargs) @@ -52,7 +52,7 @@ def _make_one(self, *args, **kwargs): def _constructor_test_helper(self, expected_scopes, creds, user_agent=None, expected_creds=None): - from google.cloud.spanner import client as MUT + from google.cloud.spanner_v1 import client as MUT user_agent = user_agent or MUT.DEFAULT_USER_AGENT client = self._make_one(project=self.PROJECT, credentials=creds, @@ -69,7 +69,7 @@ def _constructor_test_helper(self, expected_scopes, creds, self.assertEqual(client.user_agent, user_agent) def test_constructor_default_scopes(self): - from google.cloud.spanner import client as MUT + from google.cloud.spanner_v1 import client as MUT expected_scopes = ( MUT.SPANNER_ADMIN_SCOPE, @@ -78,7 +78,7 @@ def test_constructor_default_scopes(self): self._constructor_test_helper(expected_scopes, creds) def test_constructor_custom_user_agent_and_timeout(self): - from google.cloud.spanner import client as MUT + from google.cloud.spanner_v1 import client as MUT CUSTOM_USER_AGENT = 'custom-application' expected_scopes = ( @@ -106,7 +106,7 @@ def test_constructor_credentials_wo_create_scoped(self): self._constructor_test_helper(expected_scopes, creds) def test_admin_api_lib_name(self): - from google.cloud.spanner import __version__ + from google.cloud.spanner_v1 import __version__ from google.cloud.spanner_admin_database_v1 import gapic as db from google.cloud.spanner_admin_instance_v1 import gapic as inst @@ -145,16 +145,15 @@ def test_admin_api_lib_name(self): __version__) def test_instance_admin_api(self): - from google.cloud.spanner import __version__ - from google.cloud.spanner.client import SPANNER_ADMIN_SCOPE + from google.cloud.spanner_v1 import __version__ + from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) expected_scopes = (SPANNER_ADMIN_SCOPE,) - patch = mock.patch('google.cloud.spanner.client.InstanceAdminClient') - - with patch as instance_admin_client: + inst_module = 'google.cloud.spanner_v1.client.InstanceAdminClient' + with mock.patch(inst_module) as instance_admin_client: api = client.instance_admin_api self.assertIs(api, instance_admin_client.return_value) @@ -171,16 +170,15 @@ def test_instance_admin_api(self): credentials.with_scopes.assert_called_once_with(expected_scopes) def test_database_admin_api(self): - from google.cloud.spanner import __version__ - from google.cloud.spanner.client import SPANNER_ADMIN_SCOPE + from google.cloud.spanner_v1 import __version__ + from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) expected_scopes = (SPANNER_ADMIN_SCOPE,) - patch = mock.patch('google.cloud.spanner.client.DatabaseAdminClient') - - with patch as database_admin_client: + db_module = 'google.cloud.spanner_v1.client.DatabaseAdminClient' + with mock.patch(db_module) as database_admin_client: api = client.database_admin_api self.assertIs(api, database_admin_client.return_value) @@ -225,7 +223,7 @@ def test_project_name_property(self): def test_list_instance_configs_wo_paging(self): from google.cloud._testing import _GAXPageIterator from google.gax import INITIAL_PAGE - from google.cloud.spanner.client import InstanceConfig + from google.cloud.spanner_v1.client import InstanceConfig credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) @@ -255,7 +253,7 @@ def test_list_instance_configs_wo_paging(self): def test_list_instance_configs_w_paging(self): from google.cloud._testing import _GAXPageIterator - from google.cloud.spanner.client import InstanceConfig + from google.cloud.spanner_v1.client import InstanceConfig SIZE = 15 TOKEN_RETURNED = 'TOKEN_RETURNED' @@ -290,8 +288,8 @@ def test_list_instance_configs_w_paging(self): [('google-cloud-resource-prefix', client.project_name)]) def test_instance_factory_defaults(self): - from google.cloud.spanner.instance import DEFAULT_NODE_COUNT - from google.cloud.spanner.instance import Instance + from google.cloud.spanner_v1.instance import DEFAULT_NODE_COUNT + from google.cloud.spanner_v1.instance import Instance credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) @@ -306,7 +304,7 @@ def test_instance_factory_defaults(self): self.assertIs(instance._client, client) def test_instance_factory_explicit(self): - from google.cloud.spanner.instance import Instance + from google.cloud.spanner_v1.instance import Instance credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) @@ -325,7 +323,7 @@ def test_instance_factory_explicit(self): def test_list_instances_wo_paging(self): from google.cloud._testing import _GAXPageIterator from google.gax import INITIAL_PAGE - from google.cloud.spanner.instance import Instance + from google.cloud.spanner_v1.instance import Instance credentials = _make_credentials() client = self._make_one(project=self.PROJECT, credentials=credentials) @@ -360,7 +358,7 @@ def test_list_instances_wo_paging(self): def test_list_instances_w_paging(self): from google.cloud._testing import _GAXPageIterator - from google.cloud.spanner.instance import Instance + from google.cloud.spanner_v1.instance import Instance SIZE = 15 TOKEN_RETURNED = 'TOKEN_RETURNED' diff --git a/spanner/tests/unit/test_database.py b/spanner/tests/unit/test_database.py index f520ba85da98..49e9b4a4c36e 100644 --- a/spanner/tests/unit/test_database.py +++ b/spanner/tests/unit/test_database.py @@ -19,7 +19,7 @@ from google.cloud._testing import _GAXBaseAPI -from google.cloud.spanner import __version__ +from google.cloud.spanner_v1 import __version__ def _make_credentials(): # pragma: NO COVER @@ -51,12 +51,12 @@ def _make_one(self, *args, **kwargs): class TestDatabase(_BaseTest): def _getTargetClass(self): - from google.cloud.spanner.database import Database + from google.cloud.spanner_v1.database import Database return Database def test_ctor_defaults(self): - from google.cloud.spanner.pool import BurstyPool + from google.cloud.spanner_v1.pool import BurstyPool instance = _Instance(self.INSTANCE_NAME) @@ -163,7 +163,7 @@ def test_from_pb_success_w_explicit_pool(self): def test_from_pb_success_w_hyphen_w_default_pool(self): from google.cloud.spanner_admin_database_v1.proto import ( spanner_database_admin_pb2 as admin_v1_pb2) - from google.cloud.spanner.pool import BurstyPool + from google.cloud.spanner_v1.pool import BurstyPool DATABASE_ID_HYPHEN = 'database-id' DATABASE_NAME_HYPHEN = ( @@ -196,7 +196,7 @@ def test_spanner_api_property_w_scopeless_creds(self): pool = _Pool() database = self._make_one(self.DATABASE_ID, instance, pool=pool) - patch = mock.patch('google.cloud.spanner.database.SpannerClient') + patch = mock.patch('google.cloud.spanner_v1.database.SpannerClient') with patch as spanner_client: api = database.spanner_api @@ -214,7 +214,7 @@ def test_spanner_api_property_w_scopeless_creds(self): def test_spanner_api_w_scoped_creds(self): import google.auth.credentials - from google.cloud.spanner.database import SPANNER_DATA_SCOPE + from google.cloud.spanner_v1.database import SPANNER_DATA_SCOPE class _CredentialsWithScopes( google.auth.credentials.Scoped): @@ -236,7 +236,7 @@ def with_scopes(self, scopes): pool = _Pool() database = self._make_one(self.DATABASE_ID, instance, pool=pool) - patch = mock.patch('google.cloud.spanner.database.SpannerClient') + patch = mock.patch('google.cloud.spanner_v1.database.SpannerClient') with patch as spanner_client: api = database.spanner_api @@ -608,7 +608,7 @@ def test_drop_success(self): [('google-cloud-resource-prefix', database.name)]) def test_session_factory(self): - from google.cloud.spanner.session import Session + from google.cloud.spanner_v1.session import Session client = _Client() instance = _Instance(self.INSTANCE_NAME, client=client) @@ -622,7 +622,7 @@ def test_session_factory(self): self.assertIs(session._database, database) def test_snapshot_defaults(self): - from google.cloud.spanner.database import SnapshotCheckout + from google.cloud.spanner_v1.database import SnapshotCheckout client = _Client() instance = _Instance(self.INSTANCE_NAME, client=client) @@ -639,7 +639,7 @@ def test_snapshot_defaults(self): def test_snapshot_w_read_timestamp_and_multi_use(self): import datetime from google.cloud._helpers import UTC - from google.cloud.spanner.database import SnapshotCheckout + from google.cloud.spanner_v1.database import SnapshotCheckout now = datetime.datetime.utcnow().replace(tzinfo=UTC) client = _Client() @@ -657,7 +657,7 @@ def test_snapshot_w_read_timestamp_and_multi_use(self): checkout._kw, {'read_timestamp': now, 'multi_use': True}) def test_batch(self): - from google.cloud.spanner.database import BatchCheckout + from google.cloud.spanner_v1.database import BatchCheckout client = _Client() instance = _Instance(self.INSTANCE_NAME, client=client) @@ -739,7 +739,7 @@ def nested_unit_of_work(): class TestBatchCheckout(_BaseTest): def _getTargetClass(self): - from google.cloud.spanner.database import BatchCheckout + from google.cloud.spanner_v1.database import BatchCheckout return BatchCheckout @@ -755,7 +755,7 @@ def test_context_mgr_success(self): TransactionOptions) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.batch import Batch + from google.cloud.spanner_v1.batch import Batch now = datetime.datetime.utcnow().replace(tzinfo=UTC) now_pb = _datetime_to_pb_timestamp(now) @@ -785,7 +785,7 @@ def test_context_mgr_success(self): [('google-cloud-resource-prefix', database.name)]) def test_context_mgr_failure(self): - from google.cloud.spanner.batch import Batch + from google.cloud.spanner_v1.batch import Batch database = _Database(self.DATABASE_NAME) pool = database._pool = _Pool() @@ -810,12 +810,12 @@ class Testing(Exception): class TestSnapshotCheckout(_BaseTest): def _getTargetClass(self): - from google.cloud.spanner.database import SnapshotCheckout + from google.cloud.spanner_v1.database import SnapshotCheckout return SnapshotCheckout def test_ctor_defaults(self): - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot database = _Database(self.DATABASE_NAME) session = _Session(database) @@ -838,7 +838,7 @@ def test_ctor_defaults(self): def test_ctor_w_read_timestamp_and_multi_use(self): import datetime from google.cloud._helpers import UTC - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot now = datetime.datetime.utcnow().replace(tzinfo=UTC) database = _Database(self.DATABASE_NAME) @@ -861,7 +861,7 @@ def test_ctor_w_read_timestamp_and_multi_use(self): self.assertIs(pool._session, session) def test_context_mgr_failure(self): - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot database = _Database(self.DATABASE_NAME) pool = database._pool = _Pool() diff --git a/spanner/tests/unit/test_instance.py b/spanner/tests/unit/test_instance.py index 1c05219c6383..57c535969177 100644 --- a/spanner/tests/unit/test_instance.py +++ b/spanner/tests/unit/test_instance.py @@ -37,7 +37,7 @@ class TestInstance(unittest.TestCase): DATABASE_NAME = '%s/databases/%s' % (INSTANCE_NAME, DATABASE_ID) def _getTargetClass(self): - from google.cloud.spanner.instance import Instance + from google.cloud.spanner_v1.instance import Instance return Instance @@ -45,7 +45,7 @@ def _make_one(self, *args, **kwargs): return self._getTargetClass()(*args, **kwargs) def test_constructor_defaults(self): - from google.cloud.spanner.instance import DEFAULT_NODE_COUNT + from google.cloud.spanner_v1.instance import DEFAULT_NODE_COUNT client = object() instance = self._make_one(self.INSTANCE_ID, client) @@ -365,7 +365,7 @@ def test_reload_success(self): def test_update_grpc_error(self): from google.gax.errors import GaxError - from google.cloud.spanner.instance import DEFAULT_NODE_COUNT + from google.cloud.spanner_v1.instance import DEFAULT_NODE_COUNT client = _Client(self.PROJECT) api = client.instance_admin_api = _FauxInstanceAdminAPI( @@ -388,7 +388,7 @@ def test_update_grpc_error(self): def test_update_not_found(self): from google.cloud.exceptions import NotFound - from google.cloud.spanner.instance import DEFAULT_NODE_COUNT + from google.cloud.spanner_v1.instance import DEFAULT_NODE_COUNT client = _Client(self.PROJECT) api = client.instance_admin_api = _FauxInstanceAdminAPI( @@ -481,8 +481,8 @@ def test_delete_success(self): [('google-cloud-resource-prefix', instance.name)]) def test_database_factory_defaults(self): - from google.cloud.spanner.database import Database - from google.cloud.spanner.pool import BurstyPool + from google.cloud.spanner_v1.database import Database + from google.cloud.spanner_v1.pool import BurstyPool client = _Client(self.PROJECT) instance = self._make_one(self.INSTANCE_ID, client, self.CONFIG_NAME) @@ -499,7 +499,7 @@ def test_database_factory_defaults(self): self.assertIs(pool._database, database) def test_database_factory_explicit(self): - from google.cloud.spanner.database import Database + from google.cloud.spanner_v1.database import Database from tests._fixtures import DDL_STATEMENTS client = _Client(self.PROJECT) @@ -520,7 +520,7 @@ def test_database_factory_explicit(self): def test_list_databases_wo_paging(self): from google.cloud._testing import _GAXPageIterator from google.gax import INITIAL_PAGE - from google.cloud.spanner.database import Database + from google.cloud.spanner_v1.database import Database NEXT_TOKEN = 'TOKEN' database_pb = _DatabasePB(name=self.DATABASE_NAME) @@ -549,7 +549,7 @@ def test_list_databases_wo_paging(self): def test_list_databases_w_paging(self): from google.cloud._testing import _GAXPageIterator - from google.cloud.spanner.database import Database + from google.cloud.spanner_v1.database import Database SIZE = 15 TOKEN = 'TOKEN' diff --git a/spanner/tests/unit/test_keyset.py b/spanner/tests/unit/test_keyset.py index 80ae245c774b..800c0cf2cdd2 100644 --- a/spanner/tests/unit/test_keyset.py +++ b/spanner/tests/unit/test_keyset.py @@ -19,7 +19,7 @@ class TestKeyRange(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.keyset import KeyRange + from google.cloud.spanner_v1.keyset import KeyRange return KeyRange @@ -123,7 +123,7 @@ def test_to_pb_w_start_open_and_end_closed(self): class TestKeySet(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet return KeySet @@ -147,7 +147,7 @@ def test_ctor_w_keys(self): self.assertEqual(keyset.ranges, []) def test_ctor_w_ranges(self): - from google.cloud.spanner.keyset import KeyRange + from google.cloud.spanner_v1.keyset import KeyRange range_1 = KeyRange(start_closed=[u'key1'], end_open=[u'key3']) range_2 = KeyRange(start_open=[u'key5'], end_closed=[u'key6']) @@ -164,7 +164,7 @@ def test_ctor_w_all_and_keys(self): self._make_one(all_=True, keys=[['key1'], ['key2']]) def test_ctor_w_all_and_ranges(self): - from google.cloud.spanner.keyset import KeyRange + from google.cloud.spanner_v1.keyset import KeyRange range_1 = KeyRange(start_closed=[u'key1'], end_open=[u'key3']) range_2 = KeyRange(start_open=[u'key5'], end_closed=[u'key6']) @@ -204,7 +204,7 @@ def test_to_pb_w_only_keys(self): def test_to_pb_w_only_ranges(self): from google.cloud.spanner_v1.proto.keys_pb2 import KeySet - from google.cloud.spanner.keyset import KeyRange + from google.cloud.spanner_v1.keyset import KeyRange KEY_1 = u'KEY_1' KEY_2 = u'KEY_2' diff --git a/spanner/tests/unit/test_types.py b/spanner/tests/unit/test_param_types.py similarity index 65% rename from spanner/tests/unit/test_types.py rename to spanner/tests/unit/test_param_types.py index e6566441d4f6..bb1f02247416 100644 --- a/spanner/tests/unit/test_types.py +++ b/spanner/tests/unit/test_param_types.py @@ -20,14 +20,14 @@ class Test_ArrayParamType(unittest.TestCase): def test_it(self): from google.cloud.spanner_v1.proto import type_pb2 - from google.cloud.spanner.types import ArrayParamType - from google.cloud.spanner.types import INT64_PARAM_TYPE + from google.cloud.spanner_v1 import param_types expected = type_pb2.Type( code=type_pb2.ARRAY, - array_element_type=type_pb2.Type(code=type_pb2.INT64)) + array_element_type=type_pb2.Type(code=type_pb2.INT64), + ) - found = ArrayParamType(INT64_PARAM_TYPE) + found = param_types.Array(param_types.INT64) self.assertEqual(found, expected) @@ -36,26 +36,26 @@ class Test_Struct(unittest.TestCase): def test_it(self): from google.cloud.spanner_v1.proto import type_pb2 - from google.cloud.spanner.types import INT64_PARAM_TYPE - from google.cloud.spanner.types import STRING_PARAM_TYPE - from google.cloud.spanner.types import StructParamType - from google.cloud.spanner.types import StructField + from google.cloud.spanner_v1 import param_types struct_type = type_pb2.StructType(fields=[ type_pb2.StructType.Field( name='name', - type=type_pb2.Type(code=type_pb2.STRING)), + type=type_pb2.Type(code=type_pb2.STRING), + ), type_pb2.StructType.Field( name='count', - type=type_pb2.Type(code=type_pb2.INT64)), + type=type_pb2.Type(code=type_pb2.INT64), + ), ]) expected = type_pb2.Type( code=type_pb2.STRUCT, - struct_type=struct_type) + struct_type=struct_type, + ) - found = StructParamType([ - StructField('name', STRING_PARAM_TYPE), - StructField('count', INT64_PARAM_TYPE), + found = param_types.Struct([ + param_types.StructField('name', param_types.STRING), + param_types.StructField('count', param_types.INT64), ]) self.assertEqual(found, expected) diff --git a/spanner/tests/unit/test_pool.py b/spanner/tests/unit/test_pool.py index e4124dcf6b99..9334a5495493 100644 --- a/spanner/tests/unit/test_pool.py +++ b/spanner/tests/unit/test_pool.py @@ -20,7 +20,7 @@ class TestAbstractSessionPool(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import AbstractSessionPool + from google.cloud.spanner_v1.pool import AbstractSessionPool return AbstractSessionPool @@ -54,7 +54,7 @@ def test_clear_abstract(self): pool.clear() def test_session_wo_kwargs(self): - from google.cloud.spanner.pool import SessionCheckout + from google.cloud.spanner_v1.pool import SessionCheckout pool = self._make_one() checkout = pool.session() @@ -64,7 +64,7 @@ def test_session_wo_kwargs(self): self.assertEqual(checkout._kwargs, {}) def test_session_w_kwargs(self): - from google.cloud.spanner.pool import SessionCheckout + from google.cloud.spanner_v1.pool import SessionCheckout pool = self._make_one() checkout = pool.session(foo='bar') @@ -77,7 +77,7 @@ def test_session_w_kwargs(self): class TestFixedSizePool(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import FixedSizePool + from google.cloud.spanner_v1.pool import FixedSizePool return FixedSizePool @@ -210,7 +210,7 @@ def test_clear(self): class TestBurstyPool(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import BurstyPool + from google.cloud.spanner_v1.pool import BurstyPool return BurstyPool @@ -326,7 +326,7 @@ def test_clear(self): class TestPingingPool(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import PingingPool + from google.cloud.spanner_v1.pool import PingingPool return PingingPool @@ -382,7 +382,7 @@ def test_get_hit_no_ping(self): def test_get_hit_w_ping(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT pool = self._make_one(size=4) database = _Database('name') @@ -404,7 +404,7 @@ def test_get_hit_w_ping(self): def test_get_hit_w_ping_expired(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT pool = self._make_one(size=4) database = _Database('name') @@ -464,7 +464,7 @@ def test_put_full(self): def test_put_non_full(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT pool = self._make_one(size=1) queue = pool._sessions = _Queue() @@ -515,7 +515,7 @@ def test_ping_oldest_fresh(self): def test_ping_oldest_stale_but_exists(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT pool = self._make_one(size=1) database = _Database('name') @@ -532,7 +532,7 @@ def test_ping_oldest_stale_but_exists(self): def test_ping_oldest_stale_and_not_exists(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT pool = self._make_one(size=1) database = _Database('name') @@ -552,7 +552,7 @@ def test_ping_oldest_stale_and_not_exists(self): class TestTransactionPingingPool(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import TransactionPingingPool + from google.cloud.spanner_v1.pool import TransactionPingingPool return TransactionPingingPool @@ -601,7 +601,7 @@ def test_bind(self): def test_bind_w_timestamp_race(self): import datetime from google.cloud._testing import _Monkey - from google.cloud.spanner import pool as MUT + from google.cloud.spanner_v1 import pool as MUT NOW = datetime.datetime.utcnow() pool = self._make_one() database = _Database('name') @@ -715,7 +715,7 @@ def test_begin_pending_transactions_non_empty(self): class TestSessionCheckout(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.pool import SessionCheckout + from google.cloud.spanner_v1.pool import SessionCheckout return SessionCheckout diff --git a/spanner/tests/unit/test_session.py b/spanner/tests/unit/test_session.py index 6c23a072c915..51fe7c03783f 100644 --- a/spanner/tests/unit/test_session.py +++ b/spanner/tests/unit/test_session.py @@ -29,7 +29,7 @@ class TestSession(unittest.TestCase): SESSION_NAME = DATABASE_NAME + '/sessions/' + SESSION_ID def _getTargetClass(self): - from google.cloud.spanner.session import Session + from google.cloud.spanner_v1.session import Session return Session @@ -214,7 +214,7 @@ def test_snapshot_not_created(self): session.snapshot() def test_snapshot_created(self): - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot database = _Database(self.DATABASE_NAME) session = self._make_one(database) @@ -228,7 +228,7 @@ def test_snapshot_created(self): self.assertFalse(snapshot._multi_use) def test_snapshot_created_w_multi_use(self): - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot database = _Database(self.DATABASE_NAME) session = self._make_one(database) @@ -242,7 +242,7 @@ def test_snapshot_created_w_multi_use(self): self.assertTrue(snapshot._multi_use) def test_read_not_created(self): - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -255,9 +255,9 @@ def test_read_not_created(self): session.read(TABLE_NAME, COLUMNS, KEYSET) def test_read(self): - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -308,7 +308,7 @@ def test_execute_sql_not_created(self): session.execute_sql(SQL) def test_execute_sql_defaults(self): - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey SQL = 'SELECT first_name, age FROM citizens' @@ -353,7 +353,7 @@ def test_batch_not_created(self): session.batch() def test_batch_created(self): - from google.cloud.spanner.batch import Batch + from google.cloud.spanner_v1.batch import Batch database = _Database(self.DATABASE_NAME) session = self._make_one(database) @@ -372,7 +372,7 @@ def test_transaction_not_created(self): session.transaction() def test_transaction_created(self): - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction database = _Database(self.DATABASE_NAME) session = self._make_one(database) @@ -397,7 +397,7 @@ def test_transaction_w_existing_txn(self): def test_retry_transaction_w_commit_error_txn_already_begun(self): from google.gax.errors import GaxError - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -434,7 +434,7 @@ def unit_of_work(txn, *args, **kw): def test_run_in_transaction_callback_raises_abort(self): from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -481,7 +481,7 @@ def test_run_in_transaction_w_args_w_kwargs_wo_abort(self): Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -528,7 +528,7 @@ def test_run_in_transaction_w_abort_no_retry_metadata(self): Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] @@ -575,8 +575,8 @@ def test_run_in_transaction_w_abort_w_retry_metadata(self): Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.transaction import Transaction - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1.transaction import Transaction + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey TABLE_NAME = 'citizens' @@ -636,8 +636,8 @@ def test_run_in_transaction_w_callback_raises_abort_wo_metadata(self): Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.transaction import Transaction - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1.transaction import Transaction + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey TABLE_NAME = 'citizens' @@ -702,8 +702,8 @@ def test_run_in_transaction_w_abort_w_retry_metadata_deadline(self): Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp - from google.cloud.spanner.transaction import Transaction - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1.transaction import Transaction + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey TABLE_NAME = 'citizens' @@ -754,14 +754,14 @@ def unit_of_work(txn, *args, **kw): self.assertEqual(kw, {'some_arg': 'def'}) def test_run_in_transaction_w_timeout(self): - from google.cloud.spanner import session as MUT + from google.cloud.spanner_v1 import session as MUT from google.cloud._testing import _Monkey from google.gax.errors import GaxError from google.gax.grpc import exc_to_code from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from grpc import StatusCode - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction TABLE_NAME = 'citizens' COLUMNS = ['email', 'first_name', 'last_name', 'age'] diff --git a/spanner/tests/unit/test_snapshot.py b/spanner/tests/unit/test_snapshot.py index 16e07bc3fc70..6403a3e0f228 100644 --- a/spanner/tests/unit/test_snapshot.py +++ b/spanner/tests/unit/test_snapshot.py @@ -36,7 +36,7 @@ class Test_restart_on_unavailable(unittest.TestCase): def _call_fut(self, restart): - from google.cloud.spanner.snapshot import _restart_on_unavailable + from google.cloud.spanner_v1.snapshot import _restart_on_unavailable return _restart_on_unavailable(restart) @@ -123,7 +123,7 @@ class Test_SnapshotBase(unittest.TestCase): SESSION_NAME = DATABASE_NAME + '/sessions/' + SESSION_ID def _getTargetClass(self): - from google.cloud.spanner.snapshot import _SnapshotBase + from google.cloud.spanner_v1.snapshot import _SnapshotBase return _SnapshotBase @@ -166,7 +166,7 @@ def test_read_grpc_error(self): from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionSelector) from google.gax.errors import GaxError - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet KEYSET = KeySet(all_=True) database = _Database() @@ -201,8 +201,8 @@ def _read_helper(self, multi_use, first=True, count=0): TransactionSelector) from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 - from google.cloud.spanner.keyset import KeySet - from google.cloud.spanner._helpers import _make_value_pb + from google.cloud.spanner_v1.keyset import KeySet + from google.cloud.spanner_v1._helpers import _make_value_pb TXN_ID = b'DEADBEEF' VALUES = [ @@ -343,7 +343,7 @@ def _execute_sql_helper(self, multi_use, first=True, count=0): TransactionSelector) from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 - from google.cloud.spanner._helpers import _make_value_pb + from google.cloud.spanner_v1._helpers import _make_value_pb TXN_ID = b'DEADBEEF' VALUES = [ @@ -453,7 +453,7 @@ class TestSnapshot(unittest.TestCase): TRANSACTION_ID = b'DEADBEEF' def _getTargetClass(self): - from google.cloud.spanner.snapshot import Snapshot + from google.cloud.spanner_v1.snapshot import Snapshot return Snapshot def _make_one(self, *args, **kwargs): diff --git a/spanner/tests/unit/test_streamed.py b/spanner/tests/unit/test_streamed.py index 48cc91f7e508..4ab5dbc18d48 100644 --- a/spanner/tests/unit/test_streamed.py +++ b/spanner/tests/unit/test_streamed.py @@ -21,7 +21,7 @@ class TestStreamedResultSet(unittest.TestCase): def _getTargetClass(self): - from google.cloud.spanner.streamed import StreamedResultSet + from google.cloud.spanner_v1.streamed import StreamedResultSet return StreamedResultSet @@ -85,7 +85,7 @@ def _make_struct_type(struct_type_fields): @staticmethod def _make_value(value): - from google.cloud.spanner._helpers import _make_value_pb + from google.cloud.spanner_v1._helpers import _make_value_pb return _make_value_pb(value) @@ -93,7 +93,7 @@ def _make_value(value): def _make_list_value(values=(), value_pbs=None): from google.protobuf.struct_pb2 import ListValue from google.protobuf.struct_pb2 import Value - from google.cloud.spanner._helpers import _make_list_value_pb + from google.cloud.spanner_v1._helpers import _make_list_value_pb if value_pbs is not None: return Value(list_value=ListValue(values=value_pbs)) @@ -115,7 +115,7 @@ def _make_result_set_stats(query_plan=None, **kw): from google.cloud.spanner_v1.proto.result_set_pb2 import ( ResultSetStats) from google.protobuf.struct_pb2 import Struct - from google.cloud.spanner._helpers import _make_value_pb + from google.cloud.spanner_v1._helpers import _make_value_pb query_stats = Struct(fields={ key: _make_value_pb(value) for key, value in kw.items()}) @@ -150,7 +150,7 @@ def test_properties_set(self): self.assertIs(streamed.stats, stats) def test__merge_chunk_bool(self): - from google.cloud.spanner.streamed import Unmergeable + from google.cloud.spanner_v1.streamed import Unmergeable iterator = _MockCancellableIterator() streamed = self._make_one(iterator) @@ -205,7 +205,7 @@ def test__merge_chunk_float64_w_empty(self): self.assertEqual(merged.number_value, 3.14159) def test__merge_chunk_float64_w_float64(self): - from google.cloud.spanner.streamed import Unmergeable + from google.cloud.spanner_v1.streamed import Unmergeable iterator = _MockCancellableIterator() streamed = self._make_one(iterator) @@ -910,7 +910,7 @@ class TestStreamedResultSet_JSON_acceptance_tests(unittest.TestCase): _json_tests = None def _getTargetClass(self): - from google.cloud.spanner.streamed import StreamedResultSet + from google.cloud.spanner_v1.streamed import StreamedResultSet return StreamedResultSet diff --git a/spanner/tests/unit/test_transaction.py b/spanner/tests/unit/test_transaction.py index db37324c4e5f..8fe13b3de2c7 100644 --- a/spanner/tests/unit/test_transaction.py +++ b/spanner/tests/unit/test_transaction.py @@ -38,7 +38,7 @@ class TestTransaction(unittest.TestCase): TRANSACTION_ID = b'DEADBEEF' def _getTargetClass(self): - from google.cloud.spanner.transaction import Transaction + from google.cloud.spanner_v1.transaction import Transaction return Transaction @@ -280,7 +280,7 @@ def test_commit_w_gax_error(self): def test_commit_ok(self): import datetime from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse - from google.cloud.spanner.keyset import KeySet + from google.cloud.spanner_v1.keyset import KeySet from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp