@@ -152,19 +152,22 @@ def test_factory_protocol_lost_connection(self, mock_async):
152152 mock_protocol_class = mock .MagicMock ()
153153 mock_loop = mock .MagicMock ()
154154 client = ReconnectingAsyncioModbusTcpClient (protocol_class = mock_protocol_class , loop = mock_loop )
155-
156155 assert not client .connected
157156 assert client .protocol is None
158- client .protocol_lost_connection (mock .sentinel .PROTOCOL_UNEXPECTED )
159- assert not client .connected
160157
161- # fake client ist connected and *then* looses connection:
158+ # fake client is connected and *then* looses connection:
162159 client .connected = True
163160 client .host = mock .sentinel .HOST
164161 client .port = mock .sentinel .PORT
165162 client .protocol = mock .sentinel .PROTOCOL
163+ client .protocol_lost_connection (mock .sentinel .PROTOCOL_UNEXPECTED )
164+ mock_async .reset_mock ()
165+ assert not client .connected
166+
167+ client .connected = True
166168 with mock .patch ('pymodbus.client.asynchronous.async_io.ReconnectingAsyncioModbusTcpClient._reconnect' ) as mock_reconnect :
167169 mock_reconnect .return_value = mock .sentinel .RECONNECT_GENERATOR
170+
168171 client .protocol_lost_connection (mock .sentinel .PROTOCOL )
169172 if PYTHON_VERSION == (3 , 7 ):
170173 mock_async .assert_called_once_with (mock .sentinel .RECONNECT_GENERATOR , loop = mock_loop )
@@ -275,7 +278,7 @@ def testClientProtocolConnectionLost(self, protocol):
275278 assert protocol .factory .protocol_lost_connection .call_count == 1
276279
277280 @pytest .mark .parametrize ("protocol" , protocols )
278- def testClientProtocolDataReceived (self , protocol ):
281+ async def test_client_protocol_data_received (self , protocol ):
279282 ''' Test the client protocol data received '''
280283 protocol = protocol (ModbusSocketFramer (ClientDecoder ()))
281284 transport = mock .MagicMock ()
@@ -289,7 +292,7 @@ def testClientProtocolDataReceived(self, protocol):
289292 if isinstance (protocol , ModbusUdpClientProtocol ):
290293 protocol .datagram_received (data , None )
291294 else :
292- protocol .data_received (data )
295+ protocol .data_received (data )
293296 result = d .result ()
294297 assert isinstance (result , ReadCoilsResponse )
295298
@@ -316,7 +319,7 @@ async def testClientProtocolExecute(self, protocol):
316319 assert d == f
317320
318321 @pytest .mark .parametrize ("protocol" , protocols )
319- def testClientProtocolHandleResponse (self , protocol ):
322+ async def test_client_protocol_handle_response (self , protocol ):
320323 ''' Test the client protocol handles responses '''
321324 protocol = protocol ()
322325 transport = mock .MagicMock ()
@@ -337,7 +340,7 @@ def testClientProtocolHandleResponse(self, protocol):
337340 assert result == reply
338341
339342 @pytest .mark .parametrize ("protocol" , protocols )
340- def testClientProtocolBuildResponse (self , protocol ):
343+ async def test_client_protocol_build_response (self , protocol ):
341344 ''' Test the udp client protocol builds responses '''
342345 protocol = protocol ()
343346 # if isinstance(protocol.create_future, mock.MagicMock):
0 commit comments