Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/tools/test_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ elif [[ "`which easy_install`" != "" ]]; then
INSTALL="easy_install -qU"
else
echo -e "\E[31m"
echo "\E[31mPlease install distutils before continuing"
echo "\E[31mPlease install setuptools before continuing"
echo "wget http://peak.telecommunity.com/dist/ez_setup.py | sudo python"
echo -e "\E[0m"
exit -1
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""
Installs pymodbus using distutils
Installs pymodbus using setuptools

Run:
python setup.py install
Expand Down Expand Up @@ -123,4 +123,3 @@
test_suite='nose.collector',
cmdclass=command_classes,
)

22 changes: 13 additions & 9 deletions setup_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from distutils.core import Command
import sys, os, shutil

import os
import shutil
import sys
from setuptools import Command
# --------------------------------------------------------------------------- #
# Extra Commands
# --------------------------------------------------------------------------- #
Expand All @@ -12,7 +13,7 @@ class BuildApiDocsCommand(Command):
build.py script underneath trying to build the api
documentation for the given format.
"""
description = "build all the projects api documents"
description = "build all the project's api documents"
user_options = []

def initialize_options(self):
Expand All @@ -39,7 +40,7 @@ class DeepCleanCommand(Command):
Helper command to return the directory to a completely
clean state.
"""
description = "clean everything that we don't want"
description = "clean everything that we don't want"
user_options = []
trash = ['build', 'dist', 'pymodbus.egg-info',
os.path.join(os.path.join('doc', 'sphinx'), 'build'),
Expand Down Expand Up @@ -70,7 +71,7 @@ def _delete_pyc_files():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.pyc'):
os.remove(os.path.join(root,file))
os.remove(os.path.join(root, file))


class LintCommand(Command):
Expand Down Expand Up @@ -111,15 +112,17 @@ def _try_pychecker(self):
sys.argv = """pychecker pymodbus/*.py""".split()
main()
return True
except: return False
except Exception:
return False

def _try_pylint(self):
try:
import pylint
sys.argv = """pylint pymodbus/*.py""".split()
main()
return True
except: return False
except Exception:
return False


class Python3Command(Command):
Expand Down Expand Up @@ -150,7 +153,8 @@ def _run_python3(self):
sys.argv = ['2to3'] + self.directories
main("lib2to3.fixes")
return True
except: return False
except Exception:
return False


class Pep8Command(Command):
Expand Down
30 changes: 15 additions & 15 deletions test/test_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import pytest
from pymodbus.compat import IS_PYTHON3, PYTHON_VERSION
if IS_PYTHON3 and PYTHON_VERSION >= (3, 4):
from unittest.mock import patch, Mock, MagicMock
from unittest.mock import patch
import asyncio
from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusTlsClient
from pymodbus.client.asynchronous.async_io import AsyncioModbusSerialClient
from serial_asyncio import SerialTransport
else:
from mock import patch, Mock, MagicMock
from mock import patch
import platform
from distutils.version import LooseVersion
from pkg_resources import parse_version

from pymodbus.client.asynchronous.serial import AsyncModbusSerialClient
from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient
Expand All @@ -26,16 +25,17 @@
from pymodbus.client.asynchronous import schedulers
from pymodbus.factory import ClientDecoder
from pymodbus.exceptions import ConnectionException
from pymodbus.transaction import ModbusSocketFramer, ModbusTlsFramer, ModbusRtuFramer, ModbusAsciiFramer, ModbusBinaryFramer
from pymodbus.transaction import ModbusSocketFramer, ModbusTlsFramer, ModbusRtuFramer
from pymodbus.transaction import ModbusAsciiFramer, ModbusBinaryFramer
from pymodbus.client.asynchronous.twisted import ModbusSerClientProtocol

import ssl

IS_DARWIN = platform.system().lower() == "darwin"
IS_WINDOWS = platform.system().lower() == "windows"
OSX_SIERRA = LooseVersion("10.12")
OSX_SIERRA = parse_version("10.12")
if IS_DARWIN:
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < LooseVersion(platform.mac_ver()[0])
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < parse_version(platform.mac_ver()[0])
SERIAL_PORT = '/dev/ptyp0' if not IS_HIGH_SIERRA_OR_ABOVE else '/dev/ttyp0'
else:
IS_HIGH_SIERRA_OR_ABOVE = False
Expand Down Expand Up @@ -231,9 +231,9 @@ def handle_failure(failure):
assert (not client.protocol._connected)

@pytest.mark.parametrize("method, framer", [("rtu", ModbusRtuFramer),
("socket", ModbusSocketFramer),
("binary", ModbusBinaryFramer),
("ascii", ModbusAsciiFramer)])
("socket", ModbusSocketFramer),
("binary", ModbusBinaryFramer),
("ascii", ModbusAsciiFramer)])
def testSerialTornadoClient(self, method, framer):
""" Test the serial tornado client client initialize """
from serial import Serial
Expand All @@ -257,7 +257,7 @@ def handle_failure(failure):
protocol.stop()
assert(not client._connected)

