Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
asthamohta committed Aug 10, 2023
1 parent aa9f18c commit 5a0eadc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 129 deletions.
8 changes: 4 additions & 4 deletions google/cloud/spanner_v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class Client(ClientWithProject):
:type directed_read_options: :class:`~googlecloud.spanner_v1.types.DirectedReadOptions`
or :class:`dict`
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
or regions should be used for non-transactional reads or queries.
:raises: :class:`ValueError <exceptions.ValueError>` if both ``read_only``
Expand Down Expand Up @@ -409,8 +409,8 @@ def set_directed_read_options(self, directed_read_options):
"""Sets directed_read_options for the client
:type directed_read_options: :class:`~googlecloud.spanner_v1.types.DirectedReadOptions`
or :class:`dict`
:param directed_read_options: Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
:param directed_read_options: Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
or regions should be used for non-transactional reads or queries.
"""
self._directed_read_options = directed_read_options
14 changes: 9 additions & 5 deletions google/cloud/spanner_v1/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def read(
:type directed_read_options: :class:`~googlecloud.spanner_v1.types.DirectedReadOptions`
or :class:`dict`
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
or regions should be used for non-transactional reads or queries.
:rtype: :class:`~google.cloud.spanner_v1.streamed.StreamedResultSet`
Expand All @@ -239,8 +239,10 @@ def read(
:raises ValueError:
for reuse of single-use snapshots, or if a transaction ID is
already pending for multiple-use snapshots.
:raises InvalidArguement: if directed_read_options is incorrect.
:raises BadRequest: if directed_read_options are set for READ-WRITE Transaction or PDML.
"""
if self._read_request_count > 0:
if not self._multi_use:
Expand Down Expand Up @@ -407,15 +409,17 @@ def execute_sql(
:type directed_read_options: :class:`~googlecloud.spanner_v1.types.DirectedReadOptions`
or :class:`dict`
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
:param directed_read_options: (Optional) Client options used to set the directed_read_options
for all ReadRequests and ExecuteSqlRequests for the Client which indicate which replicas
or regions should be used for non-transactional reads or queries.
:raises ValueError:
for reuse of single-use snapshots, or if a transaction ID is
already pending for multiple-use snapshots.
:raises InvalidArguement: if directed_read_options is incorrect.
:raises BadRequest: if directed_read_options are set for READ-WRITE Transaction or PDML.
"""
if self._read_request_count > 0:
if not self._multi_use:
Expand Down
183 changes: 63 additions & 120 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,65 @@
import unittest
import mock

DIRECTED_READ_INCORRECT_OPTIONS1 = {
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
],
},
"exclude_replicas": {
"replica_selections": [
{
"location": "us-east1",
},
],
},
}
DIRECTED_READ_INCORRECT_OPTIONS2 = {
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
],
},
}


class Test_merge_query_options(unittest.TestCase):
def _callFUT(self, *args, **kw):
Expand Down Expand Up @@ -772,145 +831,29 @@ def _call_fut(self, directed_read_options):
def test_dict_include_exclude_replica_set_error(self):
from google.api_core.exceptions import InvalidArgument

directed_read_options = {
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
],
},
"exclude_replicas": {
"replica_selections": [
{
"location": "us-east1",
},
],
},
}
directed_read_options = DIRECTED_READ_INCORRECT_OPTIONS1
with self.assertRaises(InvalidArgument):
self._call_fut(directed_read_options)

def test_dict_greater_than_ten_replica_selections_error(self):
from google.api_core.exceptions import InvalidArgument

directed_read_options = {
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
],
},
}
directed_read_options = DIRECTED_READ_INCORRECT_OPTIONS2
with self.assertRaises(InvalidArgument):
self._call_fut(directed_read_options)

def test_object_include_exclude_replica_set_error(self):
from google.api_core.exceptions import InvalidArgument
from google.cloud.spanner_v1 import DirectedReadOptions

directed_read_options = DirectedReadOptions(
{
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
],
},
"exclude_replicas": {
"replica_selections": [
{
"location": "us-east1",
},
],
},
}
)
directed_read_options = DirectedReadOptions(DIRECTED_READ_INCORRECT_OPTIONS1)
with self.assertRaises(InvalidArgument):
self._call_fut(directed_read_options)

def test_dict_greater_than_ten_replica_selections_error(self):
from google.api_core.exceptions import InvalidArgument
from google.cloud.spanner_v1 import DirectedReadOptions

directed_read_options = DirectedReadOptions(
{
"include_replicas": {
"replica_selections": [
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
{
"location": "us-west1",
},
],
},
}
)
directed_read_options = DirectedReadOptions(DIRECTED_READ_INCORRECT_OPTIONS2)
with self.assertRaises(InvalidArgument):
self._call_fut(directed_read_options)

0 comments on commit 5a0eadc

Please sign in to comment.