Make tests less dependent on issue registry size (#145631)

* Make tests less dependent on issue registry size

* Make tests less dependent on issue registry size
This commit is contained in:
Joost Lekkerkerker 2025-05-26 19:39:11 +02:00 committed by GitHub
parent eec7666416
commit b15989f2bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 23 additions and 49 deletions

View File

@ -237,6 +237,7 @@ async def test_snapshot_service(
expected_filename: str, expected_filename: str,
expected_issues: list, expected_issues: list,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
issue_registry: ir.IssueRegistry,
) -> None: ) -> None:
"""Test snapshot service.""" """Test snapshot service."""
mopen = mock_open() mopen = mock_open()
@ -265,8 +266,6 @@ async def test_snapshot_service(
assert len(mock_write.mock_calls) == 1 assert len(mock_write.mock_calls) == 1
assert mock_write.mock_calls[0][1][0] == b"Test" assert mock_write.mock_calls[0][1][0] == b"Test"
issue_registry = ir.async_get(hass)
assert len(issue_registry.issues) == 1 + len(expected_issues)
for expected_issue in expected_issues: for expected_issue in expected_issues:
issue = issue_registry.async_get_issue(DOMAIN, expected_issue) issue = issue_registry.async_get_issue(DOMAIN, expected_issue)
assert issue is not None assert issue is not None
@ -638,6 +637,7 @@ async def test_record_service(
expected_filename: str, expected_filename: str,
expected_issues: list, expected_issues: list,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
issue_registry: ir.IssueRegistry,
) -> None: ) -> None:
"""Test record service.""" """Test record service."""
with ( with (
@ -666,8 +666,6 @@ async def test_record_service(
ANY, expected_filename, duration=30, lookback=0 ANY, expected_filename, duration=30, lookback=0
) )
issue_registry = ir.async_get(hass)
assert len(issue_registry.issues) == 1 + len(expected_issues)
for expected_issue in expected_issues: for expected_issue in expected_issues:
issue = issue_registry.async_get_issue(DOMAIN, expected_issue) issue = issue_registry.async_get_issue(DOMAIN, expected_issue)
assert issue is not None assert issue is not None

View File

@ -70,8 +70,7 @@ async def test_device_conflict_manual(
issues = await get_repairs(hass, hass_ws_client) issues = await get_repairs(hass, hass_ws_client)
assert issues assert issues
assert len(issues) == 1 assert issue_registry.async_get_issue(DOMAIN, issue_id) is not None
assert any(True for issue in issues if issue["issue_id"] == issue_id)
await async_process_repairs_platforms(hass) await async_process_repairs_platforms(hass)
client = await hass_client() client = await hass_client()
@ -182,8 +181,7 @@ async def test_device_conflict_migration(
issues = await get_repairs(hass, hass_ws_client) issues = await get_repairs(hass, hass_ws_client)
assert issues assert issues
assert len(issues) == 1 assert issue_registry.async_get_issue(DOMAIN, issue_id) is not None
assert any(True for issue in issues if issue["issue_id"] == issue_id)
await async_process_repairs_platforms(hass) await async_process_repairs_platforms(hass)
client = await hass_client() client = await hass_client()

View File

@ -481,7 +481,11 @@ async def test_sensor_with_uoms_but_no_device_class(
assert state.attributes.get("unit_of_measurement") == "W" assert state.attributes.get("unit_of_measurement") == "W"
assert state.state == str(float(sum(VALUES))) assert state.state == str(float(sum(VALUES)))
assert not issue_registry.issues assert not [
issue
for issue in issue_registry.issues.values()
if issue.domain == GROUP_DOMAIN
]
hass.states.async_set( hass.states.async_set(
entity_ids[0], entity_ids[0],

View File

@ -2,6 +2,7 @@
from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -10,13 +11,13 @@ from tests.components.repairs import (
process_repair_fix_flow, process_repair_fix_flow,
start_repair_fix_flow, start_repair_fix_flow,
) )
from tests.typing import ClientSessionGenerator, WebSocketGenerator from tests.typing import ClientSessionGenerator
async def test_integration_not_found_confirm_step( async def test_integration_not_found_confirm_step(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator, issue_registry: ir.IssueRegistry,
) -> None: ) -> None:
"""Test the integration_not_found issue confirm step.""" """Test the integration_not_found issue confirm step."""
assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {}) assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
@ -33,17 +34,11 @@ async def test_integration_not_found_confirm_step(
issue_id = "integration_not_found.test1" issue_id = "integration_not_found.test1"
await async_process_repairs_platforms(hass) await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
http_client = await hass_client() http_client = await hass_client()
# Assert the issue is present issue = issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) assert issue is not None
msg = await ws_client.receive_json() assert issue.translation_placeholders == {"domain": "test1"}
assert msg["success"]
assert len(msg["result"]["issues"]) == 1
issue = msg["result"]["issues"][0]
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id) data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id)
@ -68,16 +63,13 @@ async def test_integration_not_found_confirm_step(
assert hass.config_entries.async_get_entry(entry2.entry_id) is None assert hass.config_entries.async_get_entry(entry2.entry_id) is None
# Assert the issue is resolved # Assert the issue is resolved
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"}) assert not issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
msg = await ws_client.receive_json()
assert msg["success"]
assert len(msg["result"]["issues"]) == 0
async def test_integration_not_found_ignore_step( async def test_integration_not_found_ignore_step(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator, issue_registry: ir.IssueRegistry,
) -> None: ) -> None:
"""Test the integration_not_found issue ignore step.""" """Test the integration_not_found issue ignore step."""
assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {}) assert await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
@ -92,17 +84,11 @@ async def test_integration_not_found_ignore_step(
issue_id = "integration_not_found.test1" issue_id = "integration_not_found.test1"
await async_process_repairs_platforms(hass) await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
http_client = await hass_client() http_client = await hass_client()
# Assert the issue is present issue = issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) assert issue is not None
msg = await ws_client.receive_json() assert issue.translation_placeholders == {"domain": "test1"}
assert msg["success"]
assert len(msg["result"]["issues"]) == 1
issue = msg["result"]["issues"][0]
assert issue["issue_id"] == issue_id
assert issue["translation_placeholders"] == {"domain": "test1"}
data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id) data = await start_repair_fix_flow(http_client, HOMEASSISTANT_DOMAIN, issue_id)
@ -128,8 +114,6 @@ async def test_integration_not_found_ignore_step(
assert hass.config_entries.async_get_entry(entry1.entry_id) assert hass.config_entries.async_get_entry(entry1.entry_id)
# Assert the issue is resolved # Assert the issue is resolved
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"}) issue = issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
msg = await ws_client.receive_json() assert issue is not None
assert msg["success"] assert issue.dismissed_version is not None
assert len(msg["result"]["issues"]) == 1
assert msg["result"]["issues"][0].get("dismissed_version") is not None

View File

@ -190,5 +190,3 @@ async def test_create_issue(
assert issue_registry.async_get_issue( assert issue_registry.async_get_issue(
DOMAIN, f"deprecated_binary_sensor_{entity_id}" DOMAIN, f"deprecated_binary_sensor_{entity_id}"
) )
assert len(issue_registry.issues) == 1

View File

@ -190,7 +190,6 @@ async def test_create_issue_with_items(
assert automations_with_entity(hass, entity_id)[0] == "automation.test" assert automations_with_entity(hass, entity_id)[0] == "automation.test"
assert scripts_with_entity(hass, entity_id)[0] == "script.test" assert scripts_with_entity(hass, entity_id)[0] == "script.test"
assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue(DOMAIN, issue_id) issue = issue_registry.async_get_issue(DOMAIN, issue_id)
assert issue is not None assert issue is not None
assert issue.translation_key == f"deprecated_binary_{issue_string}_scripts" assert issue.translation_key == f"deprecated_binary_{issue_string}_scripts"
@ -210,7 +209,6 @@ async def test_create_issue_with_items(
# Assert the issue is no longer present # Assert the issue is no longer present
assert not issue_registry.async_get_issue(DOMAIN, issue_id) assert not issue_registry.async_get_issue(DOMAIN, issue_id)
assert len(issue_registry.issues) == 0
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -258,7 +256,6 @@ async def test_create_issue(
assert hass.states.get(entity_id).state == STATE_OFF assert hass.states.get(entity_id).state == STATE_OFF
assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue(DOMAIN, issue_id) issue = issue_registry.async_get_issue(DOMAIN, issue_id)
assert issue is not None assert issue is not None
assert issue.translation_key == f"deprecated_binary_{issue_string}" assert issue.translation_key == f"deprecated_binary_{issue_string}"
@ -277,4 +274,3 @@ async def test_create_issue(
# Assert the issue is no longer present # Assert the issue is no longer present
assert not issue_registry.async_get_issue(DOMAIN, issue_id) assert not issue_registry.async_get_issue(DOMAIN, issue_id)
assert len(issue_registry.issues) == 0

View File

@ -205,7 +205,6 @@ async def test_create_issue_with_items(
assert automations_with_entity(hass, entity_id)[0] == "automation.test" assert automations_with_entity(hass, entity_id)[0] == "automation.test"
assert scripts_with_entity(hass, entity_id)[0] == "script.test" assert scripts_with_entity(hass, entity_id)[0] == "script.test"
assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue(DOMAIN, issue_id) issue = issue_registry.async_get_issue(DOMAIN, issue_id)
assert issue is not None assert issue is not None
assert issue.translation_key == f"deprecated_{issue_string}_scripts" assert issue.translation_key == f"deprecated_{issue_string}_scripts"
@ -226,7 +225,6 @@ async def test_create_issue_with_items(
# Assert the issue is no longer present # Assert the issue is no longer present
assert not issue_registry.async_get_issue(DOMAIN, issue_id) assert not issue_registry.async_get_issue(DOMAIN, issue_id)
assert len(issue_registry.issues) == 0
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -333,7 +331,6 @@ async def test_create_issue(
assert hass.states.get(entity_id).state == expected_state assert hass.states.get(entity_id).state == expected_state
assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue(DOMAIN, issue_id) issue = issue_registry.async_get_issue(DOMAIN, issue_id)
assert issue is not None assert issue is not None
assert issue.translation_key == f"deprecated_{issue_string}" assert issue.translation_key == f"deprecated_{issue_string}"
@ -353,7 +350,6 @@ async def test_create_issue(
# Assert the issue is no longer present # Assert the issue is no longer present
assert not issue_registry.async_get_issue(DOMAIN, issue_id) assert not issue_registry.async_get_issue(DOMAIN, issue_id)
assert len(issue_registry.issues) == 0
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"]) @pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])