2022-08-30 00:45:27 +00:00
|
|
|
"""Test variance method."""
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.util.variance import ignore_variance
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-02-15 13:09:50 +00:00
|
|
|
("value_1", "value_2", "variance", "expected"),
|
2022-08-30 00:45:27 +00:00
|
|
|
[
|
|
|
|
(1, 1, 1, 1),
|
|
|
|
(1, 2, 2, 1),
|
|
|
|
(1, 2, 0, 2),
|
|
|
|
(2, 1, 0, 1),
|
|
|
|
(
|
|
|
|
datetime(2020, 1, 1, 0, 0),
|
|
|
|
datetime(2020, 1, 2, 0, 0),
|
|
|
|
timedelta(days=2),
|
|
|
|
datetime(2020, 1, 1, 0, 0),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
datetime(2020, 1, 2, 0, 0),
|
|
|
|
datetime(2020, 1, 1, 0, 0),
|
|
|
|
timedelta(days=2),
|
|
|
|
datetime(2020, 1, 2, 0, 0),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
datetime(2020, 1, 1, 0, 0),
|
|
|
|
datetime(2020, 1, 2, 0, 0),
|
|
|
|
timedelta(days=1),
|
|
|
|
datetime(2020, 1, 2, 0, 0),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2023-02-20 10:42:56 +00:00
|
|
|
def test_ignore_variance(value_1, value_2, variance, expected) -> None:
|
2022-08-30 00:45:27 +00:00
|
|
|
"""Test ignore_variance."""
|
|
|
|
with_ignore = ignore_variance(lambda x: x, variance)
|
|
|
|
assert with_ignore(value_1) == value_1
|
|
|
|
assert with_ignore(value_2) == expected
|