@pytest.mark.skipif(IS_PYTHON3 , reason="requires python2.7")
@pytest.mark.skipif(IS_PYTHON3, reason="requires python2.7")
def testSerialAsyncioClientPython2(self):
"""
Test Serial asynchronous asyncio client exits on python2
Expand All @@ -272,10 +272,10 @@ def testSerialAsyncioClientPython2(self):
@patch("asyncio.get_event_loop")
@patch("asyncio.gather", side_effect=mock_asyncio_gather)
@pytest.mark.parametrize("method, framer", [("rtu", ModbusRtuFramer),
("socket", ModbusSocketFramer),
("binary", ModbusBinaryFramer),
("ascii", ModbusAsciiFramer)])
def testSerialAsyncioClient(self, mock_gather, mock_event_loop, method, framer):
("socket", ModbusSocketFramer),
("binary", ModbusBinaryFramer),
("ascii", ModbusAsciiFramer)])
def testSerialAsyncioClient(self, mock_gather, mock_event_loop, method, framer):
"""
Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler.
:return:
Expand Down
21 changes: 12 additions & 9 deletions test/test_client_async_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pymodbus.compat import IS_PYTHON3
if IS_PYTHON3:
from unittest.mock import patch, Mock
else: # Python 2
else: # Python 2
from mock import patch, Mock
from pymodbus.client.asynchronous.tornado import (BaseTornadoClient,
AsyncModbusSerialClient, AsyncModbusUDPClient, AsyncModbusTCPClient
Expand All @@ -19,12 +19,12 @@
# Fixture
# ---------------------------------------------------------------------------#
import platform
from distutils.version import LooseVersion
from pkg_resources import parse_version

IS_DARWIN = platform.system().lower() == "darwin"
OSX_SIERRA = LooseVersion("10.12")
OSX_SIERRA = parse_version("10.12")
if IS_DARWIN:
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < LooseVersion(platform.mac_ver()[0])
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < parse_version(platform.mac_ver()[0])
SERIAL_PORT = '/dev/ptyp0' if not IS_HIGH_SIERRA_OR_ABOVE else '/dev/ttyp0'
else:
IS_HIGH_SIERRA_OR_ABOVE = False
Expand All @@ -43,8 +43,8 @@ class AsynchronousClientTest(unittest.TestCase):
def testBaseClientInit(self):
""" Test the client client initialize """
client = BaseTornadoClient()
self.assertTrue(client.port ==502)
self.assertTrue(client.host =="127.0.0.1")
self.assertTrue(client.port == 502)
self.assertTrue(client.host == "127.0.0.1")
self.assertEqual(0, len(list(client.transaction)))
self.assertFalse(client._connected)
self.assertTrue(client.io_loop is None)
Expand Down Expand Up @@ -95,7 +95,7 @@ def testBaseClientExecute(self, mock_iostream, mock_ioloop):

@patch("pymodbus.client.asynchronous.tornado.IOLoop")
@patch("pymodbus.client.asynchronous.tornado.IOStream")
def testBaseClientHandleResponse(self, mock_iostream, mock_ioloop):
def testBaseClientHandleResponse(self, mock_iostream, mock_ioloop):
""" Test the BaseTornado client handles responses """
client = AsyncModbusTCPClient(port=5020)
client.connect()
Expand Down Expand Up @@ -171,13 +171,15 @@ def handle_failure(failure):
client.close()
self.assertFalse(client._connected)


# -----------------------------------------------------------------------#
# Test Serial Client client
# -----------------------------------------------------------------------#
def testSerialClientInit(self):
""" Test the tornado serial client client initialize """
client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP, framer=ModbusRtuFramer(ClientDecoder()), port=SERIAL_PORT)
client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP,
framer=ModbusRtuFramer(
ClientDecoder()),
port=SERIAL_PORT)
self.assertEqual(0, len(list(client.transaction)))
self.assertTrue(isinstance(client.framer, ModbusRtuFramer))

Expand Down Expand Up @@ -309,6 +311,7 @@ def testModbusClientFactory(self):
factory = ModbusClientFactory()
self.assertTrue(factory is not None)


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
Expand Down
Loading