Skip to content
Snippets Groups Projects
Unverified Commit 713abf4c authored by epenet's avatar epenet Committed by GitHub
Browse files

Refactor PLATFORM_SCHEMA imports in tests (#120566)

parent 32c07180
No related branches found
No related tags found
No related merge requests found
......@@ -12,11 +12,7 @@ from homeassistant import config_entries, loader, setup
from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START
from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import discovery, translation
from homeassistant.helpers.config_validation import (
PLATFORM_SCHEMA,
PLATFORM_SCHEMA_BASE,
)
from homeassistant.helpers import config_validation as cv, discovery, translation
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
......@@ -88,8 +84,8 @@ async def test_validate_platform_config(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test validating platform configuration."""
platform_schema = PLATFORM_SCHEMA.extend({"hello": str})
platform_schema_base = PLATFORM_SCHEMA_BASE.extend({})
platform_schema = cv.PLATFORM_SCHEMA.extend({"hello": str})
platform_schema_base = cv.PLATFORM_SCHEMA_BASE.extend({})
mock_integration(
hass,
MockModule("platform_conf", platform_schema_base=platform_schema_base),
......@@ -149,8 +145,8 @@ async def test_validate_platform_config_2(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test component PLATFORM_SCHEMA_BASE prio over PLATFORM_SCHEMA."""
platform_schema = PLATFORM_SCHEMA.extend({"hello": str})
platform_schema_base = PLATFORM_SCHEMA_BASE.extend({"hello": "world"})
platform_schema = cv.PLATFORM_SCHEMA.extend({"hello": str})
platform_schema_base = cv.PLATFORM_SCHEMA_BASE.extend({"hello": "world"})
mock_integration(
hass,
MockModule(
......@@ -183,8 +179,8 @@ async def test_validate_platform_config_3(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test fallback to component PLATFORM_SCHEMA."""
component_schema = PLATFORM_SCHEMA_BASE.extend({"hello": str})
platform_schema = PLATFORM_SCHEMA.extend({"cheers": str, "hello": "world"})
component_schema = cv.PLATFORM_SCHEMA_BASE.extend({"hello": str})
platform_schema = cv.PLATFORM_SCHEMA.extend({"cheers": str, "hello": "world"})
mock_integration(
hass, MockModule("platform_conf", platform_schema=component_schema)
)
......@@ -210,8 +206,8 @@ async def test_validate_platform_config_3(
async def test_validate_platform_config_4(hass: HomeAssistant) -> None:
"""Test entity_namespace in PLATFORM_SCHEMA."""
component_schema = PLATFORM_SCHEMA_BASE
platform_schema = PLATFORM_SCHEMA
component_schema = cv.PLATFORM_SCHEMA_BASE
platform_schema = cv.PLATFORM_SCHEMA
mock_integration(
hass,
MockModule("platform_conf", platform_schema_base=component_schema),
......@@ -386,7 +382,9 @@ async def test_component_setup_with_validation_and_dependency(
async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
"""Test platform that specifies config."""
platform_schema = PLATFORM_SCHEMA.extend({"valid": True}, extra=vol.PREVENT_EXTRA)
platform_schema = cv.PLATFORM_SCHEMA.extend(
{"valid": True}, extra=vol.PREVENT_EXTRA
)
mock_setup = Mock(spec_set=True)
......@@ -533,7 +531,7 @@ async def test_component_warn_slow_setup(hass: HomeAssistant) -> None:
async def test_platform_no_warn_slow(hass: HomeAssistant) -> None:
"""Do not warn for long entity setup time."""
mock_integration(
hass, MockModule("test_component1", platform_schema=PLATFORM_SCHEMA)
hass, MockModule("test_component1", platform_schema=cv.PLATFORM_SCHEMA)
)
with patch.object(hass.loop, "call_later") as mock_call:
result = await setup.async_setup_component(hass, "test_component1", {})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment