Fix connect_fail test and modbus.py 100% coverage (#57894)

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
This commit is contained in:
jan iversen 2021-10-21 00:22:24 +02:00 committed by GitHub
parent cca7da77ad
commit f2a5d92e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 11 deletions

View File

@ -649,7 +649,6 @@ omit =
homeassistant/components/mjpeg/camera.py homeassistant/components/mjpeg/camera.py
homeassistant/components/mochad/* homeassistant/components/mochad/*
homeassistant/components/modbus/climate.py homeassistant/components/modbus/climate.py
homeassistant/components/modbus/modbus.py
homeassistant/components/modem_callerid/sensor.py homeassistant/components/modem_callerid/sensor.py
homeassistant/components/motion_blinds/__init__.py homeassistant/components/motion_blinds/__init__.py
homeassistant/components/motion_blinds/const.py homeassistant/components/motion_blinds/const.py

View File

@ -386,7 +386,7 @@ class ModbusHub:
return None return None
async with self._lock: async with self._lock:
if not self._client: if not self._client:
return None return None # pragma: no cover
result = await self.hass.async_add_executor_job( result = await self.hass.async_add_executor_job(
self._pymodbus_call, unit, address, value, use_call self._pymodbus_call, unit, address, value, use_call
) )

View File

@ -648,7 +648,7 @@ async def test_pymodbus_close_fail(hass, caplog, mock_pymodbus):
# Close() is called as part of teardown # Close() is called as part of teardown
async def test_pymodbus_connect_fail(hass, caplog): async def test_pymodbus_connect_fail(hass, caplog, mock_pymodbus):
"""Run test for failing pymodbus constructor.""" """Run test for failing pymodbus constructor."""
config = { config = {
DOMAIN: [ DOMAIN: [
@ -660,14 +660,11 @@ async def test_pymodbus_connect_fail(hass, caplog):
} }
] ]
} }
with mock.patch( caplog.set_level(logging.WARNING)
"homeassistant.components.modbus.modbus.ModbusTcpClient", autospec=True ExceptionMessage = "test connect exception"
) as mock_pb: mock_pymodbus.connect.side_effect = ModbusException(ExceptionMessage)
caplog.set_level(logging.ERROR) assert await async_setup_component(hass, DOMAIN, config) is False
exception_message = "test connect exception" assert ExceptionMessage in caplog.text
mock_pb.connect.side_effect = ModbusException(exception_message)
assert await async_setup_component(hass, DOMAIN, config) is True
async def test_delay(hass, mock_pymodbus): async def test_delay(hass, mock_pymodbus):