Skip to content

Commit 8191742

Browse files
emontnemeryabmantisepenetjbouwh
authored
Add test which fails on duplicated statistics units (home-assistant#153202)
Co-authored-by: Abílio Costa <[email protected]> Co-authored-by: epenet <[email protected]> Co-authored-by: jbouwh <[email protected]>
1 parent bfb6270 commit 8191742

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/components/recorder/test_statistics.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
from tests.common import MockPlatform, MockUser, mock_platform
6363
from tests.typing import RecorderInstanceContextManager, WebSocketGenerator
64+
from tests.util.test_unit_conversion import _ALL_CONVERTERS
6465

6566

6667
@pytest.fixture
@@ -3740,3 +3741,24 @@ async def test_get_statistics_service_missing_mandatory_keys(
37403741
return_response=True,
37413742
blocking=True,
37423743
)
3744+
3745+
3746+
# The STATISTIC_UNIT_TO_UNIT_CONVERTER keys are sorted to ensure that pytest runs are
3747+
# consistent and avoid `different tests were collected between gw0 and gw1`
3748+
@pytest.mark.parametrize(
3749+
"uom", sorted(STATISTIC_UNIT_TO_UNIT_CONVERTER, key=lambda x: (x is None, x))
3750+
)
3751+
def test_STATISTIC_UNIT_TO_UNIT_CONVERTER(uom: str) -> None:
3752+
"""Ensure unit does not belong to multiple converters."""
3753+
unit_converter = STATISTIC_UNIT_TO_UNIT_CONVERTER[uom]
3754+
if other := next(
3755+
(
3756+
c
3757+
for c in _ALL_CONVERTERS
3758+
if unit_converter is not c and uom in c.VALID_UNITS
3759+
),
3760+
None,
3761+
):
3762+
pytest.fail(
3763+
f"{uom} is present in both {other.__name__} and {unit_converter.__name__}"
3764+
)

0 commit comments

Comments
 (0)