Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests.common.ANY #84240

Merged
merged 1 commit into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/common.py
Expand Up @@ -1303,6 +1303,38 @@ def assert_lists_same(a, b):
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):
"""Raise for mocks."""
if isinstance(val, Mock):
Expand Down
3 changes: 1 addition & 2 deletions tests/components/config/test_entity_registry.py
@@ -1,6 +1,4 @@
"""Test entity_registry API."""
from unittest.mock import ANY

import pytest

from homeassistant.components.config import entity_registry
Expand All @@ -15,6 +13,7 @@
)

from tests.common import (
ANY,
MockConfigEntry,
MockEntity,
MockEntityPlatform,
Expand Down