Move imports to top for islamic_prayer_times (#29506)

* Move imports to top for islamic_prayer_times

* Fix test_sensor.py for islamic_prayer_times

* Format test_sensor.py with black

* Fix tests for islamic prayer times sensor
This commit is contained in:
springstan 2019-12-05 16:58:14 +01:00 committed by Martin Hjelmare
parent 76f455cea9
commit 19893b8f3c
2 changed files with 24 additions and 15 deletions

View File

@ -1,15 +1,16 @@
"""Platform to retrieve Islamic prayer times information for Home Assistant.""" """Platform to retrieve Islamic prayer times information for Home Assistant."""
import logging
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging
from prayer_times_calculator import PrayerTimesCalculator
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import DEVICE_CLASS_TIMESTAMP from homeassistant.const import DEVICE_CLASS_TIMESTAMP
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_point_in_time from homeassistant.helpers.event import async_track_point_in_time
import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -148,7 +149,6 @@ class IslamicPrayerTimesData:
def get_new_prayer_times(self): def get_new_prayer_times(self):
"""Fetch prayer times for today.""" """Fetch prayer times for today."""
from prayer_times_calculator import PrayerTimesCalculator
today = datetime.today().strftime("%Y-%m-%d") today = datetime.today().strftime("%Y-%m-%d")

View File

@ -3,7 +3,6 @@ from datetime import datetime, timedelta
from unittest.mock import patch from unittest.mock import patch
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.components.islamic_prayer_times.sensor import IslamicPrayerTimesData from homeassistant.components.islamic_prayer_times.sensor import IslamicPrayerTimesData
from tests.common import MockDependency
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
@ -34,8 +33,10 @@ async def test_islamic_prayer_times_min_config(hass):
"""Test minimum Islamic prayer times configuration.""" """Test minimum Islamic prayer times configuration."""
min_config_sensors = ["fajr", "dhuhr", "asr", "maghrib", "isha"] min_config_sensors = ["fajr", "dhuhr", "asr", "maghrib", "isha"]
with MockDependency("prayer_times_calculator") as mock_pt_calc: with patch(
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = ( "homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
) as PrayerTimesCalculator:
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
PRAYER_TIMES PRAYER_TIMES
) )
@ -63,8 +64,10 @@ async def test_islamic_prayer_times_multiple_sensors(hass):
"midnight", "midnight",
] ]
with MockDependency("prayer_times_calculator") as mock_pt_calc: with patch(
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = ( "homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
) as PrayerTimesCalculator:
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
PRAYER_TIMES PRAYER_TIMES
) )
@ -87,8 +90,10 @@ async def test_islamic_prayer_times_with_calculation_method(hass):
"""Test Islamic prayer times configuration with calculation method.""" """Test Islamic prayer times configuration with calculation method."""
sensors = ["fajr", "maghrib"] sensors = ["fajr", "maghrib"]
with MockDependency("prayer_times_calculator") as mock_pt_calc: with patch(
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = ( "homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
) as PrayerTimesCalculator:
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
PRAYER_TIMES PRAYER_TIMES
) )
@ -113,8 +118,10 @@ async def test_islamic_prayer_times_with_calculation_method(hass):
async def test_islamic_prayer_times_data_get_prayer_times(hass): async def test_islamic_prayer_times_data_get_prayer_times(hass):
"""Test Islamic prayer times data fetcher.""" """Test Islamic prayer times data fetcher."""
with MockDependency("prayer_times_calculator") as mock_pt_calc: with patch(
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = ( "homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
) as PrayerTimesCalculator:
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
PRAYER_TIMES PRAYER_TIMES
) )
@ -138,8 +145,10 @@ async def test_islamic_prayer_times_sensor_update(hass):
"Midnight": "00:45", "Midnight": "00:45",
} }
with MockDependency("prayer_times_calculator") as mock_pt_calc: with patch(
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.side_effect = [ "homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
) as PrayerTimesCalculator:
PrayerTimesCalculator.return_value.fetch_prayer_times.side_effect = [
PRAYER_TIMES, PRAYER_TIMES,
new_prayer_times, new_prayer_times,
] ]