Don't swallow all errors when checking for config validator platform (#42058)
This commit is contained in:
1 parent
8d4675713a
commit
440570244d
6 files changed
+54
-13
No files matched your search
@@ -973,6 +973,14 @@ def mock_integration(hass, module):
|
||||
hass, f"homeassistant.components.{module.DOMAIN}", None, module.mock_manifest()
|
||||
)
|
||||
|
||||
def mock_import_platform(platform_name):
|
||||
raise ImportError(
|
||||
f"Mocked unable to import platform '{platform_name}'",
|
||||
name=f"{integration.pkg_path}.{platform_name}",
|
||||
)
|
||||
|
||||
integration._import_platform = mock_import_platform
|
||||
|
||||
_LOGGER.info("Adding mock integration: %s", module.DOMAIN)
|
||||
hass.data.setdefault(loader.DATA_INTEGRATIONS, {})[module.DOMAIN] = integration
|
||||
hass.data.setdefault(loader.DATA_COMPONENTS, {})[module.DOMAIN] = module
|
||||
|
||||
@@ -14,17 +14,18 @@ from homeassistant.const import CONF_PLATFORM, CONF_SCAN_INTERVAL
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import MockModule, async_fire_time_changed, mock_integration
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_hub(hass):
|
||||
"""Mock hub."""
|
||||
mock_integration(hass, MockModule(DOMAIN))
|
||||
hub = mock.MagicMock()
|
||||
hub.name = "hub"
|
||||
hass.data[DOMAIN] = {DEFAULT_HUB: hub}
|
||||
return hub
|
||||
with patch("homeassistant.components.modbus.setup", return_value=True):
|
||||
hub = mock.MagicMock()
|
||||
hub.name = "hub"
|
||||
hass.data[DOMAIN] = {DEFAULT_HUB: hub}
|
||||
yield hub
|
||||
|
||||
|
||||
class ReadResult:
|
||||
|
||||
@@ -1064,6 +1064,30 @@ async def test_component_config_exceptions(hass, caplog):
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
# get_platform("config") raising
|
||||
caplog.clear()
|
||||
assert (
|
||||
await config_util.async_process_component_config(
|
||||
hass,
|
||||
{"test_domain": {}},
|
||||
integration=Mock(
|
||||
pkg_path="homeassistant.components.test_domain",
|
||||
domain="test_domain",
|
||||
get_platform=Mock(
|
||||
side_effect=ImportError(
|
||||
"ModuleNotFoundError: No module named 'not_installed_something'",
|
||||
name="not_installed_something",
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
is None
|
||||
)
|
||||
assert (
|
||||
"Error importing config platform test_domain: ModuleNotFoundError: No module named 'not_installed_something'"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"domain, schema, expected",
|
||||
|
||||
Reference in new issue
Block a user