Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mqtt test DeprecationWarnings #97734

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tests/components/mqtt/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test config flow."""
from collections.abc import Generator
from collections.abc import Generator, Iterator
from contextlib import contextmanager
from pathlib import Path
from random import getrandbits
from ssl import SSLError
Expand Down Expand Up @@ -136,19 +137,22 @@ def mock_process_uploaded_file(tmp_path: Path) -> Generator[MagicMock, None, Non
file_id_cert = 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:
with open(tmp_path / "ca.crt", "wb") as cafile:
cafile.write(b"## mock CA certificate file ##")
return tmp_path / "ca.crt"
yield tmp_path / "ca.crt"
elif file_id == file_id_cert:
with open(tmp_path / "client.crt", "wb") as certfile:
certfile.write(b"## mock client certificate file ##")
return tmp_path / "client.crt"
yield tmp_path / "client.crt"
elif file_id == file_id_key:
with open(tmp_path / "client.key", "wb") as keyfile:
keyfile.write(b"## mock key file ##")
return tmp_path / "client.key"
yield tmp_path / "client.key"
else:
pytest.fail(f"Unexpected file_id: {file_id}")

Expand Down