Skip to content

Commit d3c1166

Browse files
committed
fix(lint): fix import ordering in gapic_v1 config
1 parent 2c0b579 commit d3c1166

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ def use_client_cert_effective() -> bool:
181181
if hasattr(mtls, "should_use_client_cert"):
182182
return mtls.should_use_client_cert()
183183
else:
184-
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
184+
use_client_cert_str = os.getenv(
185+
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
186+
).lower()
185187
if use_client_cert_str not in ("true", "false"):
186188
raise ValueError(
187189
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from unittest import mock
1717

1818
import pytest
19-
from google.auth.exceptions import MutualTLSChannelError
2019

2120
try:
2221
import grpc # noqa: F401
@@ -25,6 +24,7 @@
2524

2625
from google.api_core import exceptions
2726
from google.api_core.gapic_v1 import config
27+
from google.auth.exceptions import MutualTLSChannelError
2828

2929
INTERFACE_CONFIG = {
3030
"retry_codes": {
@@ -121,14 +121,18 @@ def test_use_client_cert_effective_fallback_env_true():
121121
def test_use_client_cert_effective_fallback_env_false():
122122
mock_mtls = mock.Mock(spec=[])
123123
with mock.patch("google.api_core.gapic_v1.config.mtls", mock_mtls):
124-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):
124+
with mock.patch.dict(
125+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}
126+
):
125127
assert config.use_client_cert_effective() is False
126128

127129

128130
def test_use_client_cert_effective_fallback_env_invalid():
129131
mock_mtls = mock.Mock(spec=[])
130132
with mock.patch("google.api_core.gapic_v1.config.mtls", mock_mtls):
131-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "invalid"}):
133+
with mock.patch.dict(
134+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "invalid"}
135+
):
132136
with pytest.raises(
133137
ValueError,
134138
match="Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`",
@@ -142,7 +146,9 @@ def test_get_client_cert_source_provided():
142146

143147

144148
def test_get_client_cert_source_default():
145-
mock_mtls = mock.Mock(spec=["has_default_client_cert_source", "default_client_cert_source"])
149+
mock_mtls = mock.Mock(
150+
spec=["has_default_client_cert_source", "default_client_cert_source"]
151+
)
146152
mock_mtls.has_default_client_cert_source.return_value = True
147153
mock_source = mock.Mock()
148154
mock_mtls.default_client_cert_source.return_value = mock_source
@@ -151,7 +157,9 @@ def test_get_client_cert_source_default():
151157

152158

153159
def test_get_client_cert_source_none():
154-
mock_mtls = mock.Mock(spec=["has_default_client_cert_source", "default_client_cert_source"])
160+
mock_mtls = mock.Mock(
161+
spec=["has_default_client_cert_source", "default_client_cert_source"]
162+
)
155163
mock_mtls.has_default_client_cert_source.return_value = False
156164
with mock.patch("google.api_core.gapic_v1.config.mtls", mock_mtls):
157165
with pytest.raises(
@@ -168,10 +176,15 @@ def test_get_client_cert_source_use_cert_flag_false():
168176

169177

170178
def test_read_environment_variables():
171-
with mock.patch("google.api_core.gapic_v1.config.use_client_cert_effective", return_value=True):
179+
with mock.patch(
180+
"google.api_core.gapic_v1.config.use_client_cert_effective", return_value=True
181+
):
172182
with mock.patch.dict(
173183
os.environ,
174-
{"GOOGLE_API_USE_MTLS_ENDPOINT": "always", "GOOGLE_CLOUD_UNIVERSE_DOMAIN": "my-universe.com"}
184+
{
185+
"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
186+
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "my-universe.com",
187+
},
175188
):
176189
use_cert, use_mtls, universe = config.read_environment_variables()
177190
assert use_cert is True
@@ -180,7 +193,9 @@ def test_read_environment_variables():
180193

181194

182195
def test_read_environment_variables_invalid_mtls():
183-
with mock.patch("google.api_core.gapic_v1.config.use_client_cert_effective", return_value=True):
196+
with mock.patch(
197+
"google.api_core.gapic_v1.config.use_client_cert_effective", return_value=True
198+
):
184199
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "invalid"}):
185200
with pytest.raises(MutualTLSChannelError):
186201
config.read_environment_variables()

0 commit comments

Comments
 (0)