Skip to content

Commit d4d8c68

Browse files
authored
Merge pull request #65 from plugwise/testfixing
Small testing improvements
2 parents 6f3a56f + f7a3a83 commit d4d8c68

File tree

6 files changed

+606
-66
lines changed

6 files changed

+606
-66
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
ignore = E203, E231, E266, E501, W503, F403, F401
2+
ignore = E203, E231, E266, E501, W503, F403, F401, W503
33
max-line-length = 89
44
max-complexity = 20
55
select = B,C,E,F,W,T4,B9

plugwise/smile.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ def __init__(
7676
if not websession:
7777

7878
async def _create_session() -> aiohttp.ClientSession:
79-
return aiohttp.ClientSession()
79+
return aiohttp.ClientSession() # pragma: no cover
8080

8181
loop = asyncio.get_event_loop()
8282
if loop.is_running():
8383
self.websession = aiohttp.ClientSession()
8484
else:
85-
self.websession = loop.run_until_complete(_create_session())
85+
self.websession = loop.run_until_complete(
86+
_create_session()
87+
) # pragma: no cover
8688
else:
8789
self.websession = websession
8890

@@ -119,7 +121,7 @@ async def connect(self):
119121
names.append(name.text)
120122

121123
if "Plugwise" not in names:
122-
if dsmrmain is None:
124+
if dsmrmain is None: # pragma: no cover
123125
_LOGGER.error(
124126
"Connected but expected text not returned, \
125127
we got %s",
@@ -152,7 +154,8 @@ async def connect(self):
152154
version = status.find(".//system/version").text
153155
model = status.find(".//system/product").text
154156
self.smile_hostname = status.find(".//network/hostname").text
155-
except InvalidXMLError:
157+
except InvalidXMLError: # pragma: no cover
158+
# Corner case check
156159
raise ConnectionFailedError
157160

158161
# Stretch:
@@ -163,17 +166,20 @@ async def connect(self):
163166
model = system.find(".//gateway/product").text
164167
self.smile_hostname = system.find(".//gateway/hostname").text
165168
self.gateway_id = network.attrib["id"]
166-
except InvalidXMLError:
169+
except InvalidXMLError: # pragma: no cover
170+
# Corner case check
167171
raise ConnectionFailedError
168-
else:
172+
else: # pragma: no cover
173+
# No cornercase, just end of the line
169174
_LOGGER.error("Connected but no gateway device information found")
170175
raise ConnectionFailedError
171176

172177
if not self._smile_legacy:
173178
model = result.find(".//gateway/vendor_model").text
174179
version = result.find(".//gateway/firmware_version").text
175180

176-
if model is None or version is None:
181+
if model is None or version is None: # pragma: no cover
182+
# Corner case check
177183
_LOGGER.error("Unable to find model or version information")
178184
raise UnsupportedDeviceError
179185

@@ -293,7 +299,7 @@ async def update_domain_objects(self):
293299
msg = notification.find("message").text
294300
self.notifications.update({msg_id: {msg_type: msg}})
295301
_LOGGER.debug("Plugwise notifications: %s", self.notifications)
296-
except AttributeError:
302+
except AttributeError: # pragma: no cover
297303
_LOGGER.info(
298304
"Plugwise notification present but unable to process, manually investigate: %s",
299305
url,
@@ -316,24 +322,24 @@ async def full_update_device(self):
316322
# P1 legacy has no appliances
317323
if not (self.smile_type == "power" and self._smile_legacy):
318324
await self.update_appliances()
319-
if self._appliances is None:
325+
if self._appliances is None: # pragma: no cover
320326
_LOGGER.error("Appliance data missing")
321327
raise XMLDataMissingError
322328

323329
await self.update_domain_objects()
324-
if self._domain_objects is None:
330+
if self._domain_objects is None: # pragma: no cover
325331
_LOGGER.error("Domain_objects data missing")
326332
raise XMLDataMissingError
327333

328334
await self.update_locations()
329-
if self._locations is None:
335+
if self._locations is None: # pragma: no cover
330336
_LOGGER.error("Locataion data missing")
331337
raise XMLDataMissingError
332338

333339
# Stretch_v2 only uses modules
334340
if self.smile_type == "stretch" and self.smile_version[1].major == 2:
335341
await self.update_modules()
336-
if self._modules is None:
342+
if self._modules is None: # pragma: no cover
337343
_LOGGER.error("Modules data missing")
338344
raise XMLDataMissingError
339345

@@ -577,7 +583,7 @@ def scan_thermostats(self, debug_text="missing text"):
577583
locations[loc_id].update(
578584
{"master": None, "master_prio": 0, "slaves": set()}
579585
)
580-
else:
586+
else: # pragma: no cover
581587
continue
582588

583589
for appliance_id, appliance_details in appliances.items():

scripts/tests_and_coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
echo "-----------------------------------------------------------"
33
echo "Running plugwise/smile.py through pytest including coverage"
44
echo "-----------------------------------------------------------"
5-
PYTHONPATH=$(pwd) pytest -rpP --log-level debug tests/test_smile.py --cov='.' --no-cov-on-fail
5+
PYTHONPATH=$(pwd) pytest -rpP --log-level debug tests/test_smile.py --cov='.' --no-cov-on-fail --cov-report term-missing

0 commit comments

Comments
 (0)