From bd3db5ae1bba8254d336de931fe13755a826dd22 Mon Sep 17 00:00:00 2001 From: Sanjeev Bhatt Date: Wed, 7 Aug 2024 12:33:18 +0530 Subject: [PATCH 1/2] chore(spanner): Issue1180# [Refactoring] Create a copy of samples/samples/testdata in tests * created copy in tests/system and test/unit * updated references --- tests/system/_sample_data.py | 2 +- tests/system/test_session_api.py | 2 +- tests/system/testdata/singer.proto | 17 +++++++++++++++++ tests/system/testdata/singer_pb2.py | 28 ++++++++++++++++++++++++++++ tests/unit/test__helpers.py | 8 ++++---- tests/unit/test_param_types.py | 4 ++-- tests/unit/testdata/singer.proto | 17 +++++++++++++++++ tests/unit/testdata/singer_pb2.py | 28 ++++++++++++++++++++++++++++ 8 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 tests/system/testdata/singer.proto create mode 100644 tests/system/testdata/singer_pb2.py create mode 100644 tests/unit/testdata/singer.proto create mode 100644 tests/unit/testdata/singer_pb2.py diff --git a/tests/system/_sample_data.py b/tests/system/_sample_data.py index 41f41c9fe5..f23110c5dd 100644 --- a/tests/system/_sample_data.py +++ b/tests/system/_sample_data.py @@ -18,7 +18,7 @@ from google.api_core import datetime_helpers from google.cloud._helpers import UTC from google.cloud import spanner_v1 -from samples.samples.testdata import singer_pb2 +from .testdata import singer_pb2 TABLE = "contacts" COLUMNS = ("contact_id", "first_name", "last_name", "email") diff --git a/tests/system/test_session_api.py b/tests/system/test_session_api.py index 00fdf828da..31e38f967a 100644 --- a/tests/system/test_session_api.py +++ b/tests/system/test_session_api.py @@ -29,7 +29,7 @@ from google.cloud.spanner_admin_database_v1 import DatabaseDialect from google.cloud._helpers import UTC from google.cloud.spanner_v1.data_types import JsonObject -from samples.samples.testdata import singer_pb2 +from .testdata import singer_pb2 from tests import _helpers as ot_helpers from . import _helpers from . import _sample_data diff --git a/tests/system/testdata/singer.proto b/tests/system/testdata/singer.proto new file mode 100644 index 0000000000..1a995614a7 --- /dev/null +++ b/tests/system/testdata/singer.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package examples.spanner.music; + +message SingerInfo { + optional int64 singer_id = 1; + optional string birth_date = 2; + optional string nationality = 3; + optional Genre genre = 4; +} + +enum Genre { + POP = 0; + JAZZ = 1; + FOLK = 2; + ROCK = 3; +} diff --git a/tests/system/testdata/singer_pb2.py b/tests/system/testdata/singer_pb2.py new file mode 100644 index 0000000000..286f884163 --- /dev/null +++ b/tests/system/testdata/singer_pb2.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: singer.proto +# Protobuf Python Version: 4.25.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music\"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'singer_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_GENRE']._serialized_start=236 + _globals['_GENRE']._serialized_end=282 + _globals['_SINGERINFO']._serialized_start=41 + _globals['_SINGERINFO']._serialized_end=234 +# @@protoc_insertion_point(module_scope) diff --git a/tests/unit/test__helpers.py b/tests/unit/test__helpers.py index 11adec6ac9..e62bff2a2e 100644 --- a/tests/unit/test__helpers.py +++ b/tests/unit/test__helpers.py @@ -356,7 +356,7 @@ def test_w_json_None(self): def test_w_proto_message(self): from google.protobuf.struct_pb2 import Value import base64 - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 singer_info = singer_pb2.SingerInfo() expected = Value(string_value=base64.b64encode(singer_info.SerializeToString())) @@ -366,7 +366,7 @@ def test_w_proto_message(self): def test_w_proto_enum(self): from google.protobuf.struct_pb2 import Value - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 value_pb = self._callFUT(singer_pb2.Genre.ROCK) self.assertIsInstance(value_pb, Value) @@ -710,7 +710,7 @@ def test_w_proto_message(self): from google.cloud.spanner_v1 import Type from google.cloud.spanner_v1 import TypeCode import base64 - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 VALUE = singer_pb2.SingerInfo() field_type = Type(code=TypeCode.PROTO) @@ -726,7 +726,7 @@ def test_w_proto_enum(self): from google.protobuf.struct_pb2 import Value from google.cloud.spanner_v1 import Type from google.cloud.spanner_v1 import TypeCode - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 VALUE = "ROCK" field_type = Type(code=TypeCode.ENUM) diff --git a/tests/unit/test_param_types.py b/tests/unit/test_param_types.py index a7069543c8..1b0660614a 100644 --- a/tests/unit/test_param_types.py +++ b/tests/unit/test_param_types.py @@ -94,7 +94,7 @@ def test_it(self): from google.cloud.spanner_v1 import Type from google.cloud.spanner_v1 import TypeCode from google.cloud.spanner_v1 import param_types - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 singer_info = singer_pb2.SingerInfo() expected = Type( @@ -111,7 +111,7 @@ def test_it(self): from google.cloud.spanner_v1 import Type from google.cloud.spanner_v1 import TypeCode from google.cloud.spanner_v1 import param_types - from samples.samples.testdata import singer_pb2 + from .testdata import singer_pb2 singer_genre = singer_pb2.Genre expected = Type( diff --git a/tests/unit/testdata/singer.proto b/tests/unit/testdata/singer.proto new file mode 100644 index 0000000000..1a995614a7 --- /dev/null +++ b/tests/unit/testdata/singer.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package examples.spanner.music; + +message SingerInfo { + optional int64 singer_id = 1; + optional string birth_date = 2; + optional string nationality = 3; + optional Genre genre = 4; +} + +enum Genre { + POP = 0; + JAZZ = 1; + FOLK = 2; + ROCK = 3; +} diff --git a/tests/unit/testdata/singer_pb2.py b/tests/unit/testdata/singer_pb2.py new file mode 100644 index 0000000000..286f884163 --- /dev/null +++ b/tests/unit/testdata/singer_pb2.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: singer.proto +# Protobuf Python Version: 4.25.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music\"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'singer_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_GENRE']._serialized_start=236 + _globals['_GENRE']._serialized_end=282 + _globals['_SINGERINFO']._serialized_start=41 + _globals['_SINGERINFO']._serialized_end=234 +# @@protoc_insertion_point(module_scope) From 2bd181097e615670f8f1035b9157d7c80c60141a Mon Sep 17 00:00:00 2001 From: Sanjeev Bhatt Date: Wed, 7 Aug 2024 12:34:59 +0530 Subject: [PATCH 2/2] chore(spanner): Issue1180# [Refactoring] Create a copy of samples/samples/testdata in tests * updated formatting (nox -s blacken) --- tests/system/testdata/singer_pb2.py | 19 ++++++++++--------- tests/unit/testdata/singer_pb2.py | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/system/testdata/singer_pb2.py b/tests/system/testdata/singer_pb2.py index 286f884163..51b049865c 100644 --- a/tests/system/testdata/singer_pb2.py +++ b/tests/system/testdata/singer_pb2.py @@ -7,22 +7,23 @@ from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database from google.protobuf.internal import builder as _builder + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music\"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3' +) _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'singer_pb2', _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "singer_pb2", _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _globals['_GENRE']._serialized_start=236 - _globals['_GENRE']._serialized_end=282 - _globals['_SINGERINFO']._serialized_start=41 - _globals['_SINGERINFO']._serialized_end=234 + DESCRIPTOR._options = None + _globals["_GENRE"]._serialized_start = 236 + _globals["_GENRE"]._serialized_end = 282 + _globals["_SINGERINFO"]._serialized_start = 41 + _globals["_SINGERINFO"]._serialized_end = 234 # @@protoc_insertion_point(module_scope) diff --git a/tests/unit/testdata/singer_pb2.py b/tests/unit/testdata/singer_pb2.py index 286f884163..51b049865c 100644 --- a/tests/unit/testdata/singer_pb2.py +++ b/tests/unit/testdata/singer_pb2.py @@ -7,22 +7,23 @@ from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database from google.protobuf.internal import builder as _builder + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music\"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\n\x0csinger.proto\x12\x16\x65xamples.spanner.music"\xc1\x01\n\nSingerInfo\x12\x16\n\tsinger_id\x18\x01 \x01(\x03H\x00\x88\x01\x01\x12\x17\n\nbirth_date\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bnationality\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x31\n\x05genre\x18\x04 \x01(\x0e\x32\x1d.examples.spanner.music.GenreH\x03\x88\x01\x01\x42\x0c\n\n_singer_idB\r\n\x0b_birth_dateB\x0e\n\x0c_nationalityB\x08\n\x06_genre*.\n\x05Genre\x12\x07\n\x03POP\x10\x00\x12\x08\n\x04JAZZ\x10\x01\x12\x08\n\x04\x46OLK\x10\x02\x12\x08\n\x04ROCK\x10\x03\x62\x06proto3' +) _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'singer_pb2', _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "singer_pb2", _globals) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _globals['_GENRE']._serialized_start=236 - _globals['_GENRE']._serialized_end=282 - _globals['_SINGERINFO']._serialized_start=41 - _globals['_SINGERINFO']._serialized_end=234 + DESCRIPTOR._options = None + _globals["_GENRE"]._serialized_start = 236 + _globals["_GENRE"]._serialized_end = 282 + _globals["_SINGERINFO"]._serialized_start = 41 + _globals["_SINGERINFO"]._serialized_end = 234 # @@protoc_insertion_point(module_scope)