mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Update pymodbus fixtures to use autospec (#55686)
This commit is contained in:
parent
a180c3f813
commit
1f997fcd58
@ -39,12 +39,17 @@ def mock_pymodbus():
|
|||||||
"""Mock pymodbus."""
|
"""Mock pymodbus."""
|
||||||
mock_pb = mock.MagicMock()
|
mock_pb = mock.MagicMock()
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"homeassistant.components.modbus.modbus.ModbusTcpClient", return_value=mock_pb
|
"homeassistant.components.modbus.modbus.ModbusTcpClient",
|
||||||
|
return_value=mock_pb,
|
||||||
|
autospec=True,
|
||||||
), mock.patch(
|
), mock.patch(
|
||||||
"homeassistant.components.modbus.modbus.ModbusSerialClient",
|
"homeassistant.components.modbus.modbus.ModbusSerialClient",
|
||||||
return_value=mock_pb,
|
return_value=mock_pb,
|
||||||
|
autospec=True,
|
||||||
), mock.patch(
|
), mock.patch(
|
||||||
"homeassistant.components.modbus.modbus.ModbusUdpClient", return_value=mock_pb
|
"homeassistant.components.modbus.modbus.ModbusUdpClient",
|
||||||
|
return_value=mock_pb,
|
||||||
|
autospec=True,
|
||||||
):
|
):
|
||||||
yield mock_pb
|
yield mock_pb
|
||||||
|
|
||||||
@ -96,10 +101,16 @@ async def mock_modbus(
|
|||||||
}
|
}
|
||||||
mock_pb = mock.MagicMock()
|
mock_pb = mock.MagicMock()
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"homeassistant.components.modbus.modbus.ModbusTcpClient", return_value=mock_pb
|
"homeassistant.components.modbus.modbus.ModbusTcpClient",
|
||||||
|
return_value=mock_pb,
|
||||||
|
autospec=True,
|
||||||
):
|
):
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
with mock.patch("homeassistant.helpers.event.dt_util.utcnow", return_value=now):
|
with mock.patch(
|
||||||
|
"homeassistant.helpers.event.dt_util.utcnow",
|
||||||
|
return_value=now,
|
||||||
|
autospec=True,
|
||||||
|
):
|
||||||
result = await async_setup_component(hass, DOMAIN, config)
|
result = await async_setup_component(hass, DOMAIN, config)
|
||||||
assert result or not check_config_loaded
|
assert result or not check_config_loaded
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -131,7 +142,9 @@ async def mock_pymodbus_return(hass, register_words, mock_modbus):
|
|||||||
async def mock_do_cycle(hass, mock_pymodbus_exception, mock_pymodbus_return):
|
async def mock_do_cycle(hass, mock_pymodbus_exception, mock_pymodbus_return):
|
||||||
"""Trigger update call with time_changed event."""
|
"""Trigger update call with time_changed event."""
|
||||||
now = dt_util.utcnow() + timedelta(seconds=90)
|
now = dt_util.utcnow() + timedelta(seconds=90)
|
||||||
with mock.patch("homeassistant.helpers.event.dt_util.utcnow", return_value=now):
|
with mock.patch(
|
||||||
|
"homeassistant.helpers.event.dt_util.utcnow", return_value=now, autospec=True
|
||||||
|
):
|
||||||
async_fire_time_changed(hass, now)
|
async_fire_time_changed(hass, now)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -602,7 +602,7 @@ async def test_pymodbus_constructor_fail(hass, caplog):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"homeassistant.components.modbus.modbus.ModbusTcpClient"
|
"homeassistant.components.modbus.modbus.ModbusTcpClient", autospec=True
|
||||||
) as mock_pb:
|
) as mock_pb:
|
||||||
caplog.set_level(logging.ERROR)
|
caplog.set_level(logging.ERROR)
|
||||||
mock_pb.side_effect = ModbusException("test no class")
|
mock_pb.side_effect = ModbusException("test no class")
|
||||||
@ -669,7 +669,9 @@ async def test_delay(hass, mock_pymodbus):
|
|||||||
# pass first scan_interval
|
# pass first scan_interval
|
||||||
start_time = now
|
start_time = now
|
||||||
now = now + timedelta(seconds=(test_scan_interval + 1))
|
now = now + timedelta(seconds=(test_scan_interval + 1))
|
||||||
with mock.patch("homeassistant.helpers.event.dt_util.utcnow", return_value=now):
|
with mock.patch(
|
||||||
|
"homeassistant.helpers.event.dt_util.utcnow", return_value=now, autospec=True
|
||||||
|
):
|
||||||
async_fire_time_changed(hass, now)
|
async_fire_time_changed(hass, now)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user