mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add tests.common.ANY (#84240)
This commit is contained in:
parent
3405fa60ec
commit
3884e16b46
@ -1303,6 +1303,38 @@ def assert_lists_same(a, b):
|
|||||||
assert i in a
|
assert i in a
|
||||||
|
|
||||||
|
|
||||||
|
_SENTINEL = object()
|
||||||
|
|
||||||
|
|
||||||
|
class _HA_ANY:
|
||||||
|
"""A helper object that compares equal to everything.
|
||||||
|
|
||||||
|
Based on unittest.mock.ANY, but modified to not show up in pytest's equality
|
||||||
|
assertion diffs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_other = _SENTINEL
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""Test equal."""
|
||||||
|
self._other = other
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
"""Test not equal."""
|
||||||
|
self._other = other
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
"""Return repr() other to not show up in pytest quality diffs."""
|
||||||
|
if self._other is _SENTINEL:
|
||||||
|
return "<ANY>"
|
||||||
|
return repr(self._other)
|
||||||
|
|
||||||
|
|
||||||
|
ANY = _HA_ANY()
|
||||||
|
|
||||||
|
|
||||||
def raise_contains_mocks(val):
|
def raise_contains_mocks(val):
|
||||||
"""Raise for mocks."""
|
"""Raise for mocks."""
|
||||||
if isinstance(val, Mock):
|
if isinstance(val, Mock):
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""Test entity_registry API."""
|
"""Test entity_registry API."""
|
||||||
from unittest.mock import ANY
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.config import entity_registry
|
from homeassistant.components.config import entity_registry
|
||||||
@ -15,6 +13,7 @@ from homeassistant.helpers.entity_registry import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
|
ANY,
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
MockEntity,
|
MockEntity,
|
||||||
MockEntityPlatform,
|
MockEntityPlatform,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user