1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-20 02:48:57 +00:00

Use is over == comparison for ConfigEntryState in tests (#159212)

This commit is contained in:
epenet
2025-12-16 16:51:39 +01:00
committed by GitHub
parent 7b1653c77b
commit 6af674e64e
22 changed files with 49 additions and 49 deletions

View File

@@ -72,7 +72,7 @@ async def _entry(hass: HomeAssistant, filter_schema: dict[str, Any], entry) -> N
assert await async_setup_component(
hass, DOMAIN, {DOMAIN: {CONF_FILTER: filter_schema}}
)
assert entry.state == ConfigEntryState.LOADED
assert entry.state is ConfigEntryState.LOADED
# Clear the component_loaded event from the queue.
async_fire_time_changed(
@@ -87,7 +87,7 @@ async def mock_entry_with_one_event(
hass: HomeAssistant, entry_managed
) -> MockConfigEntry:
"""Use the entry and add a single test event to the queue."""
assert entry_managed.state == ConfigEntryState.LOADED
assert entry_managed.state is ConfigEntryState.LOADED
hass.states.async_set("sensor.test", STATE_ON)
return entry_managed

View File

@@ -106,10 +106,10 @@ async def test_unload_entry(
this verifies that the unload, calls async_stop, which calls async_send and
shuts down the hub.
"""
assert entry_managed.state == ConfigEntryState.LOADED
assert entry_managed.state is ConfigEntryState.LOADED
assert await hass.config_entries.async_unload(entry_managed.entry_id)
mock_managed_streaming.assert_not_called()
assert entry_managed.state == ConfigEntryState.NOT_LOADED
assert entry_managed.state is ConfigEntryState.NOT_LOADED
@pytest.mark.freeze_time("2024-01-01 00:00:00")
@@ -261,4 +261,4 @@ async def test_connection(
entry.add_to_hass(hass)
mock_execute_query.side_effect = sideeffect
await hass.config_entries.async_setup(entry.entry_id)
assert entry.state == ConfigEntryState.SETUP_ERROR
assert entry.state is ConfigEntryState.SETUP_ERROR

View File

@@ -22,12 +22,12 @@ async def test_load_unload_config_entry(
"""Test loading and unloading the integration."""
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state == ConfigEntryState.LOADED
assert mock_config_entry.state is ConfigEntryState.LOADED
await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED # type: ignore[comparison-overlap]
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED # type: ignore[comparison-overlap]
async def test_setup_entry_invalid_auth(

View File

@@ -22,13 +22,13 @@ async def test_setup_entry(
) -> None:
"""Test async_setup_entry."""
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
# Load entry
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state == ConfigEntryState.LOADED
assert mock_config_entry.state is ConfigEntryState.LOADED
# Check that the device has been registered properly
device = device_registry.async_get_device(
@@ -57,13 +57,13 @@ async def test_setup_entry_failed(
"", (ServerTimeoutError(), TimeoutError())
)
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
# Load entry
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state == ConfigEntryState.SETUP_RETRY
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
# Ensure that the connection has been checked, API client correctly closed
# and WebSocket connection has not been initialized
@@ -80,12 +80,12 @@ async def test_unload_entry(
"""Test unload_entry."""
# Load entry
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state == ConfigEntryState.LOADED
assert mock_config_entry.state is ConfigEntryState.LOADED
assert hasattr(mock_config_entry, "runtime_data")
# Unload entry
@@ -97,4 +97,4 @@ async def test_unload_entry(
# Ensure that the entry is not loaded and has been removed from hass
assert not hasattr(mock_config_entry, "runtime_data")
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED

View File

@@ -18,10 +18,10 @@ async def test_setup(
"""Test entry setup without any exceptions."""
mock_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_entry.entry_id)
assert mock_entry.state == ConfigEntryState.LOADED
assert mock_entry.state is ConfigEntryState.LOADED
# Unload
await hass.config_entries.async_unload(mock_entry.entry_id)
assert mock_entry.state == ConfigEntryState.NOT_LOADED
assert mock_entry.state is ConfigEntryState.NOT_LOADED
async def test_setup_connect_error(
@@ -33,4 +33,4 @@ async def test_setup_connect_error(
mock_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_entry.entry_id)
# Ensure is not ready
assert mock_entry.state == ConfigEntryState.SETUP_RETRY
assert mock_entry.state is ConfigEntryState.SETUP_RETRY

View File

@@ -96,7 +96,7 @@ async def _test_setup_and_signaling(
config_entries = hass.config_entries.async_entries(DOMAIN)
assert len(config_entries) == 1
config_entry = config_entries[0]
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state is ConfigEntryState.LOADED
after_setup_fn()
receive_message_callback = Mock(spec_set=WebRTCSendMessage)
@@ -183,7 +183,7 @@ async def _test_setup_and_signaling(
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.NOT_LOADED
assert config_entry.state is ConfigEntryState.NOT_LOADED
assert teardown.call_count == 2
@@ -625,7 +625,7 @@ async def test_setup_with_setup_entry_error(
await hass.async_block_till_done(wait_background_tasks=True)
config_entries = hass.config_entries.async_entries(DOMAIN)
assert len(config_entries) == 1
assert config_entries[0].state == ConfigEntryState.SETUP_ERROR
assert config_entries[0].state is ConfigEntryState.SETUP_ERROR
assert expected_log_message in caplog.text

View File

@@ -254,7 +254,7 @@ async def setup_bridge(
with patch("homeassistant.components.hue.HueBridge", return_value=mock_bridge):
await hass.config_entries.async_setup(config_entry.entry_id)
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state is ConfigEntryState.LOADED
async def setup_platform(

View File

@@ -29,7 +29,7 @@ async def test_load_unload(
"""Test loading and unloading the MySensors config entry."""
config_entry = integration
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state is ConfigEntryState.LOADED
entity_id = "binary_sensor.door_sensor_1_1"
state = hass.states.get(entity_id)

View File

@@ -313,7 +313,7 @@ async def setup_base_platform(
await hass.async_block_till_done()
yield _setup_func
if config_entry.state == ConfigEntryState.LOADED:
if config_entry.state is ConfigEntryState.LOADED:
await hass.config_entries.async_unload(config_entry.entry_id)

View File

@@ -33,7 +33,7 @@ async def test_invalid_authentication(
)
assert len(entries) == 0
# Ensure the config entry is marked as error
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
async def test_no_devices(
@@ -53,4 +53,4 @@ async def test_no_devices(
)
assert len(entries) == 0
# Ensure the config entry is marked as error
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR

View File

@@ -27,4 +27,4 @@ async def test_invalid_authentication(
)
assert len(entries) == 0
# Ensure the config entry is marked as error
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR

View File

@@ -58,7 +58,7 @@ async def test_migrate_entry(hass: HomeAssistant) -> None:
CONF_MAC_EXCLUDE: [],
CONF_OPTIONS: DEFAULT_OPTIONS,
}
assert updated_entry.state == ConfigEntryState.LOADED
assert updated_entry.state is ConfigEntryState.LOADED
async def test_migrate_entry_fails_on_downgrade(hass: HomeAssistant) -> None:
@@ -90,4 +90,4 @@ async def test_migrate_entry_fails_on_downgrade(hass: HomeAssistant) -> None:
updated_entry = hass.config_entries.async_get_entry(mock_entry.entry_id)
assert updated_entry
assert updated_entry.version == 2
assert updated_entry.state == ConfigEntryState.MIGRATION_ERROR
assert updated_entry.state is ConfigEntryState.MIGRATION_ERROR

View File

@@ -976,7 +976,7 @@ async def test_privacy_mode_on(
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state is ConfigEntryState.LOADED
async def test_LoginPrivacyModeError(

View File

@@ -78,4 +78,4 @@ async def test_migrate_from_future_version(
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ConfigEntryState.MIGRATION_ERROR
assert entry.state is ConfigEntryState.MIGRATION_ERROR

View File

@@ -15,7 +15,7 @@ async def test_async_setup_entry(hass: HomeAssistant, bypass_api: AsyncMock) ->
"""Test a successful setup entry."""
entry = await async_init_integration(hass)
assert len(hass.states.async_all("sensor")) == 2
assert entry.state == ConfigEntryState.LOADED
assert entry.state is ConfigEntryState.LOADED
async def test_cannot_auth(hass: HomeAssistant, bypass_api: AsyncMock) -> None:

View File

@@ -62,7 +62,7 @@ async def test_setup_error(
assert mock_config_entry.state == error
if error == ConfigEntryState.SETUP_RETRY:
if error is ConfigEntryState.SETUP_RETRY:
assert len(hass.config_entries.flow.async_progress()) == 0
@@ -117,7 +117,7 @@ async def test_other_exceptions_during_first_refresh(
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
await hass.async_block_till_done()
assert mock_config_entry.state == ConfigEntryState.SETUP_RETRY
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
assert len(hass.config_entries.flow.async_progress()) == 0

View File

@@ -42,7 +42,7 @@ async def test_set_webhooks_failed(
assert mock_set_webhook.call_count == 2
# SETUP_ERROR is result of ConfigEntryNotReady("Failed to register webhook with Telegram") in webhooks.py
assert mock_webhooks_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_webhooks_config_entry.state is ConfigEntryState.SETUP_ERROR
# test fail after retries
@@ -55,7 +55,7 @@ async def test_set_webhooks_failed(
# 3 retries
assert mock_set_webhook.call_count == 3
assert mock_webhooks_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_webhooks_config_entry.state is ConfigEntryState.SETUP_ERROR
await hass.async_block_till_done()
@@ -72,7 +72,7 @@ async def test_set_webhooks(
await hass.async_block_till_done()
assert mock_webhooks_config_entry.state == ConfigEntryState.LOADED
assert mock_webhooks_config_entry.state is ConfigEntryState.LOADED
async def test_webhooks_update_invalid_json(
@@ -125,7 +125,7 @@ async def test_webhooks_deregister_failed(
"""Test deregister webhooks."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state is ConfigEntryState.LOADED
with patch(
"homeassistant.components.telegram_bot.webhooks.Bot.delete_webhook",
@@ -134,4 +134,4 @@ async def test_webhooks_deregister_failed(
await hass.config_entries.async_unload(config_entry.entry_id)
mock_delete_webhook.assert_called_once()
assert config_entry.state == ConfigEntryState.NOT_LOADED
assert config_entry.state is ConfigEntryState.NOT_LOADED

View File

@@ -13,9 +13,9 @@ async def test_entry_unload(
) -> None:
"""Test unloading the entry."""
entry = hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, "tibber")
assert entry.state == ConfigEntryState.LOADED
assert entry.state is ConfigEntryState.LOADED
await hass.config_entries.async_unload(entry.entry_id)
mock_tibber_setup.rt_disconnect.assert_called_once()
await hass.async_block_till_done(wait_background_tasks=True)
assert entry.state == ConfigEntryState.NOT_LOADED
assert entry.state is ConfigEntryState.NOT_LOADED

View File

@@ -31,7 +31,7 @@ async def test_service_config_entry_not_loaded_state(
"""Test service call when config entry is in failed state."""
mock_config_entry.add_to_hass(hass)
assert mock_config_entry.state == ConfigEntryState.NOT_LOADED
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
with pytest.raises(ServiceValidationError, match="service_not_found"):
await hass.services.async_call(

View File

@@ -39,7 +39,7 @@ async def test_setup_entry_fails_config_entry_not_ready(
):
config_entry = await config_entry_factory()
assert config_entry.state == ConfigEntryState.SETUP_RETRY
assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_setup_entry_fails_trigger_reauth_flow(
@@ -56,7 +56,7 @@ async def test_setup_entry_fails_trigger_reauth_flow(
config_entry = await config_entry_factory()
mock_flow_init.assert_called_once()
assert config_entry.state == ConfigEntryState.SETUP_ERROR
assert config_entry.state is ConfigEntryState.SETUP_ERROR
@pytest.mark.parametrize(

View File

@@ -214,7 +214,7 @@ async def test_fail_when_other_device(
await hass.async_block_till_done()
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
assert mock_config_entry.reason
assert (
"MAC address does not match the configured device." in mock_config_entry.reason
@@ -238,7 +238,7 @@ async def test_fail_when_unsupported_version(
await hass.async_block_till_done()
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
assert mock_config_entry.reason
assert (
"The WLED device's firmware version is not supported:"

View File

@@ -2332,7 +2332,7 @@ async def test_driver_ready_event(
await hass.async_block_till_done()
assert len(config_entry_state_changes) == 4
assert config_entry_state_changes[0] == ConfigEntryState.UNLOAD_IN_PROGRESS
assert config_entry_state_changes[1] == ConfigEntryState.NOT_LOADED
assert config_entry_state_changes[2] == ConfigEntryState.SETUP_IN_PROGRESS
assert config_entry_state_changes[3] == ConfigEntryState.LOADED
assert config_entry_state_changes[0] is ConfigEntryState.UNLOAD_IN_PROGRESS
assert config_entry_state_changes[1] is ConfigEntryState.NOT_LOADED
assert config_entry_state_changes[2] is ConfigEntryState.SETUP_IN_PROGRESS
assert config_entry_state_changes[3] is ConfigEntryState.LOADED