Files
core/tests/components/openweathermap/__init__.py
wittypluck 6350ed3415 Add snapshot tests for OpenWeatherMap sensors (#139657)
* Add snapshot tests for sensors

* Code cleanup

* Patch during async_setup only

* Use snapshot_platform, split platforms for snapshot tests

* Make mock_config_entry and mode fixtures

* Update snapshots with  latest device and state class changes

* Move setup_platform to __init__.py and patch HA object instead of library

* Remove if statements in tests

* Add client mock fixture to patch get_weather instead of internal call

* Code cleanup

* Test explicit list of modes

* Fix

* Fix

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
2025-05-09 13:06:38 +02:00

25 lines
749 B
Python

"""Shared utilities for OpenWeatherMap tests."""
from unittest.mock import patch
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def setup_platform(
hass: HomeAssistant,
config_entry: MockConfigEntry,
platforms: list[Platform],
):
"""Set up the OpenWeatherMap platform."""
config_entry.add_to_hass(hass)
with (
patch("homeassistant.components.openweathermap.PLATFORMS", platforms),
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED