Update Ruff to be used in tests (#943)

* Update Ruff config

* Rerun ruff
This commit is contained in:
Bas Nijholt 2024-03-03 15:09:18 -08:00 • committed by GitHub
commit f2a124c30f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 196 additions and 101 deletions

View file

@ -2,6 +2,7 @@
from unittest.mock import Mock
import pytest
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP_KELVIN,
@ -9,7 +10,6 @@ from homeassistant.components.light import (
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_ON
from homeassistant.core import Context, State
import pytest
from custom_components.adaptive_lighting.adaptation_utils import (
ServiceData,
@ -22,7 +22,7 @@ from custom_components.adaptive_lighting.adaptation_utils import (
@pytest.mark.parametrize(
"input_data,expected_data_list",
("input_data", "expected_data_list"),
[
(
{"foo": 1},
@ -72,7 +72,7 @@ async def test_split_service_call_data(input_data, expected_data_list):
@pytest.mark.parametrize(
"service_data,state,service_data_expected",
("service_data", "state", "service_data_expected"),
[
(
{ATTR_ENTITY_ID: "light.test", ATTR_BRIGHTNESS: 10, ATTR_TRANSITION: 2},
@ -97,14 +97,16 @@ async def test_split_service_call_data(input_data, expected_data_list):
],
)
async def test_remove_redundant_attributes(
service_data: ServiceData, state: State | None, service_data_expected: ServiceData
service_data: ServiceData,
state: State | None,
service_data_expected: ServiceData,
):
"""Test filtering of service data."""
assert _remove_redundant_attributes(service_data, state) == service_data_expected
@pytest.mark.parametrize(
"service_data,expected_relevant",
("service_data", "expected_relevant"),
[
(
{ATTR_ENTITY_ID: "light.test"},
@ -125,14 +127,15 @@ async def test_remove_redundant_attributes(
],
)
async def test_has_relevant_service_data_attributes(
service_data: ServiceData, expected_relevant: bool
service_data: ServiceData,
expected_relevant: bool,
):
"""Test the determination of relevancy of service data"""
assert _has_relevant_service_data_attributes(service_data) == expected_relevant
@pytest.mark.parametrize(
"service_datas,filter_by_state,service_datas_expected",
("service_datas", "filter_by_state", "service_datas_expected"),
[
(
[{ATTR_ENTITY_ID: "light.test"}],
@ -198,11 +201,12 @@ async def test_create_service_call_data_iterator(
hass_states_mock,
):
"""Test the generator function for correct enumeration and filtering."""
generated_service_datas = [
data
async for data in _create_service_call_data_iterator(
hass_states_mock, service_datas, filter_by_state
hass_states_mock,
service_datas,
filter_by_state,
)
]
@ -215,7 +219,13 @@ async def test_create_service_call_data_iterator(
@pytest.mark.parametrize(
"service_data,split,filter_by_state,service_datas_expected,sleep_time_expected",
(
"service_data",
"split",
"filter_by_state",
"service_datas_expected",
"sleep_time_expected",
),
[
(
{
@ -230,7 +240,7 @@ async def test_create_service_call_data_iterator(
ATTR_ENTITY_ID: "light.test",
ATTR_BRIGHTNESS: 10,
ATTR_COLOR_TEMP_KELVIN: 4000,
}
},
],
1.2,
),
@ -266,7 +276,7 @@ async def test_create_service_call_data_iterator(
{
ATTR_ENTITY_ID: "light.test",
ATTR_COLOR_TEMP_KELVIN: 4000,
}
},
],
1.2,
),
@ -282,7 +292,7 @@ async def test_create_service_call_data_iterator(
{
ATTR_ENTITY_ID: "light.test",
ATTR_COLOR_TEMP_KELVIN: 4000,
}
},
],
0.7,
),