Move fixtures to decorators in core tests (#119675)

This commit is contained in:
epenet
2024-06-14 13:32:42 +02:00
committed by GitHub
parent b80f7185b2
commit 01be5d5f6b
9 changed files with 80 additions and 109 deletions

View File

@@ -1,6 +1,5 @@
"""Test check_config script."""
from asyncio import AbstractEventLoop
import logging
from unittest.mock import patch
@@ -56,9 +55,8 @@ def normalize_yaml_files(check_dict):
@pytest.mark.parametrize("hass_config_yaml", [BAD_CORE_CONFIG])
def test_bad_core_config(
mock_is_file: None, event_loop: AbstractEventLoop, mock_hass_config_yaml: None
) -> None:
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
def test_bad_core_config() -> None:
"""Test a bad core config setup."""
res = check_config.check(get_test_config_dir())
assert res["except"].keys() == {"homeassistant"}
@@ -67,9 +65,8 @@ def test_bad_core_config(
@pytest.mark.parametrize("hass_config_yaml", [BASE_CONFIG + "light:\n platform: demo"])
def test_config_platform_valid(
mock_is_file: None, event_loop: AbstractEventLoop, mock_hass_config_yaml: None
) -> None:
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
def test_config_platform_valid() -> None:
"""Test a valid platform setup."""
res = check_config.check(get_test_config_dir())
assert res["components"].keys() == {"homeassistant", "light"}
@@ -99,13 +96,8 @@ def test_config_platform_valid(
),
],
)
def test_component_platform_not_found(
mock_is_file: None,
event_loop: AbstractEventLoop,
mock_hass_config_yaml: None,
platforms: set[str],
error: str,
) -> None:
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
def test_component_platform_not_found(platforms: set[str], error: str) -> None:
"""Test errors if component or platform not found."""
# Make sure they don't exist
res = check_config.check(get_test_config_dir())
@@ -129,9 +121,8 @@ def test_component_platform_not_found(
}
],
)
def test_secrets(
mock_is_file: None, event_loop: AbstractEventLoop, mock_hass_config_yaml: None
) -> None:
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
def test_secrets() -> None:
"""Test secrets config checking method."""
res = check_config.check(get_test_config_dir(), True)
@@ -160,9 +151,8 @@ def test_secrets(
@pytest.mark.parametrize(
"hass_config_yaml", [BASE_CONFIG + ' packages:\n p1:\n group: ["a"]']
)
def test_package_invalid(
mock_is_file: None, event_loop: AbstractEventLoop, mock_hass_config_yaml: None
) -> None:
@pytest.mark.usefixtures("mock_is_file", "event_loop", "mock_hass_config_yaml")
def test_package_invalid() -> None:
"""Test an invalid package."""
res = check_config.check(get_test_config_dir())
@@ -178,9 +168,8 @@ def test_package_invalid(
@pytest.mark.parametrize(
"hass_config_yaml", [BASE_CONFIG + "automation: !include no.yaml"]
)
def test_bootstrap_error(
event_loop: AbstractEventLoop, mock_hass_config_yaml: None
) -> None:
@pytest.mark.usefixtures("event_loop", "mock_hass_config_yaml")
def test_bootstrap_error() -> None:
"""Test a valid platform setup."""
res = check_config.check(get_test_config_dir(YAML_CONFIG_FILE))
err = res["except"].pop(check_config.ERROR_STR)