Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/google-api-core/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
branch = True

[report]
fail_under = 99
fail_under = 100
show_missing = True
omit =
tests/*
*/tests/*
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
if they are not already set.
"""

from typing import Union
import uuid
from typing import Union

import google.protobuf.message

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from google.api_core.gapic_v1.requests import setup_request_id


# --- Mock Request Helper Classes ---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,52 @@ def test_cancel_operation():

def test_operations_client_config():
assert operations_client_config.config["interfaces"]


def test_operations_v1_transport_base_to_dict_protobuf_versions(monkeypatch):
from google.auth import credentials as ga_credentials
from google.longrunning import operations_pb2

from google.api_core.operations_v1.transports import base

message = operations_pb2.Operation(name="test_op")
transport = base.OperationsTransport(
credentials=ga_credentials.AnonymousCredentials()
)

calls = []

def mock_message_to_dict(*args, **kwargs):
calls.append(kwargs)
return {"name": "test_op"}

monkeypatch.setattr(base.json_format, "MessageToDict", mock_message_to_dict)

monkeypatch.setattr(base, "PROTOBUF_VERSION", "3.20.0")
res3 = transport._convert_protobuf_message_to_dict(message)
assert res3.get("name") == "test_op"
assert "including_default_value_fields" in calls[-1]

monkeypatch.setattr(base, "PROTOBUF_VERSION", "5.26.0")
res5 = transport._convert_protobuf_message_to_dict(message)
assert res5.get("name") == "test_op"
assert "always_print_fields_with_no_presence" in calls[-1]


def test_operations_v1_init_import_error_fallback(monkeypatch):
import importlib

import google.api_core.operations_v1 as op_v1

orig_import = __import__

def mock_import(name, globals=None, locals=None, fromlist=(), level=0):
if "operations_rest_client_async" in name or (
fromlist and "AsyncOperationsRestClient" in fromlist
):
raise ImportError("Simulated async rest import error")
return orig_import(name, globals, locals, fromlist, level)

monkeypatch.setattr("builtins.__import__", mock_import)
monkeypatch.setattr(op_v1, "_has_async_rest", True)
importlib.reload(op_v1)
Loading