Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 8, 2023
1 parent 14b67da commit 8570b19
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 53 deletions.
4 changes: 2 additions & 2 deletions custom_components/gismeteo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions custom_components/gismeteo/api.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/gismeteo/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand All @@ -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 (
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions custom_components/gismeteo/const.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions custom_components/gismeteo/entity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand Down
4 changes: 2 additions & 2 deletions custom_components/gismeteo/sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion custom_components/gismeteo/translations/sensor.pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
}
}
}

4 changes: 2 additions & 2 deletions custom_components/gismeteo/weather.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2019-2022, Andrey "Limych" Khrolenok <[email protected]>
# 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/
Expand All @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions tests/test__init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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

Expand All @@ -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,
):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_weather.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 8570b19

Please sign in to comment.