Enable Ruff PT006 (#88165)

* Enable Ruff PT006

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
This commit is contained in:
Franck Nijhof 2023-02-15 14:09:50 +01:00 committed by GitHub
parent 6f38bc274a
commit ed79265843
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
411 changed files with 1532 additions and 1123 deletions

View file

@ -77,7 +77,7 @@ async def test_get_conditions(
@pytest.mark.parametrize(
"hidden_by,entity_category",
("hidden_by", "entity_category"),
(
(RegistryEntryHider.INTEGRATION, None),
(RegistryEntryHider.USER, None),
@ -167,7 +167,7 @@ async def test_get_conditions_no_state(hass, device_registry, entity_registry):
@pytest.mark.parametrize(
"state_class,unit,condition_types",
("state_class", "unit", "condition_types"),
(
(SensorStateClass.MEASUREMENT, None, ["is_value"]),
(SensorStateClass.TOTAL, None, ["is_value"]),
@ -217,7 +217,7 @@ async def test_get_conditions_no_unit_or_stateclass(
@pytest.mark.parametrize(
"set_state,device_class_reg,device_class_state,unit_reg,unit_state",
("set_state", "device_class_reg", "device_class_state", "unit_reg", "unit_state"),
[
(False, SensorDeviceClass.BATTERY, None, PERCENTAGE, None),
(True, None, SensorDeviceClass.BATTERY, None, PERCENTAGE),

View file

@ -81,7 +81,7 @@ async def test_get_triggers(
@pytest.mark.parametrize(
"hidden_by,entity_category",
("hidden_by", "entity_category"),
(
(RegistryEntryHider.INTEGRATION, None),
(RegistryEntryHider.USER, None),
@ -130,7 +130,7 @@ async def test_get_triggers_hidden_auxiliary(
@pytest.mark.parametrize(
"state_class,unit,trigger_types",
("state_class", "unit", "trigger_types"),
(
(SensorStateClass.MEASUREMENT, None, ["value"]),
(SensorStateClass.TOTAL, None, ["value"]),
@ -180,7 +180,7 @@ async def test_get_triggers_no_unit_or_stateclass(
@pytest.mark.parametrize(
"set_state,device_class_reg,device_class_state,unit_reg,unit_state",
("set_state", "device_class_reg", "device_class_state", "unit_reg", "unit_state"),
[
(False, SensorDeviceClass.BATTERY, None, PERCENTAGE, None),
(True, None, SensorDeviceClass.BATTERY, None, PERCENTAGE),

View file

@ -39,7 +39,7 @@ from tests.common import mock_restore_cache_with_extra_data
@pytest.mark.parametrize(
"unit_system,native_unit,state_unit,native_value,state_value",
("unit_system", "native_unit", "state_unit", "native_value", "state_value"),
[
(
US_CUSTOMARY_SYSTEM,
@ -199,7 +199,7 @@ async def test_datetime_conversion(hass, caplog, enable_custom_integrations):
@pytest.mark.parametrize(
"device_class,state_value,provides",
("device_class", "state_value", "provides"),
[
(SensorDeviceClass.DATE, "2021-01-09", "date"),
(SensorDeviceClass.TIMESTAMP, "2021-01-09T12:00:00+00:00", "datetime"),
@ -283,7 +283,7 @@ RESTORE_DATA = {
# None | str | int | float | date | datetime | Decimal:
@pytest.mark.parametrize(
"native_value, native_value_type, expected_extra_data, device_class, uom",
("native_value", "native_value_type", "expected_extra_data", "device_class", "uom"),
[
("abc123", str, RESTORE_DATA["str"], None, None),
(
@ -353,7 +353,7 @@ async def test_restore_sensor_save_state(
@pytest.mark.parametrize(
"native_value, native_value_type, extra_data, device_class, uom",
("native_value", "native_value_type", "extra_data", "device_class", "uom"),
[
("abc123", str, RESTORE_DATA["str"], None, None),
(123, int, RESTORE_DATA["int"], SensorDeviceClass.TEMPERATURE, "°F"),
@ -418,7 +418,14 @@ async def test_restore_sensor_restore_state(
@pytest.mark.parametrize(
"device_class, native_unit, custom_unit, state_unit, native_value, custom_state",
(
"device_class",
"native_unit",
"custom_unit",
"state_unit",
"native_value",
"custom_state",
),
[
# Smaller to larger unit, InHg is ~33x larger than hPa -> 1 more decimal
(
@ -519,7 +526,15 @@ async def test_custom_unit(
@pytest.mark.parametrize(
"native_unit, custom_unit, state_unit, native_value, native_state, custom_state, device_class",
(
"native_unit",
"custom_unit",
"state_unit",
"native_value",
"native_state",
"custom_state",
"device_class",
),
[
# Distance
(
@ -788,9 +803,19 @@ async def test_custom_unit_change(
@pytest.mark.parametrize(
"unit_system, native_unit, automatic_unit, suggested_unit, custom_unit,"
"native_value, native_state, automatic_state, suggested_state, custom_state,"
"device_class",
(
"unit_system",
"native_unit",
"automatic_unit",
"suggested_unit",
"custom_unit",
"native_value",
"native_state",
"automatic_state",
"suggested_state",
"custom_state",
"device_class",
),
[
# Distance
(
@ -921,9 +946,20 @@ async def test_unit_conversion_priority(
@pytest.mark.parametrize(
"unit_system, native_unit, automatic_unit, suggested_unit, custom_unit,"
"suggested_precision, native_value, native_state, automatic_state, suggested_state,"
"custom_state, device_class",
(
"unit_system",
"native_unit",
"automatic_unit",
"suggested_unit",
"custom_unit",
"suggested_precision",
"native_value",
"native_state",
"automatic_state",
"suggested_state",
"custom_state",
"device_class",
),
[
# Distance
(
@ -1062,7 +1098,15 @@ async def test_unit_conversion_priority_precision(
@pytest.mark.parametrize(
"unit_system, native_unit, original_unit, suggested_unit, native_value, original_value, device_class",
(
"unit_system",
"native_unit",
"original_unit",
"suggested_unit",
"native_value",
"original_value",
"device_class",
),
[
# Distance
(
@ -1143,8 +1187,15 @@ async def test_unit_conversion_priority_suggested_unit_change(
@pytest.mark.parametrize(
"unit_system, native_unit, integration_suggested_precision,"
"options_suggested_precision, native_value, device_class, extra_options",
(
"unit_system",
"native_unit",
"integration_suggested_precision",
"options_suggested_precision",
"native_value",
"device_class",
"extra_options",
),
[
# Distance
(
@ -1208,8 +1259,17 @@ async def test_suggested_precision_option(
@pytest.mark.parametrize(
"unit_system, native_unit, suggested_unit, old_precision, new_precision,"
"opt_precision, native_value, device_class, extra_options",
(
"unit_system",
"native_unit",
"suggested_unit",
"old_precision",
"new_precision",
"opt_precision",
"native_value",
"device_class",
"extra_options",
),
[
# Distance
(
@ -1301,7 +1361,14 @@ async def test_suggested_precision_option_update(
@pytest.mark.parametrize(
"unit_system, native_unit, original_unit, native_value, original_value, device_class",
(
"unit_system",
"native_unit",
"original_unit",
"native_value",
"original_value",
"device_class",
),
[
# Distance
(
@ -1552,7 +1619,7 @@ async def test_device_classes_with_invalid_unit_of_measurement(
@pytest.mark.parametrize(
"device_class,state_class,unit",
("device_class", "state_class", "unit"),
[
(SensorDeviceClass.AQI, None, None),
(None, SensorStateClass.MEASUREMENT, None),
@ -1603,7 +1670,7 @@ async def test_non_numeric_validation_warn(
@pytest.mark.parametrize(
"device_class,state_class,unit,precision", ((None, None, None, 1),)
("device_class", "state_class", "unit", "precision"), ((None, None, None, 1),)
)
@pytest.mark.parametrize(
"native_value,expected",
@ -1648,7 +1715,7 @@ async def test_non_numeric_validation_raise(
@pytest.mark.parametrize(
"device_class,state_class,unit",
("device_class", "state_class", "unit"),
[
(SensorDeviceClass.AQI, None, None),
(None, SensorStateClass.MEASUREMENT, None),
@ -1762,7 +1829,13 @@ async def test_device_classes_with_invalid_state_class(
@pytest.mark.parametrize(
"device_class,state_class,native_unit_of_measurement,suggested_precision,is_numeric",
(
"device_class",
"state_class",
"native_unit_of_measurement",
"suggested_precision",
"is_numeric",
),
[
(SensorDeviceClass.ENUM, None, None, None, False),
(SensorDeviceClass.DATE, None, None, None, False),
@ -1807,7 +1880,21 @@ async def test_numeric_state_expected_helper(
@pytest.mark.parametrize(
"unit_system_1, unit_system_2, native_unit, automatic_unit_1, automatic_unit_2, suggested_unit, custom_unit, native_value, automatic_state_1, automatic_state_2, suggested_state, custom_state, device_class",
(
"unit_system_1",
"unit_system_2",
"native_unit",
"automatic_unit_1",
"automatic_unit_2",
"suggested_unit",
"custom_unit",
"native_value",
"automatic_state_1",
"automatic_state_2",
"suggested_state",
"custom_state",
"device_class",
),
[
# Distance
(

View file

@ -93,7 +93,16 @@ def set_time_zone():
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, mean, min, max",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"mean",
"min",
"max",
),
[
(None, "%", "%", "%", "unitless", 13.050847, -10, 30),
("battery", "%", "%", "%", "unitless", 13.050847, -10, 30),
@ -177,7 +186,7 @@ def test_compile_hourly_statistics(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class",
("device_class", "state_unit", "display_unit", "statistics_unit", "unit_class"),
[
(None, "%", "%", "%", "unitless"),
],
@ -897,7 +906,17 @@ def test_compile_hourly_sum_statistics_nan_inf_state(
@pytest.mark.parametrize(
"entity_id, device_class, state_unit, display_unit, statistics_unit, unit_class, offset, warning_1, warning_2",
(
"entity_id",
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"offset",
"warning_1",
"warning_2",
),
[
(
"sensor.test1",
@ -1030,7 +1049,14 @@ def test_compile_hourly_sum_statistics_negative_state(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, factor",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"factor",
),
[
("energy", "kWh", "kWh", "kWh", "energy", 1),
("energy", "Wh", "Wh", "Wh", "energy", 1),
@ -1134,7 +1160,14 @@ def test_compile_hourly_sum_statistics_total_no_reset(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, factor",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"factor",
),
[
("energy", "kWh", "kWh", "kWh", "energy", 1),
("energy", "Wh", "Wh", "Wh", "energy", 1),
@ -1239,7 +1272,14 @@ def test_compile_hourly_sum_statistics_total_increasing(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, factor",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"factor",
),
[("energy", "kWh", "kWh", "kWh", "energy", 1)],
)
def test_compile_hourly_sum_statistics_total_increasing_small_dip(
@ -1619,7 +1659,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
@pytest.mark.parametrize(
"device_class,state_unit,value",
("device_class", "state_unit", "value"),
[
("battery", "%", 30),
("battery", None, 30),
@ -1712,7 +1752,7 @@ def test_compile_hourly_statistics_partially_unavailable(hass_recorder, caplog):
@pytest.mark.parametrize(
"device_class,state_unit,value",
("device_class", "state_unit", "value"),
[
("battery", "%", 30),
("battery", None, 30),
@ -1796,7 +1836,15 @@ def test_compile_hourly_statistics_fails(hass_recorder, caplog):
@pytest.mark.parametrize(
"state_class, device_class, state_unit, display_unit, statistics_unit, unit_class, statistic_type",
(
"state_class",
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"statistic_type",
),
[
("measurement", "battery", "%", "%", "%", "unitless", "mean"),
("measurement", "battery", None, None, None, "unitless", "mean"),
@ -1919,7 +1967,7 @@ def test_list_statistic_ids_unsupported(hass_recorder, caplog, _attributes):
@pytest.mark.parametrize(
"device_class, state_unit, state_unit2, unit_class, mean, min, max",
("device_class", "state_unit", "state_unit2", "unit_class", "mean", "min", "max"),
[
(None, None, "cats", "unitless", 13.050847, -10, 30),
(None, "%", "cats", "unitless", 13.050847, -10, 30),
@ -2038,7 +2086,16 @@ def test_compile_hourly_statistics_changing_units_1(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, mean, min, max",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"mean",
"min",
"max",
),
[
(None, "dogs", "dogs", "dogs", None, 13.050847, -10, 30),
],
@ -2102,7 +2159,16 @@ def test_compile_hourly_statistics_changing_units_2(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, mean, min, max",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"mean",
"min",
"max",
),
[
(None, "dogs", "dogs", "dogs", None, 13.050847, -10, 30),
],
@ -2216,7 +2282,7 @@ def test_compile_hourly_statistics_changing_units_3(
@pytest.mark.parametrize(
"state_unit_1, state_unit_2, unit_class, mean, min, max, factor",
("state_unit_1", "state_unit_2", "unit_class", "mean", "min", "max", "factor"),
[
(None, "%", "unitless", 13.050847, -10, 30, 100),
("%", None, "unitless", 13.050847, -10, 30, 0.01),
@ -2342,7 +2408,17 @@ def test_compile_hourly_statistics_convert_units_1(
@pytest.mark.parametrize(
"device_class, state_unit, state_unit2, unit_class, unit_class2, mean, mean2, min, max",
(
"device_class",
"state_unit",
"state_unit2",
"unit_class",
"unit_class2",
"mean",
"mean2",
"min",
"max",
),
[
(None, "RPM", "rpm", None, None, 13.050847, 13.333333, -10, 30),
(None, "rpm", "RPM", None, None, 13.050847, 13.333333, -10, 30),
@ -2462,7 +2538,7 @@ def test_compile_hourly_statistics_equivalent_units_1(
@pytest.mark.parametrize(
"device_class, state_unit, state_unit2, unit_class, mean, min, max",
("device_class", "state_unit", "state_unit2", "unit_class", "mean", "min", "max"),
[
(None, "RPM", "rpm", None, 13.333333, -10, 30),
(None, "rpm", "RPM", None, 13.333333, -10, 30),
@ -2539,7 +2615,16 @@ def test_compile_hourly_statistics_equivalent_units_2(
@pytest.mark.parametrize(
"device_class, state_unit, statistic_unit, unit_class, mean1, mean2, min, max",
(
"device_class",
"state_unit",
"statistic_unit",
"unit_class",
"mean1",
"mean2",
"min",
"max",
),
[
("power", "kW", "kW", "power", 13.050847, 13.333333, -10, 30),
],
@ -2727,7 +2812,17 @@ def test_compile_hourly_statistics_changing_device_class_1(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistic_unit, unit_class, mean, mean2, min, max",
(
"device_class",
"state_unit",
"display_unit",
"statistic_unit",
"unit_class",
"mean",
"mean2",
"min",
"max",
),
[
("power", "kW", "kW", "kW", "power", 13.050847, 13.333333, -10, 30),
],
@ -2852,7 +2947,16 @@ def test_compile_hourly_statistics_changing_device_class_2(
@pytest.mark.parametrize(
"device_class, state_unit, display_unit, statistics_unit, unit_class, mean, min, max",
(
"device_class",
"state_unit",
"display_unit",
"statistics_unit",
"unit_class",
"mean",
"min",
"max",
),
[
(None, None, None, None, "unitless", 13.050847, -10, 30),
],
@ -3440,7 +3544,7 @@ def record_states(hass, zero, entity_id, attributes, seq=None):
@pytest.mark.parametrize(
"units, attributes, unit, unit2, supported_unit",
("units", "attributes", "unit", "unit2", "supported_unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
@ -3578,7 +3682,7 @@ async def test_validate_unit_change_convertible(
@pytest.mark.parametrize(
"units, attributes",
("units", "attributes"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES),
],
@ -3632,7 +3736,7 @@ async def test_validate_statistics_unit_ignore_device_class(
@pytest.mark.parametrize(
"units, attributes, unit, unit2, supported_unit",
("units", "attributes", "unit", "unit2", "supported_unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
@ -3777,7 +3881,7 @@ async def test_validate_statistics_unit_change_no_device_class(
@pytest.mark.parametrize(
"units, attributes, unit",
("units", "attributes", "unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
@ -3841,7 +3945,7 @@ async def test_validate_statistics_unsupported_state_class(
@pytest.mark.parametrize(
"units, attributes, unit",
("units", "attributes", "unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
@ -3904,7 +4008,7 @@ async def test_validate_statistics_sensor_no_longer_recorded(
@pytest.mark.parametrize(
"units, attributes, unit",
("units", "attributes", "unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
@ -3964,7 +4068,7 @@ async def test_validate_statistics_sensor_not_recorded(
@pytest.mark.parametrize(
"units, attributes, unit",
("units", "attributes", "unit"),
[
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
@ -4022,7 +4126,7 @@ async def test_validate_statistics_sensor_removed(
@pytest.mark.parametrize(
"attributes, unit1, unit2",
("attributes", "unit1", "unit2"),
[
(BATTERY_SENSOR_ATTRIBUTES, "cats", "dogs"),
(NONE_SENSOR_ATTRIBUTES, "cats", "dogs"),
@ -4147,7 +4251,7 @@ async def test_validate_statistics_unit_change_no_conversion(
@pytest.mark.parametrize(
"attributes, unit1, unit2",
("attributes", "unit1", "unit2"),
[
(NONE_SENSOR_ATTRIBUTES, "m3", ""),
(NONE_SENSOR_ATTRIBUTES, "rpm", "RPM"),
@ -4228,7 +4332,7 @@ async def test_validate_statistics_unit_change_equivalent_units(
@pytest.mark.parametrize(
"attributes, unit1, unit2, supported_unit",
("attributes", "unit1", "unit2", "supported_unit"),
[
(NONE_SENSOR_ATTRIBUTES, "", "m3", "CCF, L, fl. oz., ft³, gal, mL, m³"),
],

View file

@ -32,7 +32,7 @@ TEMP_FREEDOM_ATTRS = {
@pytest.mark.parametrize(
"old_state,new_state,attrs,result",
("old_state", "new_state", "attrs", "result"),
[
("0", "1", AQI_ATTRS, True),
("1", "0", AQI_ATTRS, True),