Fix mqtt test DeprecationWarnings (#97734)

This commit is contained in:
Marc Mueller 2023-08-04 09:21:36 +02:00 committed by GitHub
parent 1587ac2137
commit 37885400c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
"""Test config flow.""" """Test config flow."""
from collections.abc import Generator from collections.abc import Generator, Iterator
from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from random import getrandbits from random import getrandbits
from ssl import SSLError from ssl import SSLError
@ -136,19 +137,22 @@ def mock_process_uploaded_file(tmp_path: Path) -> Generator[MagicMock, None, Non
file_id_cert = str(uuid4()) file_id_cert = str(uuid4())
file_id_key = str(uuid4()) file_id_key = str(uuid4())
def _mock_process_uploaded_file(hass: HomeAssistant, file_id) -> None: @contextmanager
def _mock_process_uploaded_file(
hass: HomeAssistant, file_id: str
) -> Iterator[Path | None]:
if file_id == file_id_ca: if file_id == file_id_ca:
with open(tmp_path / "ca.crt", "wb") as cafile: with open(tmp_path / "ca.crt", "wb") as cafile:
cafile.write(b"## mock CA certificate file ##") cafile.write(b"## mock CA certificate file ##")
return tmp_path / "ca.crt" yield tmp_path / "ca.crt"
elif file_id == file_id_cert: elif file_id == file_id_cert:
with open(tmp_path / "client.crt", "wb") as certfile: with open(tmp_path / "client.crt", "wb") as certfile:
certfile.write(b"## mock client certificate file ##") certfile.write(b"## mock client certificate file ##")
return tmp_path / "client.crt" yield tmp_path / "client.crt"
elif file_id == file_id_key: elif file_id == file_id_key:
with open(tmp_path / "client.key", "wb") as keyfile: with open(tmp_path / "client.key", "wb") as keyfile:
keyfile.write(b"## mock key file ##") keyfile.write(b"## mock key file ##")
return tmp_path / "client.key" yield tmp_path / "client.key"
else: else:
pytest.fail(f"Unexpected file_id: {file_id}") pytest.fail(f"Unexpected file_id: {file_id}")