Use snapshot assertion for Environment Canada diagnostics test (#98912)

This commit is contained in:
Joost Lekkerkerker 2023-08-23 22:21:24 +02:00 committed by GitHub
parent 1f0e8f93c5
commit f83c335409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 119 additions and 115 deletions

View File

@ -1,110 +0,0 @@
{
"config_entry_data": {
"latitude": "**REDACTED**",
"longitude": "**REDACTED**",
"station": "XX/1234567",
"language": "Gibberish"
},
"weather_data": {
"temperature": {
"label": "Temperature",
"value": 14.9,
"unit": "C"
},
"dewpoint": {
"label": "Dew Point",
"value": 1.4,
"unit": "C"
},
"wind_chill": {
"label": "Wind Chill",
"value": null
},
"humidex": {
"label": "Humidex",
"value": null
},
"pressure": {
"label": "Pressure",
"value": 102.7,
"unit": "kPa"
},
"tendency": {
"label": "Tendency",
"value": "falling"
},
"humidity": {
"label": "Humidity",
"value": 40,
"unit": "%"
},
"visibility": {
"label": "Visibility",
"value": 24.1,
"unit": "km"
},
"condition": {
"label": "Condition",
"value": "Mainly Sunny"
},
"wind_speed": {
"label": "Wind Speed",
"value": 1,
"unit": "km/h"
},
"wind_gust": {
"label": "Wind Gust",
"value": null
},
"wind_dir": {
"label": "Wind Direction",
"value": "N"
},
"wind_bearing": {
"label": "Wind Bearing",
"value": 0,
"unit": "degrees"
},
"high_temp": {
"label": "High Temperature",
"value": 18,
"unit": "C"
},
"low_temp": {
"label": "Low Temperature",
"value": -1,
"unit": "C"
},
"uv_index": {
"label": "UV Index",
"value": 5
},
"pop": {
"label": "Chance of Precip.",
"value": null
},
"icon_code": {
"label": "Icon Code",
"value": "01"
},
"precip_yesterday": {
"label": "Precipitation Yesterday",
"value": 0.0,
"unit": "mm"
},
"normal_high": {
"label": "Normal High Temperature",
"value": 15,
"unit": "C"
},
"normal_low": {
"label": "Normal Low Temperature",
"value": 6,
"unit": "C"
},
"text_summary": {
"label": "Forecast",
"value": "Tonight. Clear. Fog patches developing after midnight. Low minus 1 with frost."
}
}
}

View File

@ -0,0 +1,113 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'config_entry_data': dict({
'language': 'Gibberish',
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'station': 'XX/1234567',
}),
'weather_data': dict({
'condition': dict({
'label': 'Condition',
'value': 'Mainly Sunny',
}),
'dewpoint': dict({
'label': 'Dew Point',
'unit': 'C',
'value': 1.4,
}),
'high_temp': dict({
'label': 'High Temperature',
'unit': 'C',
'value': 18,
}),
'humidex': dict({
'label': 'Humidex',
'value': None,
}),
'humidity': dict({
'label': 'Humidity',
'unit': '%',
'value': 40,
}),
'icon_code': dict({
'label': 'Icon Code',
'value': '01',
}),
'low_temp': dict({
'label': 'Low Temperature',
'unit': 'C',
'value': -1,
}),
'normal_high': dict({
'label': 'Normal High Temperature',
'unit': 'C',
'value': 15,
}),
'normal_low': dict({
'label': 'Normal Low Temperature',
'unit': 'C',
'value': 6,
}),
'pop': dict({
'label': 'Chance of Precip.',
'value': None,
}),
'precip_yesterday': dict({
'label': 'Precipitation Yesterday',
'unit': 'mm',
'value': 0.0,
}),
'pressure': dict({
'label': 'Pressure',
'unit': 'kPa',
'value': 102.7,
}),
'temperature': dict({
'label': 'Temperature',
'unit': 'C',
'value': 14.9,
}),
'tendency': dict({
'label': 'Tendency',
'value': 'falling',
}),
'text_summary': dict({
'label': 'Forecast',
'value': 'Tonight. Clear. Fog patches developing after midnight. Low minus 1 with frost.',
}),
'uv_index': dict({
'label': 'UV Index',
'value': 5,
}),
'visibility': dict({
'label': 'Visibility',
'unit': 'km',
'value': 24.1,
}),
'wind_bearing': dict({
'label': 'Wind Bearing',
'unit': 'degrees',
'value': 0,
}),
'wind_chill': dict({
'label': 'Wind Chill',
'value': None,
}),
'wind_dir': dict({
'label': 'Wind Direction',
'value': 'N',
}),
'wind_gust': dict({
'label': 'Wind Gust',
'value': None,
}),
'wind_speed': dict({
'label': 'Wind Speed',
'unit': 'km/h',
'value': 1,
}),
}),
})
# ---

View File

@ -3,6 +3,8 @@ from datetime import UTC, datetime
import json
from unittest.mock import AsyncMock, MagicMock, patch
from syrupy import SnapshotAssertion
from homeassistant.components.environment_canada.const import (
CONF_LANGUAGE,
CONF_STATION,
@ -72,7 +74,9 @@ async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
async def test_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
@ -80,8 +84,5 @@ async def test_entry_diagnostics(
diagnostics = await get_diagnostics_for_config_entry(
hass, hass_client, config_entry
)
redacted_entry = json.loads(
load_fixture("environment_canada/config_entry_data.json")
)
assert diagnostics == redacted_entry
assert diagnostics == snapshot