mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Migrates tests to use UnitOfPressure enum (#86785)
This commit is contained in:
@@ -1,38 +1,29 @@
|
||||
"""Test Home Assistant pressure utility functions."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import (
|
||||
PRESSURE_CBAR,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_MBAR,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_PA,
|
||||
PRESSURE_PSI,
|
||||
)
|
||||
from homeassistant.const import UnitOfPressure
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.util.pressure as pressure_util
|
||||
|
||||
INVALID_SYMBOL = "bob"
|
||||
VALID_SYMBOL = PRESSURE_PA
|
||||
VALID_SYMBOL = UnitOfPressure.PA
|
||||
|
||||
|
||||
def test_raise_deprecation_warning(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Ensure that a warning is raised on use of convert."""
|
||||
assert pressure_util.convert(2, PRESSURE_PA, PRESSURE_PA) == 2
|
||||
assert pressure_util.convert(2, UnitOfPressure.PA, UnitOfPressure.PA) == 2
|
||||
assert "use unit_conversion.PressureConverter instead" in caplog.text
|
||||
|
||||
|
||||
def test_convert_same_unit():
|
||||
"""Test conversion from any unit to same unit."""
|
||||
assert pressure_util.convert(2, PRESSURE_PA, PRESSURE_PA) == 2
|
||||
assert pressure_util.convert(3, PRESSURE_HPA, PRESSURE_HPA) == 3
|
||||
assert pressure_util.convert(4, PRESSURE_MBAR, PRESSURE_MBAR) == 4
|
||||
assert pressure_util.convert(5, PRESSURE_INHG, PRESSURE_INHG) == 5
|
||||
assert pressure_util.convert(6, PRESSURE_KPA, PRESSURE_KPA) == 6
|
||||
assert pressure_util.convert(7, PRESSURE_CBAR, PRESSURE_CBAR) == 7
|
||||
assert pressure_util.convert(8, PRESSURE_MMHG, PRESSURE_MMHG) == 8
|
||||
assert pressure_util.convert(2, UnitOfPressure.PA, UnitOfPressure.PA) == 2
|
||||
assert pressure_util.convert(3, UnitOfPressure.HPA, UnitOfPressure.HPA) == 3
|
||||
assert pressure_util.convert(4, UnitOfPressure.MBAR, UnitOfPressure.MBAR) == 4
|
||||
assert pressure_util.convert(5, UnitOfPressure.INHG, UnitOfPressure.INHG) == 5
|
||||
assert pressure_util.convert(6, UnitOfPressure.KPA, UnitOfPressure.KPA) == 6
|
||||
assert pressure_util.convert(7, UnitOfPressure.CBAR, UnitOfPressure.CBAR) == 7
|
||||
assert pressure_util.convert(8, UnitOfPressure.MMHG, UnitOfPressure.MMHG) == 8
|
||||
|
||||
|
||||
def test_convert_invalid_unit():
|
||||
@@ -47,102 +38,102 @@ def test_convert_invalid_unit():
|
||||
def test_convert_nonnumeric_value():
|
||||
"""Test exception is thrown for nonnumeric type."""
|
||||
with pytest.raises(TypeError):
|
||||
pressure_util.convert("a", PRESSURE_HPA, PRESSURE_INHG)
|
||||
pressure_util.convert("a", UnitOfPressure.HPA, UnitOfPressure.INHG)
|
||||
|
||||
|
||||
def test_convert_from_hpascals():
|
||||
"""Test conversion from hPA to other units."""
|
||||
hpascals = 1000
|
||||
assert pressure_util.convert(hpascals, PRESSURE_HPA, PRESSURE_PSI) == pytest.approx(
|
||||
14.5037743897
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
hpascals, PRESSURE_HPA, PRESSURE_INHG
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.5037743897)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.INHG
|
||||
) == pytest.approx(29.5299801647)
|
||||
assert pressure_util.convert(hpascals, PRESSURE_HPA, PRESSURE_PA) == pytest.approx(
|
||||
100000
|
||||
)
|
||||
assert pressure_util.convert(hpascals, PRESSURE_HPA, PRESSURE_KPA) == pytest.approx(
|
||||
100
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
hpascals, PRESSURE_HPA, PRESSURE_MBAR
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.PA
|
||||
) == pytest.approx(100000)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.KPA
|
||||
) == pytest.approx(100)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
hpascals, PRESSURE_HPA, PRESSURE_CBAR
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.CBAR
|
||||
) == pytest.approx(100)
|
||||
|
||||
|
||||
def test_convert_from_kpascals():
|
||||
"""Test conversion from hPA to other units."""
|
||||
kpascals = 100
|
||||
assert pressure_util.convert(kpascals, PRESSURE_KPA, PRESSURE_PSI) == pytest.approx(
|
||||
14.5037743897
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
kpascals, PRESSURE_KPA, PRESSURE_INHG
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.5037743897)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.INHG
|
||||
) == pytest.approx(29.5299801647)
|
||||
assert pressure_util.convert(kpascals, PRESSURE_KPA, PRESSURE_PA) == pytest.approx(
|
||||
100000
|
||||
)
|
||||
assert pressure_util.convert(kpascals, PRESSURE_KPA, PRESSURE_HPA) == pytest.approx(
|
||||
1000
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
kpascals, PRESSURE_KPA, PRESSURE_MBAR
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.PA
|
||||
) == pytest.approx(100000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.HPA
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, PRESSURE_KPA, PRESSURE_CBAR
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.CBAR
|
||||
) == pytest.approx(100)
|
||||
|
||||
|
||||
def test_convert_from_inhg():
|
||||
"""Test conversion from inHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_PSI) == pytest.approx(
|
||||
14.7346266155
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_KPA) == pytest.approx(
|
||||
101.59167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_HPA) == pytest.approx(
|
||||
1015.9167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_PA) == pytest.approx(
|
||||
101591.67
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_MBAR) == pytest.approx(
|
||||
1015.9167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_CBAR) == pytest.approx(
|
||||
101.59167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_MMHG) == pytest.approx(
|
||||
762
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.7346266155)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.KPA
|
||||
) == pytest.approx(101.59167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.HPA
|
||||
) == pytest.approx(1015.9167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.PA
|
||||
) == pytest.approx(101591.67)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1015.9167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.CBAR
|
||||
) == pytest.approx(101.59167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.MMHG
|
||||
) == pytest.approx(762)
|
||||
|
||||
|
||||
def test_convert_from_mmhg():
|
||||
"""Test conversion from mmHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_PSI) == pytest.approx(
|
||||
0.580103
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_KPA) == pytest.approx(
|
||||
3.99967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_HPA) == pytest.approx(
|
||||
39.9967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_PA) == pytest.approx(
|
||||
3999.67
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_MBAR) == pytest.approx(
|
||||
39.9967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_CBAR) == pytest.approx(
|
||||
3.99967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_INHG) == pytest.approx(
|
||||
1.181102
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.PSI
|
||||
) == pytest.approx(0.580103)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.KPA
|
||||
) == pytest.approx(3.99967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.HPA
|
||||
) == pytest.approx(39.9967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.PA
|
||||
) == pytest.approx(3999.67)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.MBAR
|
||||
) == pytest.approx(39.9967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.CBAR
|
||||
) == pytest.approx(3.99967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.INHG
|
||||
) == pytest.approx(1.181102)
|
||||
|
||||
Reference in New Issue
Block a user