Skip to content

Commit f4deeaa

Browse files
committed
style(api-core): format client cert and config helper tests with black
1 parent bd510e5 commit f4deeaa

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,31 @@
5454
"fallback_env_false_uppercase",
5555
"fallback_env_unset",
5656
"fallback_env_unsupported",
57-
]
57+
],
5858
)
5959
def test_use_client_cert_effective(has_method, method_val, env_val, expected):
6060
# Mock hasattr to control whether should_use_client_cert exists
6161
original_hasattr = hasattr
62+
6263
def custom_hasattr(obj, name):
6364
if obj is mtls and name == "should_use_client_cert":
6465
return has_method
6566
return original_hasattr(obj, name)
6667

6768
with mock.patch("google.api_core.gapic_v1.client_cert.hasattr", custom_hasattr):
68-
with mock.patch("google.auth.transport.mtls.should_use_client_cert", create=True, return_value=method_val):
69+
with mock.patch(
70+
"google.auth.transport.mtls.should_use_client_cert",
71+
create=True,
72+
return_value=method_val,
73+
):
6974
env = {}
7075
if env_val is not None:
7176
env["GOOGLE_API_USE_CLIENT_CERTIFICATE"] = env_val
7277
with mock.patch.dict(os.environ, env, clear=True):
7378
if expected == "value_error":
74-
with pytest.raises(ValueError, match="must be either `true` or `false`"):
79+
with pytest.raises(
80+
ValueError, match="must be either `true` or `false`"
81+
):
7582
use_client_cert_effective()
7683
else:
7784
assert use_client_cert_effective() is (expected == "true")
@@ -92,16 +99,27 @@ def custom_hasattr(obj, name):
9299
"use_cert_true_with_provided",
93100
"use_cert_true_no_provided_default_avail",
94101
"use_cert_true_no_provided_default_unavail",
95-
]
102+
],
96103
)
97-
def test_get_client_cert_source(provided, use_cert, has_default_avail, default_val, expected):
104+
def test_get_client_cert_source(
105+
provided, use_cert, has_default_avail, default_val, expected
106+
):
98107
original_hasattr = hasattr
108+
99109
def custom_hasattr(obj, name):
100110
if obj is mtls and name == "has_default_client_cert_source":
101111
return has_default_avail
102112
return original_hasattr(obj, name)
103113

104114
with mock.patch("google.api_core.gapic_v1.client_cert.hasattr", custom_hasattr):
105-
with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", create=True, return_value=has_default_avail):
106-
with mock.patch("google.auth.transport.mtls.default_client_cert_source", create=True, return_value=default_val):
115+
with mock.patch(
116+
"google.auth.transport.mtls.has_default_client_cert_source",
117+
create=True,
118+
return_value=has_default_avail,
119+
):
120+
with mock.patch(
121+
"google.auth.transport.mtls.default_client_cert_source",
122+
create=True,
123+
return_value=default_val,
124+
):
107125
assert get_client_cert_source(provided, use_cert) == expected

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
({"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}, False, (False, "always", None)),
3232
({"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}, False, (False, "auto", None)),
3333
({"GOOGLE_API_USE_MTLS_ENDPOINT": "invalid"}, False, "mutual_tls_error"),
34-
({"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}, False, (False, "auto", "foo.com")),
34+
(
35+
{"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"},
36+
False,
37+
(False, "auto", "foo.com"),
38+
),
3539
],
3640
ids=[
3741
"default_env",
@@ -41,13 +45,18 @@
4145
"mtls_auto",
4246
"mtls_invalid",
4347
"universe_domain",
44-
]
48+
],
4549
)
4650
def test_read_environment_variables(env, mock_cert_val, expected):
47-
with mock.patch("google.api_core.gapic_v1.config_helpers.use_client_cert_effective", return_value=mock_cert_val):
51+
with mock.patch(
52+
"google.api_core.gapic_v1.config_helpers.use_client_cert_effective",
53+
return_value=mock_cert_val,
54+
):
4855
with mock.patch.dict(os.environ, env, clear=True):
4956
if expected == "mutual_tls_error":
50-
with pytest.raises(MutualTLSChannelError, match="must be `never`, `auto` or `always`"):
57+
with pytest.raises(
58+
MutualTLSChannelError, match="must be `never`, `auto` or `always`"
59+
):
5160
read_environment_variables()
5261
else:
5362
assert read_environment_variables() == expected

0 commit comments

Comments
 (0)