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

Add type hints to integration tests (part 6) #87979

Merged
merged 1 commit into from Feb 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/components/dormakaba_dkey/test_config_flow.py
Expand Up @@ -104,7 +104,9 @@ async def test_user_step_device_added_between_steps_1(hass: HomeAssistant) -> No
assert result["reason"] == "already_configured"


async def test_async_step_user_takes_precedence_over_discovery(hass):
async def test_async_step_user_takes_precedence_over_discovery(
hass: HomeAssistant,
) -> None:
"""Test manual setup takes precedence over discovery."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
Expand Down Expand Up @@ -198,7 +200,7 @@ async def test_bluetooth_step_already_configured(hass: HomeAssistant) -> None:
assert result["reason"] == "already_configured"


async def test_bluetooth_step_already_in_progress(hass):
async def test_bluetooth_step_already_in_progress(hass: HomeAssistant) -> None:
"""Test we can't start a flow for the same device twice."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
Expand Down
7 changes: 5 additions & 2 deletions tests/components/emulated_roku/test_config_flow.py
@@ -1,11 +1,12 @@
"""Tests for emulated_roku config flow."""
from homeassistant import config_entries
from homeassistant.components.emulated_roku import config_flow
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def test_flow_works(hass, mock_get_source_ip):
async def test_flow_works(hass: HomeAssistant, mock_get_source_ip) -> None:
"""Test that config flow works."""
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
Expand All @@ -18,7 +19,9 @@ async def test_flow_works(hass, mock_get_source_ip):
assert result["data"] == {"name": "Emulated Roku Test", "listen_port": 8060}


async def test_flow_already_registered_entry(hass, mock_get_source_ip):
async def test_flow_already_registered_entry(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test that config flow doesn't allow existing names."""
MockConfigEntry(
domain="emulated_roku", data={"name": "Emulated Roku Test", "listen_port": 8062}
Expand Down
6 changes: 4 additions & 2 deletions tests/components/emulated_roku/test_init.py
Expand Up @@ -6,7 +6,7 @@
from homeassistant.setup import async_setup_component


async def test_config_required_fields(hass, mock_get_source_ip):
async def test_config_required_fields(hass: HomeAssistant, mock_get_source_ip) -> None:
"""Test that configuration is successful with required fields."""
with patch.object(emulated_roku, "configured_servers", return_value=[]), patch(
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
Expand All @@ -31,7 +31,9 @@ async def test_config_required_fields(hass, mock_get_source_ip):
)


async def test_config_already_registered_not_configured(hass, mock_get_source_ip):
async def test_config_already_registered_not_configured(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test that an already registered name causes the entry to be ignored."""
with patch(
"homeassistant.components.emulated_roku.binding.EmulatedRokuServer",
Expand Down
53 changes: 37 additions & 16 deletions tests/components/energy/test_sensor.py
Expand Up @@ -22,12 +22,14 @@
UnitOfEnergy,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM

from tests.components.recorder.common import async_wait_recording_done
from tests.typing import WebSocketGenerator


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -68,7 +70,9 @@ def get_statistics_for_entity(statistics_results, entity_id):
return None


async def test_cost_sensor_no_states(setup_integration, hass, hass_storage) -> None:
async def test_cost_sensor_no_states(
setup_integration, hass: HomeAssistant, hass_storage
) -> None:
"""Test sensors are created."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(
Expand All @@ -94,7 +98,9 @@ async def test_cost_sensor_no_states(setup_integration, hass, hass_storage) -> N
# TODO: No states, should the cost entity refuse to setup?


async def test_cost_sensor_attributes(setup_integration, hass, hass_storage) -> None:
async def test_cost_sensor_attributes(
setup_integration, hass: HomeAssistant, hass_storage
) -> None:
"""Test sensor attributes."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(
Expand Down Expand Up @@ -144,9 +150,9 @@ async def test_cost_sensor_attributes(setup_integration, hass, hass_storage) ->
)
async def test_cost_sensor_price_entity_total_increasing(
setup_integration,
hass,
hass: HomeAssistant,
hass_storage,
hass_ws_client,
hass_ws_client: WebSocketGenerator,
initial_energy,
initial_cost,
price_entity,
Expand Down Expand Up @@ -347,9 +353,9 @@ def _compile_statistics(_):
@pytest.mark.parametrize("energy_state_class", ["total", "measurement"])
async def test_cost_sensor_price_entity_total(
setup_integration,
hass,
hass: HomeAssistant,
hass_storage,
hass_ws_client,
hass_ws_client: WebSocketGenerator,
initial_energy,
initial_cost,
price_entity,
Expand Down Expand Up @@ -553,9 +559,9 @@ def _compile_statistics(_):
@pytest.mark.parametrize("energy_state_class", ["total"])
async def test_cost_sensor_price_entity_total_no_reset(
setup_integration,
hass,
hass: HomeAssistant,
hass_storage,
hass_ws_client,
hass_ws_client: WebSocketGenerator,
initial_energy,
initial_cost,
price_entity,
Expand Down Expand Up @@ -726,7 +732,7 @@ def _compile_statistics(_):
],
)
async def test_cost_sensor_handle_energy_units(
setup_integration, hass, hass_storage, energy_unit, factor
setup_integration, hass: HomeAssistant, hass_storage, energy_unit, factor
) -> None:
"""Test energy cost price from sensor entity."""
energy_attributes = {
Expand Down Expand Up @@ -792,7 +798,7 @@ async def test_cost_sensor_handle_energy_units(
],
)
async def test_cost_sensor_handle_price_units(
setup_integration, hass, hass_storage, price_unit, factor
setup_integration, hass: HomeAssistant, hass_storage, price_unit, factor
) -> None:
"""Test energy cost price from sensor entity."""
energy_attributes = {
Expand Down Expand Up @@ -858,7 +864,7 @@ async def test_cost_sensor_handle_price_units(
(UnitOfVolume.CUBIC_FEET, UnitOfVolume.CUBIC_METERS),
)
async def test_cost_sensor_handle_gas(
setup_integration, hass, hass_storage, unit
setup_integration, hass: HomeAssistant, hass_storage, unit
) -> None:
"""Test gas cost price from sensor entity."""
energy_attributes = {
Expand Down Expand Up @@ -908,7 +914,7 @@ async def test_cost_sensor_handle_gas(


async def test_cost_sensor_handle_gas_kwh(
setup_integration, hass, hass_storage
setup_integration, hass: HomeAssistant, hass_storage
) -> None:
"""Test gas cost price from sensor entity."""
energy_attributes = {
Expand Down Expand Up @@ -967,7 +973,12 @@ async def test_cost_sensor_handle_gas_kwh(
),
)
async def test_cost_sensor_handle_water(
setup_integration, hass, hass_storage, unit_system, usage_unit, growth
setup_integration,
hass: HomeAssistant,
hass_storage,
unit_system,
usage_unit,
growth,
) -> None:
"""Test water cost price from sensor entity."""
hass.config.units = unit_system
Expand Down Expand Up @@ -1019,7 +1030,11 @@ async def test_cost_sensor_handle_water(

@pytest.mark.parametrize("state_class", [None])
async def test_cost_sensor_wrong_state_class(
setup_integration, hass, hass_storage, caplog, state_class
setup_integration,
hass: HomeAssistant,
hass_storage,
caplog: pytest.LogCaptureFixture,
state_class,
) -> None:
"""Test energy sensor rejects sensor with wrong state_class."""
energy_attributes = {
Expand Down Expand Up @@ -1080,7 +1095,11 @@ async def test_cost_sensor_wrong_state_class(

@pytest.mark.parametrize("state_class", [SensorStateClass.MEASUREMENT])
async def test_cost_sensor_state_class_measurement_no_reset(
setup_integration, hass, hass_storage, caplog, state_class
setup_integration,
hass: HomeAssistant,
hass_storage,
caplog: pytest.LogCaptureFixture,
state_class,
) -> None:
"""Test energy sensor rejects state_class measurement with no last_reset."""
energy_attributes = {
Expand Down Expand Up @@ -1135,7 +1154,9 @@ async def test_cost_sensor_state_class_measurement_no_reset(
assert state.state == STATE_UNKNOWN


async def test_inherit_source_unique_id(setup_integration, hass, hass_storage):
async def test_inherit_source_unique_id(
setup_integration, hass: HomeAssistant, hass_storage
) -> None:
"""Test sensor inherits unique ID from source."""
energy_data = data.EnergyManager.default_preferences()
energy_data["energy_sources"].append(
Expand Down