Skip to content

Commit c968928

Browse files
committed
Import using importlib
1 parent a0c3f47 commit c968928

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

tests/test_smile.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313

1414
# Testing
1515
import aiohttp
16+
import importlib
1617
import jsonpickle as json
1718
import pytest
1819

19-
from plugwise.exceptions import (
20-
ConnectionFailedError,
21-
DeviceTimeoutError,
22-
ErrorSendingCommandError,
23-
InvalidXMLError,
24-
ResponseError,
25-
)
26-
from plugwise.smile import Smile
20+
pw_exceptions = importlib.import_module('plugwise.exceptions')
21+
pw_smile = importlib.import_module('plugwise.smile')
2722

2823
pp = PrettyPrinter(indent=8)
2924

@@ -204,7 +199,7 @@ async def connect(self, broken=False, timeout=False, put_timeout=False):
204199
text = await resp.text()
205200
assert "xml" in text
206201

207-
smile = Smile(
202+
smile = pw_smile.Smile(
208203
host=server.host,
209204
username="smile",
210205
password="".join(random.choice(string.ascii_lowercase) for i in range(8)),
@@ -223,7 +218,7 @@ async def connect(self, broken=False, timeout=False, put_timeout=False):
223218
assert connection_state
224219
assert smile.smile_type is not None
225220
return server, smile, client
226-
except (DeviceTimeoutError, InvalidXMLError) as e:
221+
except (pw_exceptions.DeviceTimeoutError, pw_exceptions.InvalidXMLError) as e:
227222
await self.disconnect(server, client)
228223
raise e
229224

@@ -239,15 +234,15 @@ async def connect_wrapper(self, put_timeout=False):
239234
await self.connect(timeout=True)
240235
_LOGGER.error(" - timeout not handled")
241236
raise self.ConnectError
242-
except (DeviceTimeoutError, ResponseError):
237+
except (pw_exceptions.DeviceTimeoutError, pw_exceptions.ResponseError):
243238
_LOGGER.info(" + successfully passed timeout handling.")
244239

245240
try:
246241
_LOGGER.warning("Connecting to device with missing data:")
247242
await self.connect(broken=True)
248243
_LOGGER.error(" - broken information not handled")
249244
raise self.ConnectError
250-
except InvalidXMLError:
245+
except pw_exceptions.InvalidXMLError:
251246
_LOGGER.info(" + successfully passed XML issue handling.")
252247

253248
_LOGGER.info("Connecting to functioning device:")
@@ -282,7 +277,7 @@ def show_setup(location_list, device_list):
282277
_LOGGER.info(" ! no devices found in this location")
283278

284279
@pytest.mark.asyncio
285-
async def device_test(self, smile=Smile, testdata=None):
280+
async def device_test(self, smile=pw_smile.Smile, testdata=None):
286281
"""Perform basic device tests."""
287282
_LOGGER.info("Asserting testdata:")
288283
device_list = smile.get_all_devices()
@@ -346,7 +341,7 @@ async def tinker_relay(self, smile, dev_ids=None, members=None, unhappy=False):
346341
)
347342
assert relay_change
348343
_LOGGER.info(" + worked as intended")
349-
except (ErrorSendingCommandError, ResponseError):
344+
except (pw_exceptions.ErrorSendingCommandError, pw_exceptions.ResponseError):
350345
if unhappy:
351346
_LOGGER.info(" + failed as expected")
352347
else:
@@ -366,7 +361,7 @@ async def tinker_thermostat(self, smile, loc_id, good_schemas=None, unhappy=Fals
366361
temp_change = await smile.set_temperature(loc_id, new_temp)
367362
assert temp_change
368363
_LOGGER.info(" + worked as intended")
369-
except (ErrorSendingCommandError, ResponseError):
364+
except (pw_exceptions.ErrorSendingCommandError, pw_exceptions.ResponseError):
370365
if unhappy:
371366
_LOGGER.info(" + failed as expected")
372367
else:
@@ -385,7 +380,7 @@ async def tinker_thermostat(self, smile, loc_id, good_schemas=None, unhappy=Fals
385380
preset_change = await smile.set_preset(loc_id, new_preset)
386381
assert preset_change == assert_state
387382
_LOGGER.info(" + worked as intended")
388-
except (ErrorSendingCommandError, ResponseError):
383+
except (pw_exceptions.ErrorSendingCommandError, pw_exceptions.ResponseError):
389384
if unhappy:
390385
_LOGGER.info(" + failed as expected")
391386
else:
@@ -408,7 +403,7 @@ async def tinker_thermostat(self, smile, loc_id, good_schemas=None, unhappy=Fals
408403
)
409404
assert schema_change == assert_state
410405
_LOGGER.info(" + failed as intended")
411-
except (ErrorSendingCommandError, ResponseError):
406+
except (pw_exceptions.ErrorSendingCommandError, pw_exceptions.ResponseError):
412407
if unhappy:
413408
_LOGGER.info(" + failed as expected before intended failure")
414409
else:
@@ -1366,7 +1361,7 @@ async def test_fail_legacy_system(self):
13661361
try:
13671362
_server, _smile, _client = await self.connect_wrapper()
13681363
assert False
1369-
except ConnectionFailedError:
1364+
except pw_exceptions.ConnectionFailedError:
13701365
assert True
13711366

13721367
class PlugwiseTestError(Exception):

0 commit comments

Comments
 (0)