From fcfae9e277b3ca4c7c41d47cb9f5b2e344ee333a Mon Sep 17 00:00:00 2001 From: vam-google Date: Thu, 8 Sep 2022 19:56:26 -0700 Subject: [PATCH] fix: Fix test generation for `*Value` wrapper classes This fixes https://github.com/googleapis/gapic-generator-python/issues/1372 --- .bazelrc | 2 ++ WORKSPACE | 14 ++++++++++++++ .../gapic/%name_%version/%sub/test_%service.py.j2 | 2 +- .../unit/gapic/%name_%version/%sub/test_macros.j2 | 4 ++++ .../unit/gapic/asset_v1/test_asset_service.py | 2 +- .../gapic/credentials_v1/test_iam_credentials.py | 2 +- .../tests/unit/gapic/eventarc_v1/test_eventarc.py | 2 +- .../gapic/logging_v2/test_config_service_v2.py | 2 +- .../gapic/logging_v2/test_logging_service_v2.py | 2 +- .../gapic/logging_v2/test_metrics_service_v2.py | 2 +- .../tests/unit/gapic/redis_v1/test_cloud_redis.py | 2 +- 11 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000000..19ab83c1cd --- /dev/null +++ b/.bazelrc @@ -0,0 +1,2 @@ +# New boringssl requires C++14 +build --repo_env=BAZEL_CXXOPTS="-std=c++14" diff --git a/WORKSPACE b/WORKSPACE index d5239a9aac..3c08a04e7a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -50,6 +50,20 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() +# Import boringssl explicitly to override what gRPC imports as its dependency. +# Boringssl build fails on gcc12 without this fix: +# https://github.com/google/boringssl/commit/8462a367bb57e9524c3d8eca9c62733c63a63cf4, +# which is present only in the newest version of boringssl, not the one imported +# by gRPC. Remove this import once gRPC depends on a newer version. +http_archive( + name = "boringssl", + sha256 = "b460f8673f3393e58ce506e9cdde7f2c3b2575b075f214cb819fb57d809f052b", + strip_prefix = "boringssl-bb41bc007079982da419c0ec3186e510cbcf09d0", + urls = [ + "https://github.com/google/boringssl/archive/bb41bc007079982da419c0ec3186e510cbcf09d0.zip", + ], +) + # # Import grpc as a native bazel dependency. This avoids duplication and also # speeds up loading phase a lot (otherwise python_rules will be building grpcio diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 58ae08c114..40a99150b5 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -21,7 +21,7 @@ import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers {% if 'rest' in opts.transport %} from requests import Response from requests import Request, PreparedRequest diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 index 731482be48..e7be4b42fc 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 @@ -400,6 +400,8 @@ def test_{{ method_name }}_flattened(): assert TimestampRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} {% elif field.ident|string() == 'duration_pb2.Duration' %} assert DurationRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} + {% elif (field.ident|string()).startswith('wrappers_pb2.') %} + assert wrappers.{{ (field.ident|string())[13:] }}Rule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} {% else %} arg = args[0].{{ key }} mock_val = {{ field.mock_value }} @@ -493,6 +495,8 @@ async def test_{{ method_name }}_flattened_async(): assert TimestampRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} {% elif field.ident|string() == 'duration_pb2.Duration' %} assert DurationRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} + {% elif (field.ident|string()).startswith('wrappers_pb2.') %} + assert wrappers.{{ (field.ident|string())[13:] }}Rule().to_proto(args[0].{{ key }}) == {{ field.mock_value }} {% else %} arg = args[0].{{ key }} mock_val = {{ field.mock_value }} diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 44b675b470..4fc860508d 100644 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions diff --git a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index 56311032b9..cc9650d799 100644 --- a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions diff --git a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index 7e74a1ebe3..4b89a35c2a 100644 --- a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index 827611076f..af8c6186c4 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 76a5868192..d7697c4015 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api import monitored_resource_pb2 # type: ignore from google.api_core import client_options diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index dbd281a034..c193ecc27d 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api import distribution_pb2 # type: ignore from google.api import label_pb2 # type: ignore diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index ad48f0866d..d9802ee941 100644 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -26,7 +26,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions