Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use issue_registry fixture in component tests #118041

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/components/airvisual/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ async def test_migration_1_2(hass: HomeAssistant, mock_pyairvisual) -> None:


async def test_migration_2_3(
hass: HomeAssistant, mock_pyairvisual, device_registry: dr.DeviceRegistry
hass: HomeAssistant,
mock_pyairvisual,
device_registry: dr.DeviceRegistry,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test migrating from version 2 to 3."""
entry = MockConfigEntry(
Expand Down Expand Up @@ -134,5 +137,4 @@ async def test_migration_2_3(
for domain, entry_count in ((DOMAIN, 0), (AIRVISUAL_PRO_DOMAIN, 1)):
assert len(hass.config_entries.async_entries(domain)) == entry_count

issue_registry = ir.async_get(hass)
assert len(issue_registry.issues) == 1
32 changes: 19 additions & 13 deletions tests/components/bayesian/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
STATE_UNKNOWN,
)
from homeassistant.core import Context, HomeAssistant, callback
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.entity_registry import async_get as async_get_entities
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.issue_registry import async_get
from homeassistant.setup import async_setup_component

from tests.common import get_fixture_path
Expand Down Expand Up @@ -104,7 +104,9 @@ async def test_unknown_state_does_not_influence_probability(
assert state.attributes.get("probability") == prior


async def test_sensor_numeric_state(hass: HomeAssistant) -> None:
async def test_sensor_numeric_state(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test sensor on numeric state platform observations."""
config = {
"binary_sensor": {
Expand Down Expand Up @@ -200,7 +202,7 @@ async def test_sensor_numeric_state(hass: HomeAssistant) -> None:

assert state.state == "off"

assert len(async_get(hass).issues) == 0
assert len(issue_registry.issues) == 0


async def test_sensor_state(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -329,7 +331,7 @@ async def test_sensor_value_template(hass: HomeAssistant) -> None:
assert state.state == "off"


async def test_threshold(hass: HomeAssistant) -> None:
async def test_threshold(hass: HomeAssistant, issue_registry: ir.IssueRegistry) -> None:
"""Test sensor on probability threshold limits."""
config = {
"binary_sensor": {
Expand Down Expand Up @@ -359,7 +361,7 @@ async def test_threshold(hass: HomeAssistant) -> None:
assert round(abs(1.0 - state.attributes.get("probability")), 7) == 0

assert state.state == "on"
assert len(async_get(hass).issues) == 0
assert len(issue_registry.issues) == 0


async def test_multiple_observations(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -513,7 +515,9 @@ async def test_multiple_numeric_observations(hass: HomeAssistant) -> None:
assert state.attributes.get("observations")[1]["platform"] == "numeric_state"


async def test_mirrored_observations(hass: HomeAssistant) -> None:
async def test_mirrored_observations(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test whether mirrored entries are detected and appropriate issues are created."""

config = {
Expand Down Expand Up @@ -586,22 +590,24 @@ async def test_mirrored_observations(hass: HomeAssistant) -> None:
"prior": 0.1,
}
}
assert len(async_get(hass).issues) == 0
assert len(issue_registry.issues) == 0
assert await async_setup_component(hass, "binary_sensor", config)
await hass.async_block_till_done()
hass.states.async_set("sensor.test_monitored2", "on")
await hass.async_block_till_done()

assert len(async_get(hass).issues) == 3
assert len(issue_registry.issues) == 3
assert (
async_get(hass).issues[
issue_registry.issues[
("bayesian", "mirrored_entry/Test_Binary/sensor.test_monitored1")
]
is not None
)


async def test_missing_prob_given_false(hass: HomeAssistant) -> None:
async def test_missing_prob_given_false(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test whether missing prob_given_false are detected and appropriate issues are created."""

config = {
Expand Down Expand Up @@ -630,15 +636,15 @@ async def test_missing_prob_given_false(hass: HomeAssistant) -> None:
"prior": 0.1,
}
}
assert len(async_get(hass).issues) == 0
assert len(issue_registry.issues) == 0
assert await async_setup_component(hass, "binary_sensor", config)
await hass.async_block_till_done()
hass.states.async_set("sensor.test_monitored2", "on")
await hass.async_block_till_done()

assert len(async_get(hass).issues) == 3
assert len(issue_registry.issues) == 3
assert (
async_get(hass).issues[
issue_registry.issues[
("bayesian", "no_prob_given_false/missingpgf/sensor.test_monitored1")
]
is not None
Expand Down
10 changes: 5 additions & 5 deletions tests/components/bluetooth/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.issue_registry import async_get as async_get_issue_registry
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -3151,15 +3151,15 @@ async def test_issue_outdated_haos_removed(
mock_bleak_scanner_start: MagicMock,
no_adapters: None,
operating_system_85: None,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test we do not create an issue on outdated haos anymore."""
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()

registry = async_get_issue_registry(hass)
issue = registry.async_get_issue(DOMAIN, "haos_outdated")
issue = issue_registry.async_get_issue(DOMAIN, "haos_outdated")
assert issue is None


Expand All @@ -3168,6 +3168,7 @@ async def test_haos_9_or_later(
mock_bleak_scanner_start: MagicMock,
one_adapter: None,
operating_system_90: None,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test we do not create issues for haos 9.x or later."""
entry = MockConfigEntry(
Expand All @@ -3178,8 +3179,7 @@ async def test_haos_9_or_later(
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
registry = async_get_issue_registry(hass)
issue = registry.async_get_issue(DOMAIN, "haos_outdated")
issue = issue_registry.async_get_issue(DOMAIN, "haos_outdated")
assert issue is None


Expand Down
4 changes: 2 additions & 2 deletions tests/components/bmw_connected_drive/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.issue_registry import IssueRegistry
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.update_coordinator import UpdateFailed

from . import FIXTURE_CONFIG_ENTRY
Expand Down Expand Up @@ -100,7 +100,7 @@ async def test_init_reauth(
hass: HomeAssistant,
bmw_fixture: respx.Router,
freezer: FrozenDateTimeFactory,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the reauth form."""

Expand Down
4 changes: 2 additions & 2 deletions tests/components/calendar/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.issue_registry import IssueRegistry
from homeassistant.helpers import issue_registry as ir
import homeassistant.util.dt as dt_util

from .conftest import TEST_DOMAIN, MockCalendarEntity, MockConfigEntry
Expand Down Expand Up @@ -572,7 +572,7 @@ async def test_list_events_missing_fields(hass: HomeAssistant) -> None:

async def test_issue_deprecated_service_calendar_list_events(
hass: HomeAssistant,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the issue is raised on deprecated service weather.get_forecast."""
Expand Down
12 changes: 6 additions & 6 deletions tests/components/climate/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ async def test_issue_aux_property_deprecated(
translation_placeholders_extra: dict[str, str],
report: str,
module: str,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the issue is raised on deprecated auxiliary heater attributes."""

Expand Down Expand Up @@ -894,8 +895,7 @@ async def async_setup_entry_climate_platform(

assert climate_entity.state == HVACMode.HEAT

issues = ir.async_get(hass)
issue = issues.async_get_issue("climate", "deprecated_climate_aux_test")
issue = issue_registry.async_get_issue("climate", "deprecated_climate_aux_test")
assert issue
assert issue.issue_domain == "test"
assert issue.issue_id == "deprecated_climate_aux_test"
Expand Down Expand Up @@ -954,6 +954,7 @@ async def test_no_issue_aux_property_deprecated_for_core(
translation_placeholders_extra: dict[str, str],
report: str,
module: str,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the no issue on deprecated auxiliary heater attributes for core integrations."""

Expand Down Expand Up @@ -1023,8 +1024,7 @@ async def async_setup_entry_climate_platform(

assert climate_entity.state == HVACMode.HEAT

issues = ir.async_get(hass)
issue = issues.async_get_issue("climate", "deprecated_climate_aux_test")
issue = issue_registry.async_get_issue("climate", "deprecated_climate_aux_test")
assert not issue

assert (
Expand All @@ -1038,6 +1038,7 @@ async def test_no_issue_no_aux_property(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
config_flow_fixture: None,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the issue is raised on deprecated auxiliary heater attributes."""

Expand Down Expand Up @@ -1082,8 +1083,7 @@ async def async_setup_entry_climate_platform(

assert climate_entity.state == HVACMode.HEAT

issues = ir.async_get(hass)
assert len(issues.issues) == 0
assert len(issue_registry.issues) == 0

assert (
"test::MockClimateEntityWithAux implements the `is_aux_heat` property or uses "
Expand Down
7 changes: 3 additions & 4 deletions tests/components/cloud/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from homeassistant.components.http.const import StrictConnectionMode
from homeassistant.const import CONTENT_TYPE_JSON, __version__ as HA_VERSION
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.issue_registry import IssueRegistry
from homeassistant.helpers import entity_registry as er, issue_registry as ir
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -401,7 +400,7 @@ async def test_cloud_connection_info(hass: HomeAssistant) -> None:
async def test_async_create_repair_issue_known(
cloud: MagicMock,
mock_cloud_setup: None,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
translation_key: str,
) -> None:
"""Test create repair issue for known repairs."""
Expand All @@ -419,7 +418,7 @@ async def test_async_create_repair_issue_known(
async def test_async_create_repair_issue_unknown(
cloud: MagicMock,
mock_cloud_setup: None,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test not creating repair issue for unknown repairs."""
identifier = "abc123"
Expand Down
14 changes: 7 additions & 7 deletions tests/components/cloud/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from homeassistant.config import async_process_ha_core_config
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.entity_registry import EntityRegistry
from homeassistant.helpers.issue_registry import IssueRegistry, IssueSeverity
from homeassistant.setup import async_setup_component

from . import PIPELINE_DATA
Expand Down Expand Up @@ -143,7 +143,7 @@ async def test_prefs_default_voice(

async def test_deprecated_platform_config(
hass: HomeAssistant,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
cloud: MagicMock,
) -> None:
"""Test cloud provider uses the preferences."""
Expand All @@ -157,7 +157,7 @@ async def test_deprecated_platform_config(
assert issue.breaks_in_ha_version == "2024.9.0"
assert issue.is_fixable is False
assert issue.is_persistent is False
assert issue.severity == IssueSeverity.WARNING
assert issue.severity == ir.IssueSeverity.WARNING
assert issue.translation_key == "deprecated_tts_platform_config"


Expand Down Expand Up @@ -463,7 +463,7 @@ async def test_migrating_pipelines(
)
async def test_deprecated_voice(
hass: HomeAssistant,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
cloud: MagicMock,
hass_client: ClientSessionGenerator,
data: dict[str, Any],
Expand Down Expand Up @@ -555,7 +555,7 @@ async def test_deprecated_voice(
assert issue.breaks_in_ha_version == "2024.8.0"
assert issue.is_fixable is True
assert issue.is_persistent is True
assert issue.severity == IssueSeverity.WARNING
assert issue.severity == ir.IssueSeverity.WARNING
assert issue.translation_key == "deprecated_voice"
assert issue.translation_placeholders == {
"deprecated_voice": deprecated_voice,
Expand Down Expand Up @@ -613,7 +613,7 @@ async def test_deprecated_voice(
)
async def test_deprecated_gender(
hass: HomeAssistant,
issue_registry: IssueRegistry,
issue_registry: ir.IssueRegistry,
cloud: MagicMock,
hass_client: ClientSessionGenerator,
data: dict[str, Any],
Expand Down Expand Up @@ -700,7 +700,7 @@ async def test_deprecated_gender(
assert issue.breaks_in_ha_version == "2024.10.0"
assert issue.is_fixable is True
assert issue.is_persistent is True
assert issue.severity == IssueSeverity.WARNING
assert issue.severity == ir.IssueSeverity.WARNING
assert issue.translation_key == "deprecated_gender"
assert issue.translation_placeholders == {
"integration_name": "Home Assistant Cloud",
Expand Down
13 changes: 5 additions & 8 deletions tests/components/dynalite/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from homeassistant.const import CONF_PORT
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_get as async_get_issue_registry,
)
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component

from tests.common import MockConfigEntry
Expand All @@ -34,10 +31,10 @@ async def test_flow(
exp_type,
exp_result,
exp_reason,
issue_registry: ir.IssueRegistry,
) -> None:
"""Run a flow with or without errors and return result."""
registry = async_get_issue_registry(hass)
issue = registry.async_get_issue(dynalite.DOMAIN, "deprecated_yaml")
issue = issue_registry.async_get_issue(dynalite.DOMAIN, "deprecated_yaml")
assert issue is None
host = "1.2.3.4"
with patch(
Expand All @@ -55,12 +52,12 @@ async def test_flow(
assert result["result"].state == exp_result
if exp_reason:
assert result["reason"] == exp_reason
issue = registry.async_get_issue(
issue = issue_registry.async_get_issue(
HOMEASSISTANT_DOMAIN, f"deprecated_yaml_{dynalite.DOMAIN}"
)
assert issue is not None
assert issue.issue_domain == dynalite.DOMAIN
assert issue.severity == IssueSeverity.WARNING
assert issue.severity == ir.IssueSeverity.WARNING


async def test_deprecated(
Expand Down
Loading