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

Adjust formatting in unit system tests #80958

Merged
merged 2 commits into from
Oct 25, 2022
Merged
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
106 changes: 44 additions & 62 deletions tests/util/test_unit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,76 +389,58 @@ def test_get_unit_system_invalid(key: str) -> None:


@pytest.mark.parametrize(
"unit_system, device_class, original_unit, state_unit",
"device_class, original_unit, state_unit",
(
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_FEET, LENGTH_METERS),
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_INCHES, LENGTH_MILLIMETERS),
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_MILES, LENGTH_KILOMETERS),
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_YARD, LENGTH_METERS),
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, None),
(METRIC_SYSTEM, SensorDeviceClass.DISTANCE, "very_long", None),
# Test distance conversion
(SensorDeviceClass.DISTANCE, LENGTH_FEET, LENGTH_METERS),
(SensorDeviceClass.DISTANCE, LENGTH_INCHES, LENGTH_MILLIMETERS),
(SensorDeviceClass.DISTANCE, LENGTH_MILES, LENGTH_KILOMETERS),
(SensorDeviceClass.DISTANCE, LENGTH_YARD, LENGTH_METERS),
(SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, None),
(SensorDeviceClass.DISTANCE, "very_long", None),
# Test speed conversion
(
METRIC_SYSTEM,
SensorDeviceClass.SPEED,
SPEED_FEET_PER_SECOND,
SPEED_KILOMETERS_PER_HOUR,
),
(
METRIC_SYSTEM,
SensorDeviceClass.SPEED,
SPEED_MILES_PER_HOUR,
SPEED_KILOMETERS_PER_HOUR,
),
(METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, None),
(METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_KNOTS, None),
(METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, None),
(METRIC_SYSTEM, SensorDeviceClass.SPEED, "very_fast", None),
(
US_CUSTOMARY_SYSTEM,
SensorDeviceClass.DISTANCE,
LENGTH_CENTIMETERS,
LENGTH_INCHES,
),
(
US_CUSTOMARY_SYSTEM,
SensorDeviceClass.DISTANCE,
LENGTH_KILOMETERS,
LENGTH_MILES,
),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_METERS, LENGTH_FEET),
(
US_CUSTOMARY_SYSTEM,
SensorDeviceClass.DISTANCE,
LENGTH_MILLIMETERS,
LENGTH_INCHES,
),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_MILES, None),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, "very_long", None),
(SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, SPEED_KILOMETERS_PER_HOUR),
(SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR),
(SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, None),
(SensorDeviceClass.SPEED, SPEED_KNOTS, None),
(SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, None),
(SensorDeviceClass.SPEED, "very_fast", None),
),
)
def test_get_metric_converted_unit_(
device_class: SensorDeviceClass,
original_unit: str,
state_unit: str | None,
) -> None:
"""Test unit conversion rules."""
unit_system = METRIC_SYSTEM
assert unit_system.get_converted_unit(device_class, original_unit) == state_unit


@pytest.mark.parametrize(
"device_class, original_unit, state_unit",
(
# Test distance conversion
(SensorDeviceClass.DISTANCE, LENGTH_CENTIMETERS, LENGTH_INCHES),
(SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, LENGTH_MILES),
(SensorDeviceClass.DISTANCE, LENGTH_METERS, LENGTH_FEET),
(SensorDeviceClass.DISTANCE, LENGTH_MILLIMETERS, LENGTH_INCHES),
(SensorDeviceClass.DISTANCE, LENGTH_MILES, None),
(SensorDeviceClass.DISTANCE, "very_long", None),
# Test speed conversion
(
US_CUSTOMARY_SYSTEM,
SensorDeviceClass.SPEED,
SPEED_METERS_PER_SECOND,
SPEED_MILES_PER_HOUR,
),
(
US_CUSTOMARY_SYSTEM,
SensorDeviceClass.SPEED,
SPEED_KILOMETERS_PER_HOUR,
SPEED_MILES_PER_HOUR,
),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, None),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_KNOTS, None),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, None),
(US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, "very_fast", None),
(SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR),
(SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR),
(SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, None),
(SensorDeviceClass.SPEED, SPEED_KNOTS, None),
(SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, None),
(SensorDeviceClass.SPEED, "very_fast", None),
),
)
def test_get_converted_unit(
unit_system: UnitSystem,
def test_get_us_converted_unit(
device_class: SensorDeviceClass,
original_unit: str,
state_unit: str | None,
) -> None:
"""Test unit conversion rules."""
unit_system = US_CUSTOMARY_SYSTEM
assert unit_system.get_converted_unit(device_class, original_unit) == state_unit