From 8570b19db24a73ca689c5590e98bd8bf489881a6 Mon Sep 17 00:00:00 2001 From: Andrey Khrolenok Date: Thu, 9 Feb 2023 00:15:41 +0300 Subject: [PATCH] Update tests --- custom_components/gismeteo/__init__.py | 4 ++-- custom_components/gismeteo/api.py | 11 ++++++----- custom_components/gismeteo/config_flow.py | 8 ++++---- custom_components/gismeteo/const.py | 6 ++---- custom_components/gismeteo/entity.py | 3 +-- custom_components/gismeteo/sensor.py | 4 ++-- .../gismeteo/translations/sensor.pt-BR.json | 1 - custom_components/gismeteo/weather.py | 4 ++-- tests/test__init.py | 8 ++++---- tests/test_api.py | 15 ++++++++------- tests/test_config_flow.py | 11 +++++++---- tests/test_entity.py | 16 ++++++++-------- tests/test_sensor.py | 8 ++++---- tests/test_weather.py | 8 ++++---- 14 files changed, 54 insertions(+), 53 deletions(-) diff --git a/custom_components/gismeteo/__init__.py b/custom_components/gismeteo/__init__.py index c8516d4..c6dd8db 100644 --- a/custom_components/gismeteo/__init__.py +++ b/custom_components/gismeteo/__init__.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -14,6 +13,7 @@ from aiohttp import ClientConnectorError from async_timeout import timeout + from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry diff --git a/custom_components/gismeteo/api.py b/custom_components/gismeteo/api.py index 06ead6f..629691e 100644 --- a/custom_components/gismeteo/api.py +++ b/custom_components/gismeteo/api.py @@ -1,22 +1,23 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ """ +from collections.abc import Callable +from datetime import datetime +from http import HTTPStatus import logging import math import time +from typing import Any, Dict, Optional import xml.etree.ElementTree as etree # type: ignore -from datetime import datetime -from http import HTTPStatus -from typing import Any, Callable, Dict, Optional from aiohttp import ClientSession + from homeassistant.components.weather import ( ATTR_CONDITION_CLEAR_NIGHT, ATTR_CONDITION_CLOUDY, diff --git a/custom_components/gismeteo/config_flow.py b/custom_components/gismeteo/config_flow.py index 143edf2..97e755b 100644 --- a/custom_components/gismeteo/config_flow.py +++ b/custom_components/gismeteo/config_flow.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -11,10 +10,10 @@ import asyncio import logging -import homeassistant.helpers.config_validation as cv -import voluptuous as vol from aiohttp import ClientConnectorError, ClientError from async_timeout import timeout +import voluptuous as vol + from homeassistant import config_entries from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( @@ -26,6 +25,7 @@ CONF_SHOW_ON_MAP, ) from homeassistant.core import callback +import homeassistant.helpers.config_validation as cv from . import DOMAIN, get_gismeteo # pylint: disable=unused-import from .api import ApiError diff --git a/custom_components/gismeteo/const.py b/custom_components/gismeteo/const.py index 16c3503..93bf850 100644 --- a/custom_components/gismeteo/const.py +++ b/custom_components/gismeteo/const.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -12,8 +11,7 @@ from typing import Final from homeassistant.components.sensor import DOMAIN as SENSOR -from homeassistant.components.weather import ATTR_FORECAST_CONDITION -from homeassistant.components.weather import DOMAIN as WEATHER +from homeassistant.components.weather import ATTR_FORECAST_CONDITION, DOMAIN as WEATHER from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_ICON, diff --git a/custom_components/gismeteo/entity.py b/custom_components/gismeteo/entity.py index b1584c9..659ce2e 100644 --- a/custom_components/gismeteo/entity.py +++ b/custom_components/gismeteo/entity.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ diff --git a/custom_components/gismeteo/sensor.py b/custom_components/gismeteo/sensor.py index f488e8d..954a011 100644 --- a/custom_components/gismeteo/sensor.py +++ b/custom_components/gismeteo/sensor.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -12,6 +11,7 @@ from typing import List import voluptuous as vol + from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.weather import ATTR_FORECAST_CONDITION from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry diff --git a/custom_components/gismeteo/translations/sensor.pt-BR.json b/custom_components/gismeteo/translations/sensor.pt-BR.json index dcb6138..4e2a08d 100644 --- a/custom_components/gismeteo/translations/sensor.pt-BR.json +++ b/custom_components/gismeteo/translations/sensor.pt-BR.json @@ -19,4 +19,3 @@ } } } - \ No newline at end of file diff --git a/custom_components/gismeteo/weather.py b/custom_components/gismeteo/weather.py index 4002856..878d3a0 100644 --- a/custom_components/gismeteo/weather.py +++ b/custom_components/gismeteo/weather.py @@ -1,8 +1,7 @@ # Copyright (c) 2019-2022, Andrey "Limych" Khrolenok # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Gismeteo component. +"""The Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -11,6 +10,7 @@ import logging import voluptuous as vol + from homeassistant.components.weather import PLATFORM_SCHEMA, WeatherEntity from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( diff --git a/tests/test__init.py b/tests/test__init.py index 087acee..63b58a9 100644 --- a/tests/test__init.py +++ b/tests/test__init.py @@ -4,15 +4,15 @@ from unittest.mock import patch import pytest +from pytest_homeassistant_custom_component.common import MockConfigEntry, load_fixture + +from custom_components.gismeteo.api import ApiError, GismeteoApiClient +from custom_components.gismeteo.const import CONF_FORECAST, DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from pytest_homeassistant_custom_component.common import MockConfigEntry, load_fixture - -from custom_components.gismeteo.api import ApiError, GismeteoApiClient -from custom_components.gismeteo.const import CONF_FORECAST, DOMAIN from .const import MOCK_CONFIG diff --git a/tests/test_api.py b/tests/test_api.py index ac052d4..4fcf245 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,8 +4,7 @@ # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -Tests for the Gismeteo component. +"""Tests for the Gismeteo component. For more details about this platform, please refer to the documentation at https://github.com/Limych/ha-gismeteo/ @@ -16,8 +15,6 @@ from aiohttp import ClientSession from asynctest import CoroutineMock -from homeassistant.components.weather import ATTR_WEATHER_WIND_SPEED -from homeassistant.const import ATTR_ID, ATTR_NAME from pytest import raises from pytest_homeassistant_custom_component.common import load_fixture @@ -36,6 +33,8 @@ FORECAST_MODE_DAILY, FORECAST_MODE_HOURLY, ) +from homeassistant.components.weather import ATTR_WEATHER_WIND_SPEED +from homeassistant.const import ATTR_ID, ATTR_NAME LATITUDE = 52.0677904 LONGITUDE = 19.4795644 @@ -145,10 +144,12 @@ async def test_async_get_location(): def test__get_utime(): """Test _get_utime service method.""" - assert GismeteoApiClient._get_utime("2021-02-21T16:00:00", 180) == 1613912400 - assert GismeteoApiClient._get_utime("2021-02-21T16:00:00", 0) == 1613923200 - assert GismeteoApiClient._get_utime("2021-02-21", 180) == 1613854800 assert GismeteoApiClient._get_utime("2021-02-21", 0) == 1613865600 + assert GismeteoApiClient._get_utime("2021-02-21", 180) == 1613854800 + + assert GismeteoApiClient._get_utime("2021-02-21T16:00:00", 0) == 1613923200 + assert GismeteoApiClient._get_utime("2021-02-21T16:00:00", 180) == 1613912400 + assert GismeteoApiClient._get_utime("2021-02-21T13:00:00", 0) == 1613912400 with raises(ValueError): GismeteoApiClient._get_utime("2021-02-", 0) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index a12113a..cd0939f 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -4,9 +4,6 @@ from unittest.mock import patch import pytest -from homeassistant import config_entries, data_entry_flow -from homeassistant.const import CONF_MODE, CONF_NAME, CONF_PLATFORM, CONF_SHOW_ON_MAP -from homeassistant.core import HomeAssistant from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.gismeteo.const import ( @@ -17,6 +14,9 @@ SENSOR, WEATHER, ) +from homeassistant import config_entries, data_entry_flow +from homeassistant.const import CONF_MODE, CONF_NAME, CONF_PLATFORM, CONF_SHOW_ON_MAP +from homeassistant.core import HomeAssistant from .const import MOCK_CONFIG @@ -27,7 +27,10 @@ @pytest.fixture(autouse=True) def bypass_setup_fixture(): """Prevent setup.""" - with patch("custom_components.gismeteo.async_setup", return_value=True,), patch( + with patch( + "custom_components.gismeteo.async_setup", + return_value=True, + ), patch( "custom_components.gismeteo.async_setup_entry", return_value=True, ): diff --git a/tests/test_entity.py b/tests/test_entity.py index 9dff3f4..aa52b82 100644 --- a/tests/test_entity.py +++ b/tests/test_entity.py @@ -1,14 +1,6 @@ """Tests for GisMeteo integration.""" from asynctest import Mock -from homeassistant.const import ( - ATTR_ATTRIBUTION, - ATTR_ID, - ATTR_LATITUDE, - ATTR_LONGITUDE, - CONF_SHOW_ON_MAP, -) -from homeassistant.core import HomeAssistant from custom_components.gismeteo import GismeteoDataUpdateCoordinator from custom_components.gismeteo.const import ( @@ -19,6 +11,14 @@ NAME, ) from custom_components.gismeteo.entity import GismeteoEntity +from homeassistant.const import ( + ATTR_ATTRIBUTION, + ATTR_ID, + ATTR_LATITUDE, + ATTR_LONGITUDE, + CONF_SHOW_ON_MAP, +) +from homeassistant.core import HomeAssistant from tests.const import ( MOCK_API_ID, diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 81c4277..13574c5 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -1,15 +1,15 @@ """Tests for GisMeteo integration.""" from asynctest import Mock -from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_PLATFORM -from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component from pytest_homeassistant_custom_component.common import assert_setup_component from custom_components.gismeteo import GismeteoDataUpdateCoordinator from custom_components.gismeteo.const import CONF_FORECAST, DOMAIN, SENSOR_TYPES from custom_components.gismeteo.sensor import GismeteoSensor, fix_kinds +from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_PLATFORM +from homeassistant.core import HomeAssistant +from homeassistant.setup import async_setup_component from tests.const import MOCK_CONFIG, MOCK_UNIQUE_ID diff --git a/tests/test_weather.py b/tests/test_weather.py index 3b84fee..c94d4d1 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -1,14 +1,14 @@ """Tests for GisMeteo integration.""" from asynctest import Mock -from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN -from homeassistant.const import CONF_NAME, CONF_PLATFORM -from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component from pytest_homeassistant_custom_component.common import assert_setup_component from custom_components.gismeteo import GismeteoDataUpdateCoordinator from custom_components.gismeteo.const import DOMAIN from custom_components.gismeteo.weather import GismeteoWeather +from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN +from homeassistant.const import CONF_NAME, CONF_PLATFORM +from homeassistant.core import HomeAssistant +from homeassistant.setup import async_setup_component from tests.const import MOCK_CONFIG, MOCK_UNIQUE_ID