Cleanup pytest.approx in unit conversion tests (#84810)

pull/84864/head
epenet 2022-12-30 10:16:20 +01:00 committed by GitHub
parent 0e98e0f65f
commit f68a7636c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 116 additions and 203 deletions

View File

@ -238,107 +238,62 @@ def test_data_rate_convert(
@pytest.mark.parametrize(
"value,from_unit,expected,to_unit",
[
(5, UnitOfLength.MILES, pytest.approx(8.04672), UnitOfLength.KILOMETERS),
(5, UnitOfLength.MILES, pytest.approx(8046.72), UnitOfLength.METERS),
(5, UnitOfLength.MILES, pytest.approx(804672.0), UnitOfLength.CENTIMETERS),
(5, UnitOfLength.MILES, pytest.approx(8046720.0), UnitOfLength.MILLIMETERS),
(5, UnitOfLength.MILES, pytest.approx(8800.0), UnitOfLength.YARDS),
(5, UnitOfLength.MILES, pytest.approx(26400.0008448), UnitOfLength.FEET),
(5, UnitOfLength.MILES, pytest.approx(316800.171072), UnitOfLength.INCHES),
(
5,
UnitOfLength.YARDS,
pytest.approx(0.0045720000000000005),
UnitOfLength.KILOMETERS,
),
(5, UnitOfLength.YARDS, pytest.approx(4.572), UnitOfLength.METERS),
(5, UnitOfLength.YARDS, pytest.approx(457.2), UnitOfLength.CENTIMETERS),
(5, UnitOfLength.YARDS, pytest.approx(4572), UnitOfLength.MILLIMETERS),
(5, UnitOfLength.YARDS, pytest.approx(0.002840908212), UnitOfLength.MILES),
(5, UnitOfLength.YARDS, pytest.approx(15.00000048), UnitOfLength.FEET),
(5, UnitOfLength.YARDS, pytest.approx(180.0000972), UnitOfLength.INCHES),
(5000, UnitOfLength.FEET, pytest.approx(1.524), UnitOfLength.KILOMETERS),
(5000, UnitOfLength.FEET, pytest.approx(1524), UnitOfLength.METERS),
(5000, UnitOfLength.FEET, pytest.approx(152400.0), UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.FEET, pytest.approx(1524000.0), UnitOfLength.MILLIMETERS),
(
5000,
UnitOfLength.FEET,
pytest.approx(0.9469694040000001),
UnitOfLength.MILES,
),
(5000, UnitOfLength.FEET, pytest.approx(1666.66667), UnitOfLength.YARDS),
(
5000,
UnitOfLength.FEET,
pytest.approx(60000.032400000004),
UnitOfLength.INCHES,
),
(5000, UnitOfLength.INCHES, pytest.approx(0.127), UnitOfLength.KILOMETERS),
(5000, UnitOfLength.INCHES, pytest.approx(127.0), UnitOfLength.METERS),
(5000, UnitOfLength.INCHES, pytest.approx(12700.0), UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.INCHES, pytest.approx(127000.0), UnitOfLength.MILLIMETERS),
(5000, UnitOfLength.INCHES, pytest.approx(0.078914117), UnitOfLength.MILES),
(5000, UnitOfLength.INCHES, pytest.approx(138.88889), UnitOfLength.YARDS),
(5000, UnitOfLength.INCHES, pytest.approx(416.66668), UnitOfLength.FEET),
(5, UnitOfLength.KILOMETERS, pytest.approx(5000), UnitOfLength.METERS),
(5, UnitOfLength.KILOMETERS, pytest.approx(500000), UnitOfLength.CENTIMETERS),
(5, UnitOfLength.KILOMETERS, pytest.approx(5000000), UnitOfLength.MILLIMETERS),
(5, UnitOfLength.KILOMETERS, pytest.approx(3.106855), UnitOfLength.MILES),
(5, UnitOfLength.KILOMETERS, pytest.approx(5468.066), UnitOfLength.YARDS),
(5, UnitOfLength.KILOMETERS, pytest.approx(16404.2), UnitOfLength.FEET),
(5, UnitOfLength.KILOMETERS, pytest.approx(196850.5), UnitOfLength.INCHES),
(5000, UnitOfLength.METERS, pytest.approx(5), UnitOfLength.KILOMETERS),
(5000, UnitOfLength.METERS, pytest.approx(500000), UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.METERS, pytest.approx(5000000), UnitOfLength.MILLIMETERS),
(5000, UnitOfLength.METERS, pytest.approx(3.106855), UnitOfLength.MILES),
(5000, UnitOfLength.METERS, pytest.approx(5468.066), UnitOfLength.YARDS),
(5000, UnitOfLength.METERS, pytest.approx(16404.2), UnitOfLength.FEET),
(5000, UnitOfLength.METERS, pytest.approx(196850.5), UnitOfLength.INCHES),
(500000, UnitOfLength.CENTIMETERS, pytest.approx(5), UnitOfLength.KILOMETERS),
(500000, UnitOfLength.CENTIMETERS, pytest.approx(5000), UnitOfLength.METERS),
(
500000,
UnitOfLength.CENTIMETERS,
pytest.approx(5000000),
UnitOfLength.MILLIMETERS,
),
(500000, UnitOfLength.CENTIMETERS, pytest.approx(3.106855), UnitOfLength.MILES),
(500000, UnitOfLength.CENTIMETERS, pytest.approx(5468.066), UnitOfLength.YARDS),
(500000, UnitOfLength.CENTIMETERS, pytest.approx(16404.2), UnitOfLength.FEET),
(
500000,
UnitOfLength.CENTIMETERS,
pytest.approx(196850.5),
UnitOfLength.INCHES,
),
(5000000, UnitOfLength.MILLIMETERS, pytest.approx(5), UnitOfLength.KILOMETERS),
(5000000, UnitOfLength.MILLIMETERS, pytest.approx(5000), UnitOfLength.METERS),
(
5000000,
UnitOfLength.MILLIMETERS,
pytest.approx(500000),
UnitOfLength.CENTIMETERS,
),
(
5000000,
UnitOfLength.MILLIMETERS,
pytest.approx(3.106855),
UnitOfLength.MILES,
),
(
5000000,
UnitOfLength.MILLIMETERS,
pytest.approx(5468.066),
UnitOfLength.YARDS,
),
(5000000, UnitOfLength.MILLIMETERS, pytest.approx(16404.2), UnitOfLength.FEET),
(
5000000,
UnitOfLength.MILLIMETERS,
pytest.approx(196850.5),
UnitOfLength.INCHES,
),
(5, UnitOfLength.MILES, 8.04672, UnitOfLength.KILOMETERS),
(5, UnitOfLength.MILES, 8046.72, UnitOfLength.METERS),
(5, UnitOfLength.MILES, 804672.0, UnitOfLength.CENTIMETERS),
(5, UnitOfLength.MILES, 8046720.0, UnitOfLength.MILLIMETERS),
(5, UnitOfLength.MILES, 8800.0, UnitOfLength.YARDS),
(5, UnitOfLength.MILES, 26400.0008448, UnitOfLength.FEET),
(5, UnitOfLength.MILES, 316800.171072, UnitOfLength.INCHES),
(5, UnitOfLength.YARDS, 0.004572, UnitOfLength.KILOMETERS),
(5, UnitOfLength.YARDS, 4.572, UnitOfLength.METERS),
(5, UnitOfLength.YARDS, 457.2, UnitOfLength.CENTIMETERS),
(5, UnitOfLength.YARDS, 4572, UnitOfLength.MILLIMETERS),
(5, UnitOfLength.YARDS, 0.002840908212, UnitOfLength.MILES),
(5, UnitOfLength.YARDS, 15.00000048, UnitOfLength.FEET),
(5, UnitOfLength.YARDS, 180.0000972, UnitOfLength.INCHES),
(5000, UnitOfLength.FEET, 1.524, UnitOfLength.KILOMETERS),
(5000, UnitOfLength.FEET, 1524, UnitOfLength.METERS),
(5000, UnitOfLength.FEET, 152400.0, UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.FEET, 1524000.0, UnitOfLength.MILLIMETERS),
(5000, UnitOfLength.FEET, 0.946969404, UnitOfLength.MILES),
(5000, UnitOfLength.FEET, 1666.66667, UnitOfLength.YARDS),
(5000, UnitOfLength.FEET, 60000.0324, UnitOfLength.INCHES),
(5000, UnitOfLength.INCHES, 0.127, UnitOfLength.KILOMETERS),
(5000, UnitOfLength.INCHES, 127.0, UnitOfLength.METERS),
(5000, UnitOfLength.INCHES, 12700.0, UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.INCHES, 127000.0, UnitOfLength.MILLIMETERS),
(5000, UnitOfLength.INCHES, 0.078914117, UnitOfLength.MILES),
(5000, UnitOfLength.INCHES, 138.88889, UnitOfLength.YARDS),
(5000, UnitOfLength.INCHES, 416.66668, UnitOfLength.FEET),
(5, UnitOfLength.KILOMETERS, 5000, UnitOfLength.METERS),
(5, UnitOfLength.KILOMETERS, 500000, UnitOfLength.CENTIMETERS),
(5, UnitOfLength.KILOMETERS, 5000000, UnitOfLength.MILLIMETERS),
(5, UnitOfLength.KILOMETERS, 3.106855, UnitOfLength.MILES),
(5, UnitOfLength.KILOMETERS, 5468.066, UnitOfLength.YARDS),
(5, UnitOfLength.KILOMETERS, 16404.2, UnitOfLength.FEET),
(5, UnitOfLength.KILOMETERS, 196850.5, UnitOfLength.INCHES),
(5000, UnitOfLength.METERS, 5, UnitOfLength.KILOMETERS),
(5000, UnitOfLength.METERS, 500000, UnitOfLength.CENTIMETERS),
(5000, UnitOfLength.METERS, 5000000, UnitOfLength.MILLIMETERS),
(5000, UnitOfLength.METERS, 3.106855, UnitOfLength.MILES),
(5000, UnitOfLength.METERS, 5468.066, UnitOfLength.YARDS),
(5000, UnitOfLength.METERS, 16404.2, UnitOfLength.FEET),
(5000, UnitOfLength.METERS, 196850.5, UnitOfLength.INCHES),
(500000, UnitOfLength.CENTIMETERS, 5, UnitOfLength.KILOMETERS),
(500000, UnitOfLength.CENTIMETERS, 5000, UnitOfLength.METERS),
(500000, UnitOfLength.CENTIMETERS, 5000000, UnitOfLength.MILLIMETERS),
(500000, UnitOfLength.CENTIMETERS, 3.106855, UnitOfLength.MILES),
(500000, UnitOfLength.CENTIMETERS, 5468.066, UnitOfLength.YARDS),
(500000, UnitOfLength.CENTIMETERS, 16404.2, UnitOfLength.FEET),
(500000, UnitOfLength.CENTIMETERS, 196850.5, UnitOfLength.INCHES),
(5000000, UnitOfLength.MILLIMETERS, 5, UnitOfLength.KILOMETERS),
(5000000, UnitOfLength.MILLIMETERS, 5000, UnitOfLength.METERS),
(5000000, UnitOfLength.MILLIMETERS, 500000, UnitOfLength.CENTIMETERS),
(5000000, UnitOfLength.MILLIMETERS, 3.106855, UnitOfLength.MILES),
(5000000, UnitOfLength.MILLIMETERS, 5468.066, UnitOfLength.YARDS),
(5000000, UnitOfLength.MILLIMETERS, 16404.2, UnitOfLength.FEET),
(5000000, UnitOfLength.MILLIMETERS, 196850.5, UnitOfLength.INCHES),
],
)
def test_distance_convert(
@ -348,6 +303,7 @@ def test_distance_convert(
to_unit: str,
) -> None:
"""Test conversion to other units."""
expected = pytest.approx(expected)
assert DistanceConverter.convert(value, from_unit, to_unit) == expected
@ -406,9 +362,8 @@ def test_information_convert(
to_unit: str,
) -> None:
"""Test conversion to other units."""
assert InformationConverter.convert(value, from_unit, to_unit) == pytest.approx(
expected
)
expected = pytest.approx(expected)
assert InformationConverter.convert(value, from_unit, to_unit) == expected
@pytest.mark.parametrize(
@ -417,28 +372,23 @@ def test_information_convert(
(10, UnitOfMass.KILOGRAMS, 10000, UnitOfMass.GRAMS),
(10, UnitOfMass.KILOGRAMS, 10000000, UnitOfMass.MILLIGRAMS),
(10, UnitOfMass.KILOGRAMS, 10000000000, UnitOfMass.MICROGRAMS),
(10, UnitOfMass.KILOGRAMS, pytest.approx(352.73961), UnitOfMass.OUNCES),
(10, UnitOfMass.KILOGRAMS, pytest.approx(22.046226), UnitOfMass.POUNDS),
(10, UnitOfMass.KILOGRAMS, 352.73961, UnitOfMass.OUNCES),
(10, UnitOfMass.KILOGRAMS, 22.046226, UnitOfMass.POUNDS),
(10, UnitOfMass.GRAMS, 0.01, UnitOfMass.KILOGRAMS),
(10, UnitOfMass.GRAMS, 10000, UnitOfMass.MILLIGRAMS),
(10, UnitOfMass.GRAMS, 10000000, UnitOfMass.MICROGRAMS),
(10, UnitOfMass.GRAMS, pytest.approx(0.35273961), UnitOfMass.OUNCES),
(10, UnitOfMass.GRAMS, pytest.approx(0.022046226), UnitOfMass.POUNDS),
(10, UnitOfMass.GRAMS, 0.35273961, UnitOfMass.OUNCES),
(10, UnitOfMass.GRAMS, 0.022046226, UnitOfMass.POUNDS),
(10, UnitOfMass.MILLIGRAMS, 0.00001, UnitOfMass.KILOGRAMS),
(10, UnitOfMass.MILLIGRAMS, 0.01, UnitOfMass.GRAMS),
(10, UnitOfMass.MILLIGRAMS, 10000, UnitOfMass.MICROGRAMS),
(10, UnitOfMass.MILLIGRAMS, pytest.approx(0.00035273961), UnitOfMass.OUNCES),
(10, UnitOfMass.MILLIGRAMS, pytest.approx(0.000022046226), UnitOfMass.POUNDS),
(10, UnitOfMass.MILLIGRAMS, 0.00035273961, UnitOfMass.OUNCES),
(10, UnitOfMass.MILLIGRAMS, 0.000022046226, UnitOfMass.POUNDS),
(10000, UnitOfMass.MICROGRAMS, 0.00001, UnitOfMass.KILOGRAMS),
(10000, UnitOfMass.MICROGRAMS, 0.01, UnitOfMass.GRAMS),
(10000, UnitOfMass.MICROGRAMS, 10, UnitOfMass.MILLIGRAMS),
(10000, UnitOfMass.MICROGRAMS, pytest.approx(0.00035273961), UnitOfMass.OUNCES),
(
10000,
UnitOfMass.MICROGRAMS,
pytest.approx(0.000022046226),
UnitOfMass.POUNDS,
),
(10000, UnitOfMass.MICROGRAMS, 0.00035273961, UnitOfMass.OUNCES),
(10000, UnitOfMass.MICROGRAMS, 0.000022046226, UnitOfMass.POUNDS),
(1, UnitOfMass.POUNDS, 0.45359237, UnitOfMass.KILOGRAMS),
(1, UnitOfMass.POUNDS, 453.59237, UnitOfMass.GRAMS),
(1, UnitOfMass.POUNDS, 453592.37, UnitOfMass.MILLIGRAMS),
@ -449,11 +399,11 @@ def test_information_convert(
(16, UnitOfMass.OUNCES, 453592.37, UnitOfMass.MILLIGRAMS),
(16, UnitOfMass.OUNCES, 453592370, UnitOfMass.MICROGRAMS),
(16, UnitOfMass.OUNCES, 1, UnitOfMass.POUNDS),
(1, UnitOfMass.STONES, pytest.approx(6.350293), UnitOfMass.KILOGRAMS),
(1, UnitOfMass.STONES, pytest.approx(6350.293), UnitOfMass.GRAMS),
(1, UnitOfMass.STONES, pytest.approx(6350293), UnitOfMass.MILLIGRAMS),
(1, UnitOfMass.STONES, pytest.approx(14), UnitOfMass.POUNDS),
(1, UnitOfMass.STONES, pytest.approx(224), UnitOfMass.OUNCES),
(1, UnitOfMass.STONES, 6.350293, UnitOfMass.KILOGRAMS),
(1, UnitOfMass.STONES, 6350.293, UnitOfMass.GRAMS),
(1, UnitOfMass.STONES, 6350293, UnitOfMass.MILLIGRAMS),
(1, UnitOfMass.STONES, 14, UnitOfMass.POUNDS),
(1, UnitOfMass.STONES, 224, UnitOfMass.OUNCES),
],
)
def test_mass_convert(
@ -463,7 +413,7 @@ def test_mass_convert(
to_unit: str,
) -> None:
"""Test conversion to other units."""
assert MassConverter.convert(value, from_unit, to_unit) == expected
assert MassConverter.convert(value, from_unit, to_unit) == pytest.approx(expected)
@pytest.mark.parametrize(
@ -486,32 +436,32 @@ def test_power_convert(
@pytest.mark.parametrize(
"value,from_unit,expected,to_unit",
[
(1000, UnitOfPressure.HPA, pytest.approx(14.5037743897), UnitOfPressure.PSI),
(1000, UnitOfPressure.HPA, pytest.approx(29.5299801647), UnitOfPressure.INHG),
(1000, UnitOfPressure.HPA, pytest.approx(100000), UnitOfPressure.PA),
(1000, UnitOfPressure.HPA, pytest.approx(100), UnitOfPressure.KPA),
(1000, UnitOfPressure.HPA, pytest.approx(1000), UnitOfPressure.MBAR),
(1000, UnitOfPressure.HPA, pytest.approx(100), UnitOfPressure.CBAR),
(100, UnitOfPressure.KPA, pytest.approx(14.5037743897), UnitOfPressure.PSI),
(100, UnitOfPressure.KPA, pytest.approx(29.5299801647), UnitOfPressure.INHG),
(100, UnitOfPressure.KPA, pytest.approx(100000), UnitOfPressure.PA),
(100, UnitOfPressure.KPA, pytest.approx(1000), UnitOfPressure.HPA),
(100, UnitOfPressure.KPA, pytest.approx(1000), UnitOfPressure.MBAR),
(100, UnitOfPressure.KPA, pytest.approx(100), UnitOfPressure.CBAR),
(30, UnitOfPressure.INHG, pytest.approx(14.7346266155), UnitOfPressure.PSI),
(30, UnitOfPressure.INHG, pytest.approx(101.59167), UnitOfPressure.KPA),
(30, UnitOfPressure.INHG, pytest.approx(1015.9167), UnitOfPressure.HPA),
(30, UnitOfPressure.INHG, pytest.approx(101591.67), UnitOfPressure.PA),
(30, UnitOfPressure.INHG, pytest.approx(1015.9167), UnitOfPressure.MBAR),
(30, UnitOfPressure.INHG, pytest.approx(101.59167), UnitOfPressure.CBAR),
(30, UnitOfPressure.INHG, pytest.approx(762), UnitOfPressure.MMHG),
(30, UnitOfPressure.MMHG, pytest.approx(0.580103), UnitOfPressure.PSI),
(30, UnitOfPressure.MMHG, pytest.approx(3.99967), UnitOfPressure.KPA),
(30, UnitOfPressure.MMHG, pytest.approx(39.9967), UnitOfPressure.HPA),
(30, UnitOfPressure.MMHG, pytest.approx(3999.67), UnitOfPressure.PA),
(30, UnitOfPressure.MMHG, pytest.approx(39.9967), UnitOfPressure.MBAR),
(30, UnitOfPressure.MMHG, pytest.approx(3.99967), UnitOfPressure.CBAR),
(30, UnitOfPressure.MMHG, pytest.approx(1.181102), UnitOfPressure.INHG),
(1000, UnitOfPressure.HPA, 14.5037743897, UnitOfPressure.PSI),
(1000, UnitOfPressure.HPA, 29.5299801647, UnitOfPressure.INHG),
(1000, UnitOfPressure.HPA, 100000, UnitOfPressure.PA),
(1000, UnitOfPressure.HPA, 100, UnitOfPressure.KPA),
(1000, UnitOfPressure.HPA, 1000, UnitOfPressure.MBAR),
(1000, UnitOfPressure.HPA, 100, UnitOfPressure.CBAR),
(100, UnitOfPressure.KPA, 14.5037743897, UnitOfPressure.PSI),
(100, UnitOfPressure.KPA, 29.5299801647, UnitOfPressure.INHG),
(100, UnitOfPressure.KPA, 100000, UnitOfPressure.PA),
(100, UnitOfPressure.KPA, 1000, UnitOfPressure.HPA),
(100, UnitOfPressure.KPA, 1000, UnitOfPressure.MBAR),
(100, UnitOfPressure.KPA, 100, UnitOfPressure.CBAR),
(30, UnitOfPressure.INHG, 14.7346266155, UnitOfPressure.PSI),
(30, UnitOfPressure.INHG, 101.59167, UnitOfPressure.KPA),
(30, UnitOfPressure.INHG, 1015.9167, UnitOfPressure.HPA),
(30, UnitOfPressure.INHG, 101591.67, UnitOfPressure.PA),
(30, UnitOfPressure.INHG, 1015.9167, UnitOfPressure.MBAR),
(30, UnitOfPressure.INHG, 101.59167, UnitOfPressure.CBAR),
(30, UnitOfPressure.INHG, 762, UnitOfPressure.MMHG),
(30, UnitOfPressure.MMHG, 0.580103, UnitOfPressure.PSI),
(30, UnitOfPressure.MMHG, 3.99967, UnitOfPressure.KPA),
(30, UnitOfPressure.MMHG, 39.9967, UnitOfPressure.HPA),
(30, UnitOfPressure.MMHG, 3999.67, UnitOfPressure.PA),
(30, UnitOfPressure.MMHG, 39.9967, UnitOfPressure.MBAR),
(30, UnitOfPressure.MMHG, 3.99967, UnitOfPressure.CBAR),
(30, UnitOfPressure.MMHG, 1.181102, UnitOfPressure.INHG),
],
)
def test_pressure_convert(
@ -521,6 +471,7 @@ def test_pressure_convert(
to_unit: str,
) -> None:
"""Test conversion to other units."""
expected = pytest.approx(expected)
assert PressureConverter.convert(value, from_unit, to_unit) == expected
@ -528,12 +479,7 @@ def test_pressure_convert(
"value,from_unit,expected,to_unit",
[
# 5 km/h / 1.609 km/mi = 3.10686 mi/h
(
5,
UnitOfSpeed.KILOMETERS_PER_HOUR,
pytest.approx(3.106856),
UnitOfSpeed.MILES_PER_HOUR,
),
(5, UnitOfSpeed.KILOMETERS_PER_HOUR, 3.106856, UnitOfSpeed.MILES_PER_HOUR),
# 5 mi/h * 1.609 km/mi = 8.04672 km/h
(5, UnitOfSpeed.MILES_PER_HOUR, 8.04672, UnitOfSpeed.KILOMETERS_PER_HOUR),
# 5 in/day * 25.4 mm/in = 127 mm/day
@ -547,14 +493,14 @@ def test_pressure_convert(
(
5,
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
pytest.approx(0.1968504),
0.1968504,
UnitOfVolumetricFlux.INCHES_PER_DAY,
),
# 48 mm/day = 2 mm/h
(
48,
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
pytest.approx(2),
2,
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
),
# 5 in/hr * 24 hr/day = 3048 mm/day
@ -568,25 +514,20 @@ def test_pressure_convert(
(
5,
UnitOfSpeed.METERS_PER_SECOND,
pytest.approx(708661.42),
708661.42,
UnitOfVolumetricFlux.INCHES_PER_HOUR,
),
# 5000 in/h / 39.3701 in/m / 3600 s/h = 0.03528 m/s
(
5000,
UnitOfVolumetricFlux.INCHES_PER_HOUR,
pytest.approx(0.0352778),
0.0352778,
UnitOfSpeed.METERS_PER_SECOND,
),
# 5 kt * 1852 m/nmi / 3600 s/h = 2.5722 m/s
(5, UnitOfSpeed.KNOTS, pytest.approx(2.57222), UnitOfSpeed.METERS_PER_SECOND),
(5, UnitOfSpeed.KNOTS, 2.57222, UnitOfSpeed.METERS_PER_SECOND),
# 5 ft/s * 0.3048 m/ft = 1.524 m/s
(
5,
UnitOfSpeed.FEET_PER_SECOND,
pytest.approx(1.524),
UnitOfSpeed.METERS_PER_SECOND,
),
(5, UnitOfSpeed.FEET_PER_SECOND, 1.524, UnitOfSpeed.METERS_PER_SECOND),
],
)
def test_speed_convert(
@ -596,7 +537,7 @@ def test_speed_convert(
to_unit: str,
) -> None:
"""Test conversion to other units."""
assert SpeedConverter.convert(value, from_unit, to_unit) == expected
assert SpeedConverter.convert(value, from_unit, to_unit) == pytest.approx(expected)
@pytest.mark.parametrize(
@ -604,36 +545,17 @@ def test_speed_convert(
[
(100, UnitOfTemperature.CELSIUS, 212, UnitOfTemperature.FAHRENHEIT),
(100, UnitOfTemperature.CELSIUS, 373.15, UnitOfTemperature.KELVIN),
(
100,
UnitOfTemperature.FAHRENHEIT,
pytest.approx(37.77777777777778),
UnitOfTemperature.CELSIUS,
),
(
100,
UnitOfTemperature.FAHRENHEIT,
pytest.approx(310.92777777777775),
UnitOfTemperature.KELVIN,
),
(
100,
UnitOfTemperature.KELVIN,
pytest.approx(-173.15),
UnitOfTemperature.CELSIUS,
),
(
100,
UnitOfTemperature.KELVIN,
pytest.approx(-279.66999999999996),
UnitOfTemperature.FAHRENHEIT,
),
(100, UnitOfTemperature.FAHRENHEIT, 37.7778, UnitOfTemperature.CELSIUS),
(100, UnitOfTemperature.FAHRENHEIT, 310.9277, UnitOfTemperature.KELVIN),
(100, UnitOfTemperature.KELVIN, -173.15, UnitOfTemperature.CELSIUS),
(100, UnitOfTemperature.KELVIN, -279.6699, UnitOfTemperature.FAHRENHEIT),
],
)
def test_temperature_convert(
value: float, from_unit: str, expected: float, to_unit: str
) -> None:
"""Test conversion to other units."""
expected = pytest.approx(expected)
assert TemperatureConverter.convert(value, from_unit, to_unit) == expected
@ -642,18 +564,8 @@ def test_temperature_convert(
[
(100, UnitOfTemperature.CELSIUS, 180, UnitOfTemperature.FAHRENHEIT),
(100, UnitOfTemperature.CELSIUS, 100, UnitOfTemperature.KELVIN),
(
100,
UnitOfTemperature.FAHRENHEIT,
pytest.approx(55.55555555555556),
UnitOfTemperature.CELSIUS,
),
(
100,
UnitOfTemperature.FAHRENHEIT,
pytest.approx(55.55555555555556),
UnitOfTemperature.KELVIN,
),
(100, UnitOfTemperature.FAHRENHEIT, 55.5556, UnitOfTemperature.CELSIUS),
(100, UnitOfTemperature.FAHRENHEIT, 55.5556, UnitOfTemperature.KELVIN),
(100, UnitOfTemperature.KELVIN, 100, UnitOfTemperature.CELSIUS),
(100, UnitOfTemperature.KELVIN, 180, UnitOfTemperature.FAHRENHEIT),
],
@ -662,6 +574,7 @@ def test_temperature_convert_with_interval(
value: float, from_unit: str, expected: float, to_unit: str
) -> None:
"""Test conversion to other units."""
expected = pytest.approx(expected)
assert TemperatureConverter.convert_interval(value, from_unit, to_unit) == expected