Skip to content

Commit d4b93a6

Browse files
ohmayrhebaalazzeh
authored andcommitted
chore(api-core): restore fail_under=100 in .coveragerc (#17768)
`fail_under` was previously adjusted down to `99` because coverage reports included helper lines inside test files (`tests/unit/test_operations_rest_client.py`). In non-`async_rest` matrix sessions, conditional `if GOOGLE_AUTH_AIO_INSTALLED:` checks inside test runner files were flagged as un-executed lines, artificially dragging down total reported coverage. - Configured `omit = tests/*, */tests/*` under `[report]` in `.coveragerc` so coverage reporting evaluates threshold enforcement (`fail_under`) strictly against the `google.api_core` source library rather than test execution helper code. - Restored `fail_under = 100` in `.coveragerc`. Towards #17459 🦕
1 parent 7071978 commit d4b93a6

4 files changed

Lines changed: 54 additions & 3 deletions

File tree

packages/google-api-core/.coveragerc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
branch = True
33

44
[report]
5-
fail_under = 99
5+
fail_under = 100
66
show_missing = True
7+
omit =
8+
tests/*
9+
*/tests/*
710
exclude_lines =
811
# Re-enable the standard pragma
912
pragma: NO COVER

packages/google-api-core/google/api_core/gapic_v1/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
if they are not already set.
2222
"""
2323

24-
from typing import Union
2524
import uuid
25+
from typing import Union
2626

2727
import google.protobuf.message
2828

packages/google-api-core/tests/unit/gapic/test_requests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from google.api_core.gapic_v1.requests import setup_request_id
2121

22-
2322
# --- Mock Request Helper Classes ---
2423

2524

packages/google-api-core/tests/unit/operations_v1/test_operations_client.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,52 @@ def test_cancel_operation():
100100

101101
def test_operations_client_config():
102102
assert operations_client_config.config["interfaces"]
103+
104+
105+
def test_operations_v1_transport_base_to_dict_protobuf_versions(monkeypatch):
106+
from google.auth import credentials as ga_credentials
107+
from google.longrunning import operations_pb2
108+
109+
from google.api_core.operations_v1.transports import base
110+
111+
message = operations_pb2.Operation(name="test_op")
112+
transport = base.OperationsTransport(
113+
credentials=ga_credentials.AnonymousCredentials()
114+
)
115+
116+
calls = []
117+
118+
def mock_message_to_dict(*args, **kwargs):
119+
calls.append(kwargs)
120+
return {"name": "test_op"}
121+
122+
monkeypatch.setattr(base.json_format, "MessageToDict", mock_message_to_dict)
123+
124+
monkeypatch.setattr(base, "PROTOBUF_VERSION", "3.20.0")
125+
res3 = transport._convert_protobuf_message_to_dict(message)
126+
assert res3.get("name") == "test_op"
127+
assert "including_default_value_fields" in calls[-1]
128+
129+
monkeypatch.setattr(base, "PROTOBUF_VERSION", "5.26.0")
130+
res5 = transport._convert_protobuf_message_to_dict(message)
131+
assert res5.get("name") == "test_op"
132+
assert "always_print_fields_with_no_presence" in calls[-1]
133+
134+
135+
def test_operations_v1_init_import_error_fallback(monkeypatch):
136+
import importlib
137+
138+
import google.api_core.operations_v1 as op_v1
139+
140+
orig_import = __import__
141+
142+
def mock_import(name, globals=None, locals=None, fromlist=(), level=0):
143+
if "operations_rest_client_async" in name or (
144+
fromlist and "AsyncOperationsRestClient" in fromlist
145+
):
146+
raise ImportError("Simulated async rest import error")
147+
return orig_import(name, globals, locals, fromlist, level)
148+
149+
monkeypatch.setattr("builtins.__import__", mock_import)
150+
monkeypatch.setattr(op_v1, "_has_async_rest", True)
151+
importlib.reload(op_v1)

0 commit comments

Comments
 (0)