Skip to content

Commit 6287fdd

Browse files
committed
fix: fix test failures due to warnings
1 parent fc9d25f commit 6287fdd

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

tests/unit/test_client_options.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ def get_client_encrypted_cert():
2828

2929
def test_constructor():
3030

31-
options = client_options.ClientOptions(
32-
api_endpoint="foo.googleapis.com",
33-
client_cert_source=get_client_cert,
34-
quota_project_id="quote-proj",
35-
credentials_file="path/to/credentials.json",
36-
scopes=[
37-
"https://www.googleapis.com/auth/cloud-platform",
38-
"https://www.googleapis.com/auth/cloud-platform.read-only",
39-
],
40-
api_audience="foo2.googleapis.com",
41-
universe_domain="googleapis.com",
42-
)
31+
with pytest.warns(
32+
DeprecationWarning,
33+
match="argument is deprecated because of a potential security risk",
34+
):
35+
options = client_options.ClientOptions(
36+
api_endpoint="foo.googleapis.com",
37+
client_cert_source=get_client_cert,
38+
quota_project_id="quote-proj",
39+
credentials_file="path/to/credentials.json",
40+
scopes=[
41+
"https://www.googleapis.com/auth/cloud-platform",
42+
"https://www.googleapis.com/auth/cloud-platform.read-only",
43+
],
44+
api_audience="foo2.googleapis.com",
45+
universe_domain="googleapis.com",
46+
)
4347

4448
assert options.api_endpoint == "foo.googleapis.com"
4549
assert options.client_cert_source() == (b"cert", b"key")
@@ -102,10 +106,14 @@ def test_constructor_with_api_key():
102106

103107
def test_constructor_with_both_api_key_and_credentials_file():
104108
with pytest.raises(ValueError):
105-
client_options.ClientOptions(
106-
api_key="api-key",
107-
credentials_file="path/to/credentials.json",
108-
)
109+
with pytest.warns(
110+
DeprecationWarning,
111+
match="argument is deprecated because of a potential security risk",
112+
):
113+
client_options.ClientOptions(
114+
api_key="api-key",
115+
credentials_file="path/to/credentials.json",
116+
)
109117

110118

111119
def test_from_dict():

tests/unit/test_python_version_support.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,20 @@ def test_override_gapic_end_only():
178178
"google.api_core._python_version_support.PYTHON_VERSION_INFO",
179179
{version_tuple: overridden_info},
180180
):
181-
result_before_boundary = check_python_version(
182-
today=custom_gapic_end + datetime.timedelta(days=-1)
183-
)
181+
with pytest.warns(FutureWarning, match="past its end of life"):
182+
result_before_boundary = check_python_version(
183+
today=custom_gapic_end + datetime.timedelta(days=-1)
184+
)
184185
assert result_before_boundary == PythonVersionStatus.PYTHON_VERSION_EOL
185186

186-
result_at_boundary = check_python_version(today=custom_gapic_end)
187+
with pytest.warns(FutureWarning, match="past its end of life"):
188+
result_at_boundary = check_python_version(today=custom_gapic_end)
187189
assert result_at_boundary == PythonVersionStatus.PYTHON_VERSION_EOL
188190

189-
result_after_boundary = check_python_version(
190-
today=custom_gapic_end + datetime.timedelta(days=1)
191-
)
191+
with pytest.warns(FutureWarning, match="non-supported Python version"):
192+
result_after_boundary = check_python_version(
193+
today=custom_gapic_end + datetime.timedelta(days=1)
194+
)
192195
assert (
193196
result_after_boundary == PythonVersionStatus.PYTHON_VERSION_UNSUPPORTED
194197
)
@@ -217,7 +220,8 @@ def test_override_gapic_deprecation_only():
217220
result_before_boundary == PythonVersionStatus.PYTHON_VERSION_SUPPORTED
218221
)
219222

220-
result_at_boundary = check_python_version(today=custom_gapic_dep)
223+
with pytest.warns(FutureWarning, match="Google will stop supporting"):
224+
result_at_boundary = check_python_version(today=custom_gapic_dep)
221225
assert result_at_boundary == PythonVersionStatus.PYTHON_VERSION_DEPRECATED
222226

223227

0 commit comments

Comments
 (0)