From f83c33540924e8dea809621fee60b9c07b85bafc Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 23 Aug 2023 22:21:24 +0200 Subject: [PATCH] Use snapshot assertion for Environment Canada diagnostics test (#98912) --- .../fixtures/config_entry_data.json | 110 ----------------- .../snapshots/test_diagnostics.ambr | 113 ++++++++++++++++++ .../environment_canada/test_diagnostics.py | 11 +- 3 files changed, 119 insertions(+), 115 deletions(-) delete mode 100644 tests/components/environment_canada/fixtures/config_entry_data.json create mode 100644 tests/components/environment_canada/snapshots/test_diagnostics.ambr diff --git a/tests/components/environment_canada/fixtures/config_entry_data.json b/tests/components/environment_canada/fixtures/config_entry_data.json deleted file mode 100644 index 085a3394dce..00000000000 --- a/tests/components/environment_canada/fixtures/config_entry_data.json +++ /dev/null @@ -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." - } - } -} diff --git a/tests/components/environment_canada/snapshots/test_diagnostics.ambr b/tests/components/environment_canada/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..94ed1d88201 --- /dev/null +++ b/tests/components/environment_canada/snapshots/test_diagnostics.ambr @@ -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, + }), + }), + }) +# --- diff --git a/tests/components/environment_canada/test_diagnostics.py b/tests/components/environment_canada/test_diagnostics.py index 6044c9e778b..3eedb7a0ddb 100644 --- a/tests/components/environment_canada/test_diagnostics.py +++ b/tests/components/environment_canada/test_diagnostics.py @@ -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