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 sensorpull/29223/head^2
parent
76f455cea9
commit
19893b8f3c
|
@ -1,15 +1,16 @@
|
|||
"""Platform to retrieve Islamic prayer times information for Home Assistant."""
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
from prayer_times_calculator import PrayerTimesCalculator
|
||||
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.const import DEVICE_CLASS_TIMESTAMP
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import async_track_point_in_time
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -148,7 +149,6 @@ class IslamicPrayerTimesData:
|
|||
|
||||
def get_new_prayer_times(self):
|
||||
"""Fetch prayer times for today."""
|
||||
from prayer_times_calculator import PrayerTimesCalculator
|
||||
|
||||
today = datetime.today().strftime("%Y-%m-%d")
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from datetime import datetime, timedelta
|
|||
from unittest.mock import patch
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.islamic_prayer_times.sensor import IslamicPrayerTimesData
|
||||
from tests.common import MockDependency
|
||||
import homeassistant.util.dt as dt_util
|
||||
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."""
|
||||
min_config_sensors = ["fajr", "dhuhr", "asr", "maghrib", "isha"]
|
||||
|
||||
with MockDependency("prayer_times_calculator") as mock_pt_calc:
|
||||
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
with patch(
|
||||
"homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
|
||||
) as PrayerTimesCalculator:
|
||||
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
PRAYER_TIMES
|
||||
)
|
||||
|
||||
|
@ -63,8 +64,10 @@ async def test_islamic_prayer_times_multiple_sensors(hass):
|
|||
"midnight",
|
||||
]
|
||||
|
||||
with MockDependency("prayer_times_calculator") as mock_pt_calc:
|
||||
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
with patch(
|
||||
"homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
|
||||
) as PrayerTimesCalculator:
|
||||
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
PRAYER_TIMES
|
||||
)
|
||||
|
||||
|
@ -87,8 +90,10 @@ async def test_islamic_prayer_times_with_calculation_method(hass):
|
|||
"""Test Islamic prayer times configuration with calculation method."""
|
||||
sensors = ["fajr", "maghrib"]
|
||||
|
||||
with MockDependency("prayer_times_calculator") as mock_pt_calc:
|
||||
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
with patch(
|
||||
"homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
|
||||
) as PrayerTimesCalculator:
|
||||
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
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):
|
||||
"""Test Islamic prayer times data fetcher."""
|
||||
with MockDependency("prayer_times_calculator") as mock_pt_calc:
|
||||
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
with patch(
|
||||
"homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
|
||||
) as PrayerTimesCalculator:
|
||||
PrayerTimesCalculator.return_value.fetch_prayer_times.return_value = (
|
||||
PRAYER_TIMES
|
||||
)
|
||||
|
||||
|
@ -138,8 +145,10 @@ async def test_islamic_prayer_times_sensor_update(hass):
|
|||
"Midnight": "00:45",
|
||||
}
|
||||
|
||||
with MockDependency("prayer_times_calculator") as mock_pt_calc:
|
||||
mock_pt_calc.PrayerTimesCalculator.return_value.fetch_prayer_times.side_effect = [
|
||||
with patch(
|
||||
"homeassistant.components.islamic_prayer_times.sensor.PrayerTimesCalculator"
|
||||
) as PrayerTimesCalculator:
|
||||
PrayerTimesCalculator.return_value.fetch_prayer_times.side_effect = [
|
||||
PRAYER_TIMES,
|
||||
new_prayer_times,
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue