55import pytest
66from pymodbus .compat import IS_PYTHON3 , PYTHON_VERSION
77if IS_PYTHON3 and PYTHON_VERSION >= (3 , 4 ):
8- from unittest .mock import patch , Mock , MagicMock
8+ from unittest .mock import patch
99 import asyncio
1010 from pymodbus .client .asynchronous .async_io import ReconnectingAsyncioModbusTlsClient
1111 from pymodbus .client .asynchronous .async_io import AsyncioModbusSerialClient
12- from serial_asyncio import SerialTransport
1312else :
14- from mock import patch , Mock , MagicMock
13+ from mock import patch
1514import platform
16- from distutils . version import LooseVersion
15+ from pkg_resources import parse_version
1716
1817from pymodbus .client .asynchronous .serial import AsyncModbusSerialClient
1918from pymodbus .client .asynchronous .tcp import AsyncModbusTCPClient
2625from pymodbus .client .asynchronous import schedulers
2726from pymodbus .factory import ClientDecoder
2827from pymodbus .exceptions import ConnectionException
29- from pymodbus .transaction import ModbusSocketFramer , ModbusTlsFramer , ModbusRtuFramer , ModbusAsciiFramer , ModbusBinaryFramer
28+ from pymodbus .transaction import ModbusSocketFramer , ModbusTlsFramer , ModbusRtuFramer
29+ from pymodbus .transaction import ModbusAsciiFramer , ModbusBinaryFramer
3030from pymodbus .client .asynchronous .twisted import ModbusSerClientProtocol
3131
3232import ssl
3333
3434IS_DARWIN = platform .system ().lower () == "darwin"
3535IS_WINDOWS = platform .system ().lower () == "windows"
36- OSX_SIERRA = LooseVersion ("10.12" )
36+ OSX_SIERRA = parse_version ("10.12" )
3737if IS_DARWIN :
38- IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < LooseVersion (platform .mac_ver ()[0 ])
38+ IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < parse_version (platform .mac_ver ()[0 ])
3939 SERIAL_PORT = '/dev/ptyp0' if not IS_HIGH_SIERRA_OR_ABOVE else '/dev/ttyp0'
4040else :
4141 IS_HIGH_SIERRA_OR_ABOVE = False
@@ -231,9 +231,9 @@ def handle_failure(failure):
231231 assert (not client .protocol ._connected )
232232
233233 @pytest .mark .parametrize ("method, framer" , [("rtu" , ModbusRtuFramer ),
234- ("socket" , ModbusSocketFramer ),
235- ("binary" , ModbusBinaryFramer ),
236- ("ascii" , ModbusAsciiFramer )])
234+ ("socket" , ModbusSocketFramer ),
235+ ("binary" , ModbusBinaryFramer ),
236+ ("ascii" , ModbusAsciiFramer )])
237237 def testSerialTornadoClient (self , method , framer ):
238238 """ Test the serial tornado client client initialize """
239239 from serial import Serial
@@ -257,7 +257,7 @@ def handle_failure(failure):
257257 protocol .stop ()
258258 assert (not client ._connected )
259259
260- @pytest .mark .skipif (IS_PYTHON3 , reason = "requires python2.7" )
260+ @pytest .mark .skipif (IS_PYTHON3 , reason = "requires python2.7" )
261261 def testSerialAsyncioClientPython2 (self ):
262262 """
263263 Test Serial asynchronous asyncio client exits on python2
@@ -272,10 +272,10 @@ def testSerialAsyncioClientPython2(self):
272272 @patch ("asyncio.get_event_loop" )
273273 @patch ("asyncio.gather" , side_effect = mock_asyncio_gather )
274274 @pytest .mark .parametrize ("method, framer" , [("rtu" , ModbusRtuFramer ),
275- ("socket" , ModbusSocketFramer ),
276- ("binary" , ModbusBinaryFramer ),
277- ("ascii" , ModbusAsciiFramer )])
278- def testSerialAsyncioClient (self , mock_gather , mock_event_loop , method , framer ):
275+ ("socket" , ModbusSocketFramer ),
276+ ("binary" , ModbusBinaryFramer ),
277+ ("ascii" , ModbusAsciiFramer )])
278+ def testSerialAsyncioClient (self , mock_gather , mock_event_loop , method , framer ):
279279 """
280280 Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler.
281281 :return:
0 commit comments