Move imports in darksky component (#27633)

* move imports to top-level

* modify patch path

* removed unused mocks and patches
This commit is contained in:
Malte Franken 2019-10-15 00:02:00 +11:00 committed by Pascal Vizeli
parent aefb807222
commit 91c6cd9646
3 changed files with 16 additions and 13 deletions

View File

@ -2,6 +2,7 @@
import logging import logging
from datetime import timedelta from datetime import timedelta
import forecastio
import voluptuous as vol import voluptuous as vol
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
@ -797,8 +798,6 @@ class DarkSkyData:
def _update(self): def _update(self):
"""Get the latest data from Dark Sky.""" """Get the latest data from Dark Sky."""
import forecastio
try: try:
self.data = forecastio.load_forecast( self.data = forecastio.load_forecast(
self._api_key, self._api_key,

View File

@ -2,6 +2,7 @@
from datetime import timedelta from datetime import timedelta
import logging import logging
import forecastio
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
import voluptuous as vol import voluptuous as vol
@ -244,8 +245,6 @@ class DarkSkyData:
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
"""Get the latest data from Dark Sky.""" """Get the latest data from Dark Sky."""
import forecastio
try: try:
self.data = forecastio.load_forecast( self.data = forecastio.load_forecast(
self._api_key, self.latitude, self.longitude, units=self.requested_units self._api_key, self.latitude, self.longitude, units=self.requested_units

View File

@ -112,7 +112,10 @@ class TestDarkSkySetup(unittest.TestCase):
self.hass.stop() self.hass.stop()
@MockDependency("forecastio") @MockDependency("forecastio")
@patch("forecastio.load_forecast", new=load_forecastMock) @patch(
"homeassistant.components.darksky.sensor.forecastio.load_forecast",
new=load_forecastMock,
)
def test_setup_with_config(self, mock_forecastio): def test_setup_with_config(self, mock_forecastio):
"""Test the platform setup with configuration.""" """Test the platform setup with configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL) setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
@ -120,9 +123,7 @@ class TestDarkSkySetup(unittest.TestCase):
state = self.hass.states.get("sensor.dark_sky_summary") state = self.hass.states.get("sensor.dark_sky_summary")
assert state is not None assert state is not None
@MockDependency("forecastio") def test_setup_with_invalid_config(self):
@patch("forecastio.load_forecast", new=load_forecastMock)
def test_setup_with_invalid_config(self, mock_forecastio):
"""Test the platform setup with invalid configuration.""" """Test the platform setup with invalid configuration."""
setup_component(self.hass, "sensor", INVALID_CONFIG_MINIMAL) setup_component(self.hass, "sensor", INVALID_CONFIG_MINIMAL)
@ -130,7 +131,10 @@ class TestDarkSkySetup(unittest.TestCase):
assert state is None assert state is None
@MockDependency("forecastio") @MockDependency("forecastio")
@patch("forecastio.load_forecast", new=load_forecastMock) @patch(
"homeassistant.components.darksky.sensor.forecastio.load_forecast",
new=load_forecastMock,
)
def test_setup_with_language_config(self, mock_forecastio): def test_setup_with_language_config(self, mock_forecastio):
"""Test the platform setup with language configuration.""" """Test the platform setup with language configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_LANG_DE) setup_component(self.hass, "sensor", VALID_CONFIG_LANG_DE)
@ -138,9 +142,7 @@ class TestDarkSkySetup(unittest.TestCase):
state = self.hass.states.get("sensor.dark_sky_summary") state = self.hass.states.get("sensor.dark_sky_summary")
assert state is not None assert state is not None
@MockDependency("forecastio") def test_setup_with_invalid_language_config(self):
@patch("forecastio.load_forecast", new=load_forecastMock)
def test_setup_with_invalid_language_config(self, mock_forecastio):
"""Test the platform setup with language configuration.""" """Test the platform setup with language configuration."""
setup_component(self.hass, "sensor", INVALID_CONFIG_LANG) setup_component(self.hass, "sensor", INVALID_CONFIG_LANG)
@ -164,7 +166,10 @@ class TestDarkSkySetup(unittest.TestCase):
assert not response assert not response
@MockDependency("forecastio") @MockDependency("forecastio")
@patch("forecastio.load_forecast", new=load_forecastMock) @patch(
"homeassistant.components.darksky.sensor.forecastio.load_forecast",
new=load_forecastMock,
)
def test_setup_with_alerts_config(self, mock_forecastio): def test_setup_with_alerts_config(self, mock_forecastio):
"""Test the platform setup with alert configuration.""" """Test the platform setup with alert configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_ALERTS) setup_component(self.hass, "sensor", VALID_CONFIG_ALERTS)