Improve tests of inheriting entity descriptions (#106647)

pull/106645/head
Erik Montnemery 2023-12-29 13:22:52 +01:00 committed by GitHub
parent 95d7a66c16
commit 56a58f9285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 380 additions and 10 deletions

View File

@ -42,17 +42,99 @@
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.11
"test_extending_entity_description.<locals>.CustomInitEntityDescription(key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None)"
"test_extending_entity_description.<locals>.ComplexEntityDescription1C(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.12
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.13
"test_extending_entity_description.<locals>.ComplexEntityDescription1D(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.14
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.15
"test_extending_entity_description.<locals>.ComplexEntityDescription2A(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.16
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.17
"test_extending_entity_description.<locals>.ComplexEntityDescription2B(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.18
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.19
"test_extending_entity_description.<locals>.ComplexEntityDescription2C(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.2
dict({
@ -70,9 +152,127 @@
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.20
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.21
"test_extending_entity_description.<locals>.ComplexEntityDescription2D(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.22
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.23
"test_extending_entity_description.<locals>.ComplexEntityDescription3A(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.24
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.25
"test_extending_entity_description.<locals>.ComplexEntityDescription3B(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.26
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.27
"test_extending_entity_description.<locals>.ComplexEntityDescription4A(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.28
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'extra': 'foo',
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'mixin': 'mixin',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.29
"test_extending_entity_description.<locals>.ComplexEntityDescription4B(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.3
"test_extending_entity_description.<locals>.ThawedEntityDescription(key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.30
dict({
'device_class': None,
'entity_category': None,
'entity_registry_enabled_default': True,
'entity_registry_visible_default': True,
'force_update': False,
'has_entity_name': False,
'icon': None,
'key': 'blah',
'name': 'name',
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_extending_entity_description.31
"test_extending_entity_description.<locals>.CustomInitEntityDescription(key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None)"
# ---
# name: test_extending_entity_description.4
dict({
'device_class': None,
@ -111,7 +311,7 @@
})
# ---
# name: test_extending_entity_description.7
"test_extending_entity_description.<locals>.ComplexEntityDescription1(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
"test_extending_entity_description.<locals>.ComplexEntityDescription1A(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---
# name: test_extending_entity_description.8
dict({
@ -131,5 +331,5 @@
})
# ---
# name: test_extending_entity_description.9
"test_extending_entity_description.<locals>.ComplexEntityDescription2(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
"test_extending_entity_description.<locals>.ComplexEntityDescription1B(mixin='mixin', key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
# ---

View File

@ -1716,31 +1716,201 @@ def test_extending_entity_description(snapshot: SnapshotAssertion):
# Try multiple direct parents
@dataclasses.dataclass(frozen=True)
class MyMixin:
class MyMixin1:
mixin: str
@dataclasses.dataclass
class MyMixin2:
mixin: str
@dataclasses.dataclass(frozen=True)
class MyMixin3:
mixin: str = None
@dataclasses.dataclass
class MyMixin4:
mixin: str = None
@dataclasses.dataclass(frozen=True, kw_only=True)
class ComplexEntityDescription1(MyMixin, entity.EntityDescription):
class ComplexEntityDescription1A(MyMixin1, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription1(key="blah", extra="foo", mixin="mixin", name="name")
obj = ComplexEntityDescription1A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription1(
assert obj == ComplexEntityDescription1A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(frozen=True, kw_only=True)
class ComplexEntityDescription2(entity.EntityDescription, MyMixin):
class ComplexEntityDescription1B(entity.EntityDescription, MyMixin1):
extra: str = None
obj = ComplexEntityDescription2(key="blah", extra="foo", mixin="mixin", name="name")
obj = ComplexEntityDescription1B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription2(
assert obj == ComplexEntityDescription1B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(frozen=True)
class ComplexEntityDescription1C(MyMixin1, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription1C(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription1C(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(frozen=True)
class ComplexEntityDescription1D(entity.EntityDescription, MyMixin1):
extra: str = None
obj = ComplexEntityDescription1D(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription1D(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(kw_only=True)
class ComplexEntityDescription2A(MyMixin2, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription2A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription2A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(kw_only=True)
class ComplexEntityDescription2B(entity.EntityDescription, MyMixin2):
extra: str = None
obj = ComplexEntityDescription2B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription2B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass
class ComplexEntityDescription2C(MyMixin2, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription2C(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription2C(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass
class ComplexEntityDescription2D(entity.EntityDescription, MyMixin2):
extra: str = None
obj = ComplexEntityDescription2D(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription2D(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(frozen=True, kw_only=True)
class ComplexEntityDescription3A(MyMixin3, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription3A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription3A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(frozen=True, kw_only=True)
class ComplexEntityDescription3B(entity.EntityDescription, MyMixin3):
extra: str = None
obj = ComplexEntityDescription3B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription3B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
with pytest.raises(TypeError):
@dataclasses.dataclass(frozen=True)
class ComplexEntityDescription3C(MyMixin3, entity.EntityDescription):
extra: str = None
with pytest.raises(TypeError):
@dataclasses.dataclass(frozen=True)
class ComplexEntityDescription3D(entity.EntityDescription, MyMixin3):
extra: str = None
@dataclasses.dataclass(kw_only=True)
class ComplexEntityDescription4A(MyMixin4, entity.EntityDescription):
extra: str = None
obj = ComplexEntityDescription4A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription4A(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
@dataclasses.dataclass(kw_only=True)
class ComplexEntityDescription4B(entity.EntityDescription, MyMixin4):
extra: str = None
obj = ComplexEntityDescription4B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert obj == snapshot
assert obj == ComplexEntityDescription4B(
key="blah", extra="foo", mixin="mixin", name="name"
)
assert repr(obj) == snapshot
with pytest.raises(TypeError):
@dataclasses.dataclass
class ComplexEntityDescription4C(MyMixin4, entity.EntityDescription):
extra: str = None
with pytest.raises(TypeError):
@dataclasses.dataclass
class ComplexEntityDescription4D(entity.EntityDescription, MyMixin4):
extra: str = None
# Try inheriting with custom init
@dataclasses.dataclass
class CustomInitEntityDescription(entity.EntityDescription):