mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Adjust IntFlag handling in syrupy (#90223)
This commit is contained in:
parent
f8431278c8
commit
e0ec3488d3
@ -125,6 +125,7 @@ tests: &tests
|
||||
- tests/mock/**
|
||||
- tests/pylint/**
|
||||
- tests/scripts/**
|
||||
- tests/syrupy.py
|
||||
- tests/test_util/**
|
||||
- tests/testing_config/**
|
||||
- tests/util/**
|
||||
|
@ -23,7 +23,7 @@
|
||||
'supported_color_modes': list([
|
||||
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||
]),
|
||||
'supported_features': 0,
|
||||
'supported_features': <LightEntityFeature: 0>,
|
||||
'xy_color': tuple(
|
||||
0.465,
|
||||
0.376,
|
||||
@ -130,7 +130,7 @@
|
||||
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||
<ColorMode.HS: 'hs'>,
|
||||
]),
|
||||
'supported_features': 0,
|
||||
'supported_features': <LightEntityFeature: 0>,
|
||||
'xy_color': tuple(
|
||||
0.465,
|
||||
0.376,
|
||||
@ -236,7 +236,7 @@
|
||||
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||
<ColorMode.HS: 'hs'>,
|
||||
]),
|
||||
'supported_features': 0,
|
||||
'supported_features': <LightEntityFeature: 0>,
|
||||
'xy_color': tuple(
|
||||
0.34,
|
||||
0.327,
|
||||
|
@ -111,10 +111,10 @@ class HomeAssistantSnapshotSerializer(AmberDataSerializer):
|
||||
serializable_data = cls._serializable_config_entry(data)
|
||||
elif dataclasses.is_dataclass(data):
|
||||
serializable_data = dataclasses.asdict(data)
|
||||
elif isinstance(data, IntFlag) and data == 0:
|
||||
elif isinstance(data, IntFlag):
|
||||
# The repr of an enum.IntFlag has changed between Python 3.10 and 3.11
|
||||
# This only concerns the 0 case, which we normalize here
|
||||
serializable_data = 0
|
||||
# so we normalize it here.
|
||||
serializable_data = _IntFlagWrapper(data)
|
||||
else:
|
||||
serializable_data = data
|
||||
with suppress(TypeError):
|
||||
@ -201,6 +201,17 @@ class HomeAssistantSnapshotSerializer(AmberDataSerializer):
|
||||
)
|
||||
|
||||
|
||||
class _IntFlagWrapper:
|
||||
def __init__(self, flag: IntFlag) -> None:
|
||||
self._flag = flag
|
||||
|
||||
def __repr__(self) -> str:
|
||||
# 3.10: <ClimateEntityFeature.SWING_MODE|PRESET_MODE|FAN_MODE|TARGET_TEMPERATURE: 57>
|
||||
# 3.11: <ClimateEntityFeature.TARGET_TEMPERATURE|FAN_MODE|PRESET_MODE|SWING_MODE: 57>
|
||||
# Syrupy: <ClimateEntityFeature: 57>
|
||||
return f"<{self._flag.__class__.__name__}: {self._flag.value}>"
|
||||
|
||||
|
||||
class HomeAssistantSnapshotExtension(AmberSnapshotExtension):
|
||||
"""Home Assistant extension for Syrupy."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user