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

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
pull/58138/head
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/mochad/*
homeassistant/components/modbus/climate.py
homeassistant/components/modbus/modbus.py
homeassistant/components/modem_callerid/sensor.py
homeassistant/components/motion_blinds/__init__.py
homeassistant/components/motion_blinds/const.py

View File

@ -386,7 +386,7 @@ class ModbusHub:
return None
async with self._lock:
if not self._client:
return None
return None # pragma: no cover
result = await self.hass.async_add_executor_job(
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
async def test_pymodbus_connect_fail(hass, caplog):
async def test_pymodbus_connect_fail(hass, caplog, mock_pymodbus):
"""Run test for failing pymodbus constructor."""
config = {
DOMAIN: [
@ -660,14 +660,11 @@ async def test_pymodbus_connect_fail(hass, caplog):
}
]
}
with mock.patch(
"homeassistant.components.modbus.modbus.ModbusTcpClient", autospec=True
) as mock_pb:
caplog.set_level(logging.ERROR)
exception_message = "test connect exception"
mock_pb.connect.side_effect = ModbusException(exception_message)
assert await async_setup_component(hass, DOMAIN, config) is True
caplog.set_level(logging.WARNING)
ExceptionMessage = "test connect exception"
mock_pymodbus.connect.side_effect = ModbusException(ExceptionMessage)
assert await async_setup_component(hass, DOMAIN, config) is False
assert ExceptionMessage in caplog.text
async def test_delay(hass, mock_pymodbus):