Skip to content

Commit 093c903

Browse files
committed
test updates
1 parent 15942e8 commit 093c903

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

test/test_bit_read_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def testReadBitBaseClassMethods(self):
4545
msg = "ReadBitRequest(1,1)"
4646
self.assertEqual(msg, str(handle))
4747
handle = ReadBitsResponseBase([1,1])
48-
msg = "ReadBitResponse(2)"
48+
msg = "ReadBitsResponseBase(2)"
4949
self.assertEqual(msg, str(handle))
5050

5151
def testBitReadBaseRequestEncoding(self):

test/test_client_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ def testBasicSyncTcpClient(self, mock_select):
192192
def testTcpClientConnect(self):
193193
''' Test the tcp client connection method'''
194194
with patch.object(socket, 'create_connection') as mock_method:
195-
mock_method.return_value = object()
195+
_socket = MagicMock()
196+
mock_method.return_value = _socket
196197
client = ModbusTcpClient()
198+
_socket.getsockname.return_value = ('dmmy', 1234)
197199
self.assertTrue(client.connect())
198200

199201
with patch.object(socket, 'create_connection') as mock_method:

test/test_server_asyncio.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def tearDown(self):
7272
# Test ModbusConnectedRequestHandler
7373
#-----------------------------------------------------------------------#
7474
@asyncio.coroutine
75+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
7576
def testStartTcpServer(self):
7677
''' Test that the modbus tcp asyncio server starts correctly '''
7778
identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
@@ -99,6 +100,7 @@ def testTcpServerServeForever(self):
99100
serve.assert_awaited()
100101

101102
@asyncio.coroutine
103+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
102104
def testTcpServerServeForeverTwice(self):
103105
''' Call on serve_forever() twice should result in a runtime error '''
104106
server = yield from StartTcpServer(context=self.context,address=("127.0.0.1", 0), loop=self.loop)
@@ -112,6 +114,7 @@ def testTcpServerServeForeverTwice(self):
112114
server.server_close()
113115

114116
@asyncio.coroutine
117+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
115118
def testTcpServerReceiveData(self):
116119
''' Test data sent on socket is received by internals - doesn't not process data '''
117120
data = b'\x01\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x19'
@@ -146,6 +149,7 @@ def eof_received(self):
146149
server.server_close()
147150

148151
@asyncio.coroutine
152+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
149153
def testTcpServerRoundtrip(self):
150154
''' Test sending and receiving data on tcp socket '''
151155
data = b"\x01\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01" # unit 1, read register
@@ -186,6 +190,7 @@ def eof_received(self):
186190
server.server_close()
187191

188192
@asyncio.coroutine
193+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
189194
def testTcpServerConnectionLost(self):
190195
''' Test tcp stream interruption '''
191196
data = b"\x01\x00\x00\x00\x00\x06\x01\x01\x00\x00\x00\x01"
@@ -222,6 +227,7 @@ def connection_made(self, transport):
222227
server.server_close()
223228

224229
@asyncio.coroutine
230+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
225231
def testTcpServerCloseActiveConnection(self):
226232
''' Test server_close() while there are active TCP connections '''
227233
data = b"\x01\x00\x00\x00\x00\x06\x01\x01\x00\x00\x00\x01"
@@ -254,6 +260,7 @@ def connection_made(self, transport):
254260
self.assertTrue( len(server.active_connections) == 0 )
255261

256262
@asyncio.coroutine
263+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
257264
def testTcpServerNoSlave(self):
258265
''' Test unknown slave unit exception '''
259266
context = ModbusServerContext(slaves={0x01: self.store, 0x02: self.store }, single=False)
@@ -290,6 +297,7 @@ def eof_received(self):
290297
server.server_close()
291298

292299
@asyncio.coroutine
300+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
293301
def testTcpServerModbusError(self):
294302
''' Test sending garbage data on a TCP socket should drop the connection '''
295303
data = b"\x01\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01" # get slave 5 function 3 (holding register)
@@ -329,6 +337,7 @@ def eof_received(self):
329337
server.server_close()
330338

331339
@asyncio.coroutine
340+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
332341
def testTcpServerInternalException(self):
333342
''' Test sending garbage data on a TCP socket should drop the connection '''
334343
data = b"\x01\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01" # get slave 5 function 3 (holding register)
@@ -373,6 +382,7 @@ def eof_received(self):
373382
# Test ModbusTlsProtocol
374383
#-----------------------------------------------------------------------#
375384
@asyncio.coroutine
385+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
376386
def testStartTlsServer(self):
377387
''' Test that the modbus tls asyncio server starts correctly '''
378388
with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
@@ -404,6 +414,7 @@ def testTlsServerServeForever(self):
404414
serve.assert_awaited()
405415

