mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 09:38:58 +01:00
Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com> Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
committed by
GitHub
parent
27219b6962
commit
6bb4e7d62c
+166
-83
@@ -252,13 +252,21 @@ async def test_get_integration_exceptions(hass: HomeAssistant) -> None:
|
||||
"""Test resolving integration."""
|
||||
integration = await loader.async_get_integration(hass, "hue")
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ValueError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ValueError("Boom"),
|
||||
),
|
||||
):
|
||||
assert hue == integration.get_component()
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ValueError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ValueError("Boom"),
|
||||
),
|
||||
):
|
||||
assert hue_light == integration.get_platform("light")
|
||||
|
||||
@@ -269,27 +277,43 @@ async def test_get_platform_caches_failures_when_component_loaded(
|
||||
"""Test get_platform cache failures only when the component is loaded."""
|
||||
integration = await loader.async_get_integration(hass, "hue")
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_component() == hue
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_platform("light") == hue_light
|
||||
|
||||
# Hue is not loaded so we should still hit the import_module path
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_platform("light") == hue_light
|
||||
|
||||
assert integration.get_component() == hue
|
||||
|
||||
# Hue is loaded so we should cache the import_module failure now
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_platform("light") == hue_light
|
||||
|
||||
@@ -304,27 +328,43 @@ async def test_async_get_platform_caches_failures_when_component_loaded(
|
||||
"""Test async_get_platform cache failures only when the component is loaded."""
|
||||
integration = await loader.async_get_integration(hass, "hue")
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_component() == hue
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platform("light") == hue_light
|
||||
|
||||
# Hue is not loaded so we should still hit the import_module path
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platform("light") == hue_light
|
||||
|
||||
assert integration.get_component() == hue
|
||||
|
||||
# Hue is loaded so we should cache the import_module failure now
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platform("light") == hue_light
|
||||
|
||||
@@ -342,27 +382,43 @@ async def test_async_get_platforms_caches_failures_when_component_loaded(
|
||||
"""Test async_get_platforms cache failures only when the component is loaded."""
|
||||
integration = await loader.async_get_integration(hass, "hue")
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert integration.get_component() == hue
|
||||
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platforms(["light"]) == {"light": hue_light}
|
||||
|
||||
# Hue is not loaded so we should still hit the import_module path
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platforms(["light"]) == {"light": hue_light}
|
||||
|
||||
assert integration.get_component() == hue
|
||||
|
||||
# Hue is loaded so we should cache the import_module failure now
|
||||
with pytest.raises(ImportError), patch(
|
||||
"homeassistant.loader.importlib.import_module", side_effect=ImportError("Boom")
|
||||
with (
|
||||
pytest.raises(ImportError),
|
||||
patch(
|
||||
"homeassistant.loader.importlib.import_module",
|
||||
side_effect=ImportError("Boom"),
|
||||
),
|
||||
):
|
||||
assert await integration.async_get_platforms(["light"]) == {"light": hue_light}
|
||||
|
||||
@@ -1129,12 +1185,15 @@ async def test_hass_components_use_reported(
|
||||
relative_filename="custom_components/test_integration_frame/__init__.py",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.get_integration_frame",
|
||||
return_value=integration_frame,
|
||||
), patch(
|
||||
"homeassistant.components.http.start_http_server_and_save_config",
|
||||
return_value=None,
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.helpers.frame.get_integration_frame",
|
||||
return_value=integration_frame,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.http.start_http_server_and_save_config",
|
||||
return_value=None,
|
||||
),
|
||||
):
|
||||
await hass.components.http.start_http_server_and_save_config(hass, [], None)
|
||||
|
||||
@@ -1162,10 +1221,11 @@ async def test_async_get_component_preloads_config_and_config_flow(
|
||||
platform_exists_calls.append(platforms)
|
||||
return platforms
|
||||
|
||||
with patch(
|
||||
"homeassistant.loader.importlib.import_module"
|
||||
) as mock_import, patch.object(
|
||||
executor_import_integration, "platforms_exists", mock_platforms_exists
|
||||
with (
|
||||
patch("homeassistant.loader.importlib.import_module") as mock_import,
|
||||
patch.object(
|
||||
executor_import_integration, "platforms_exists", mock_platforms_exists
|
||||
),
|
||||
):
|
||||
await executor_import_integration.async_get_component()
|
||||
|
||||
@@ -1218,11 +1278,14 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
|
||||
modules_without_config_flow = {
|
||||
k: v for k, v in sys.modules.items() if k != config_flow_module_name
|
||||
}
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_config_flow, integration.pkg_path: module_mock},
|
||||
clear=True,
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_config_flow, integration.pkg_path: module_mock},
|
||||
clear=True,
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
module = await integration.async_get_component()
|
||||
|
||||
# The config flow is missing so we should load
|
||||
@@ -1232,13 +1295,16 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
|
||||
assert module is module_mock
|
||||
caplog.clear()
|
||||
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
{
|
||||
integration.pkg_path: module_mock,
|
||||
config_flow_module_name: config_flow_module_mock,
|
||||
},
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
{
|
||||
integration.pkg_path: module_mock,
|
||||
config_flow_module_name: config_flow_module_mock,
|
||||
},
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
module = await integration.async_get_component()
|
||||
|
||||
# Everything is already in the integration cache
|
||||
@@ -1285,11 +1351,14 @@ async def test_async_get_component_concurrent_loads(
|
||||
for k, v in sys.modules.items()
|
||||
if k != config_flow_module_name and k != integration.pkg_path
|
||||
}
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_integration},
|
||||
clear=True,
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_integration},
|
||||
clear=True,
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
load_task1 = asyncio.create_task(integration.async_get_component())
|
||||
load_task2 = asyncio.create_task(integration.async_get_component())
|
||||
await import_event.wait() # make sure the import is started
|
||||
@@ -1371,9 +1440,10 @@ async def test_async_get_component_raises_after_import_failure(
|
||||
|
||||
assert "homeassistant.components.executor_import" not in sys.modules
|
||||
assert "custom_components.executor_import" not in sys.modules
|
||||
with patch(
|
||||
"homeassistant.loader.importlib.import_module", mock_import
|
||||
), pytest.raises(ImportError):
|
||||
with (
|
||||
patch("homeassistant.loader.importlib.import_module", mock_import),
|
||||
pytest.raises(ImportError),
|
||||
):
|
||||
await executor_import_integration.async_get_component()
|
||||
|
||||
assert (
|
||||
@@ -1454,9 +1524,10 @@ async def test_async_get_platform_raises_after_import_failure(
|
||||
|
||||
assert "homeassistant.components.executor_import" not in sys.modules
|
||||
assert "custom_components.executor_import" not in sys.modules
|
||||
with patch(
|
||||
"homeassistant.loader.importlib.import_module", mock_import
|
||||
), pytest.raises(ImportError):
|
||||
with (
|
||||
patch("homeassistant.loader.importlib.import_module", mock_import),
|
||||
pytest.raises(ImportError),
|
||||
):
|
||||
await executor_import_integration.async_get_platform("config_flow")
|
||||
|
||||
assert (
|
||||
@@ -1563,11 +1634,14 @@ async def test_async_get_platforms_loads_loop_if_already_in_sys_modules(
|
||||
modules_without_button = {
|
||||
k: v for k, v in sys.modules.items() if k != button_module_name
|
||||
}
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
modules_without_button,
|
||||
clear=True,
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
modules_without_button,
|
||||
clear=True,
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
module = (await integration.async_get_platforms(["button"]))["button"]
|
||||
|
||||
# The button module is missing so we should load
|
||||
@@ -1577,13 +1651,16 @@ async def test_async_get_platforms_loads_loop_if_already_in_sys_modules(
|
||||
assert module is button_module_mock
|
||||
caplog.clear()
|
||||
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
{
|
||||
**modules_without_button,
|
||||
button_module_name: button_module_mock,
|
||||
},
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
{
|
||||
**modules_without_button,
|
||||
button_module_name: button_module_mock,
|
||||
},
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
module = (await integration.async_get_platforms(["button"]))["button"]
|
||||
|
||||
# Everything is cached so there should be no logging
|
||||
@@ -1595,11 +1672,14 @@ async def test_async_get_platforms_loads_loop_if_already_in_sys_modules(
|
||||
modules_without_switch = {
|
||||
k: v for k, v in sys.modules.items() if k not in switch_module_name
|
||||
}
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_switch, light_module_name: light_module_mock},
|
||||
clear=True,
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
{**modules_without_switch, light_module_name: light_module_mock},
|
||||
clear=True,
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
modules = await integration.async_get_platforms(["button", "switch", "light"])
|
||||
|
||||
# The button module is already in the cache so nothing happens
|
||||
@@ -1659,11 +1739,14 @@ async def test_async_get_platforms_concurrent_loads(
|
||||
for k, v in sys.modules.items()
|
||||
if k != button_module_name and k != integration.pkg_path
|
||||
}
|
||||
with patch.dict(
|
||||
"sys.modules",
|
||||
modules_without_button,
|
||||
clear=True,
|
||||
), patch("homeassistant.loader.importlib.import_module", import_module):
|
||||
with (
|
||||
patch.dict(
|
||||
"sys.modules",
|
||||
modules_without_button,
|
||||
clear=True,
|
||||
),
|
||||
patch("homeassistant.loader.importlib.import_module", import_module),
|
||||
):
|
||||
load_task1 = asyncio.create_task(integration.async_get_platforms(["button"]))
|
||||
load_task2 = asyncio.create_task(integration.async_get_platforms(["button"]))
|
||||
await import_event.wait() # make sure the import is started
|
||||
|
||||
Reference in New Issue
Block a user