Fix blocking I/O in config tests (#121144)

pull/121146/head
J. Nick Koston 2024-07-03 23:21:30 -05:00 committed by GitHub
parent e8ef2c2822
commit 1144e23d8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import contextlib
import copy
import logging
import os
from pathlib import Path
from typing import Any
from unittest import mock
from unittest.mock import AsyncMock, MagicMock, Mock, patch
@ -412,11 +413,10 @@ async def test_ensure_config_exists_creates_config(hass: HomeAssistant) -> None:
async def test_ensure_config_exists_uses_existing_config(hass: HomeAssistant) -> None:
"""Test that calling ensure_config_exists uses existing config."""
create_file(YAML_PATH)
await hass.async_add_executor_job(create_file, YAML_PATH)
await config_util.async_ensure_config_exists(hass)
with open(YAML_PATH, encoding="utf8") as fp:
content = fp.read()
content = await hass.async_add_executor_job(Path(YAML_PATH).read_text)
# File created with create_file are empty
assert content == ""
@ -424,12 +424,11 @@ async def test_ensure_config_exists_uses_existing_config(hass: HomeAssistant) ->
async def test_ensure_existing_files_is_not_overwritten(hass: HomeAssistant) -> None:
"""Test that calling async_create_default_config does not overwrite existing files."""
create_file(SECRET_PATH)
await hass.async_add_executor_job(create_file, SECRET_PATH)
await config_util.async_create_default_config(hass)
with open(SECRET_PATH, encoding="utf8") as fp:
content = fp.read()
content = await hass.async_add_executor_job(Path(SECRET_PATH).read_text)
# File created with create_file are empty
assert content == ""