406416
@asyncio.coroutine
417+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
407418
def testTlsServerServeForeverTwice(self):
408419
''' Call on serve_forever() twice should result in a runtime error '''
409420
with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
@@ -423,6 +434,7 @@ def testTlsServerServeForeverTwice(self):
423434
#-----------------------------------------------------------------------#
424435

425436
@asyncio.coroutine
437+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
426438
def testStartUdpServer(self):
427439
''' Test that the modbus udp asyncio server starts correctly '''
428440
identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
@@ -449,6 +461,7 @@ def testUdpServerServeForeverStart(self):
449461
serve.assert_awaited()
450462

451463
@asyncio.coroutine
464+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
452465
def testUdpServerServeForeverClose(self):
453466
''' Test StartUdpServer serve_forever() method '''
454467
server = yield from StartUdpServer(context=self.context,address=("127.0.0.1", 0), loop=self.loop)
@@ -465,6 +478,7 @@ def testUdpServerServeForeverClose(self):
465478
self.assertTrue(server.protocol.is_closing())
466479

467480
@asyncio.coroutine
481+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
468482
def testUdpServerServeForeverTwice(self):
469483
''' Call on serve_forever() twice should result in a runtime error '''
470484
identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
@@ -480,6 +494,7 @@ def testUdpServerServeForeverTwice(self):
480494
server.server_close()
481495

482496
@asyncio.coroutine
497+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
483498
def testUdpServerReceiveData(self):
484499
''' Test that the sending data on datagram socket gets data pushed to framer '''
485500
server = yield from StartUdpServer(context=self.context,address=("127.0.0.1", 0),loop=self.loop)
@@ -501,6 +516,7 @@ def testUdpServerReceiveData(self):
501516
server.server_close()
502517

503518
@asyncio.coroutine
519+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
504520
def testUdpServerSendData(self):
505521
''' Test that the modbus udp asyncio server correctly sends data outbound '''
506522
identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
@@ -543,6 +559,7 @@ def datagram_received(self, data, addr):
543559
yield from asyncio.sleep(0.1)
544560

545561
@asyncio.coroutine
562+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
546563
def testUdpServerRoundtrip(self):
547564
''' Test sending and receiving data on udp socket'''
548565
data = b"\x01\x00\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01" # unit 1, read register
@@ -581,6 +598,7 @@ def datagram_received(self, data, addr):
581598
server.server_close()
582599

583600
@asyncio.coroutine
601+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
584602
def testUdpServerException(self):
585603
''' Test sending garbage data on a TCP socket should drop the connection '''
586604
garbage = b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
@@ -619,16 +637,19 @@ def datagram_received(self, data, addr):
619637
# -----------------------------------------------------------------------#
620638
# Test ModbusServerFactory
621639
# -----------------------------------------------------------------------#
640+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
622641
def testModbusServerFactory(self):
623642
''' Test the base class for all the clients '''
624643
with self.assertWarns(DeprecationWarning):
625644
factory = ModbusServerFactory(store=None)
626645

646+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
627647
def testStopServer(self):
628648
with self.assertWarns(DeprecationWarning):
629649
StopServer()
630650

631651
@asyncio.coroutine
652+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
632653
def testTcpServerException(self):
633654
''' Sending garbage data on a TCP socket should drop the connection '''
634655
garbage = b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'
@@ -669,6 +690,7 @@ def eof_received(self):
669690

670691

671692
@asyncio.coroutine
693+
@pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above")
672694
def testTcpServerException(self):
673695
''' Sending garbage data on a TCP socket should drop the connection '''
674696
garbage = b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF'

test/test_server_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ def testSerialServerServeForever(self):
365365
with patch('pymodbus.server.sync.CustomSingleRequestHandler') as mock_handler:
366366
server = ModbusSerialServer(None)
367367
instance = mock_handler.return_value
368-
instance.handle.side_effect = server.server_close
368+
instance.response_manipulator.side_effect = server.server_close
369369
server.serve_forever()
370-
instance.handle.assert_any_call()
370+
instance.response_manipulator.assert_any_call()
371371

372372
def testSerialServerClose(self):
373373
''' test that the synchronous serial server closes correctly '''

0 commit comments

Comments
 (0)