Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* client/sync.py: Fix missing serial module dependency The serial.connect failed in PR riptideio#400 with "NameError: name 'serial' is not defined" [1]: self = <ModbusSerialClient at 0x7fcda4009b00 socket=None, method=ascii, timeout=3> def connect(self): """ Connect to the modbus serial server :returns: True if connection succeeded, False otherwise """ if self.socket: return True try: > self.socket = serial.Serial(port=self.port, timeout=self.timeout, bytesize=self.bytesize, stopbits=self.stopbits, baudrate=self.baudrate, parity=self.parity) E NameError: name 'serial' is not defined pymodbus/client/sync.py:476: NameError This patch moves the serial import back to the head. [1] https://travis-ci.org/riptideio/pymodbus/jobs/566009109 Fixes: commit e6da559 asyncio server implementation (#400) * server/asyncio.py: Create server with appropriate args and environment If Python is older than 3.7, the create_server will fail like PR riptideio#400 with "unexpected keyword argument 'start_serving'" [1] which is new in Python version 3.7: self.server_factory = self.loop.create_server(lambda :self.handler(self), *self.address, reuse_address=allow_reuse_address, reuse_port=allow_reuse_port, backlog=backlog, > start_serving=not defer_start) E TypeError: create_server() got an unexpected keyword argument 'start_serving' pymodbus/server/asyncio.py:400: TypeError This patch creates server according to Python environment. [1] https://travis-ci.org/starnight/pymodbus/jobs/584178484 Fixes: commit e6da559 asyncio server implementation (#400) * Create asyncio task with appropriate method and environment If Python is older than 3.7, the asyncio.create_task will fail like PR riptideio#400 with "AttributeError: module 'asyncio' has no attribute 'create_task'" [1] which is new in Python version 3.7 [2]: @asyncio.coroutine def testTcpServerCloseActiveConnection(self): ''' Test server_close() while there are active TCP connections''' data = b"\x01\x00\x00\x00\x00\x06\x01\x01\x00\x00\x00\x01" server = yield from StartTcpServer(context=self.context,address=("127.0.0.1", 0),loop=self.loop) > server_task = asyncio.create_task(server.serve_forever()) E AttributeError: module 'asyncio' has no attribute 'create_task' test/test_server_asyncio.py:205: AttributeError This patch creates task according to Python environment. [1] https://travis-ci.org/starnight/pymodbus/jobs/584193587 [2] https://docs.python.org/3/library/asyncio-task.html#creating-tasks Fixes: commit e6da559 asyncio server implementation (#400) * server/asyncio.py: Fix format string for older Python If Python is older than 3.6, f-Strings will fail like PR riptideio#400 with "SyntaxError: invalid syntax" [1] which is new in Python version 3.6 with PEP 498 -- Literal String Interpolation [2]: test/test_server_asyncio.py:14: in <module> from pymodbus.server.asyncio import StartTcpServer, StartUdpServer, StartSerialServer, StopServer, ModbusServerFactory E File "/home/travis/build/starnight/pymodbus/pymodbus/server/asyncio.py", line 424 E _logger.warning(f"aborting active session {k}") E ^ E SyntaxError: invalid syntax This patch fixes the format string with traditional format string syntax. [1] https://travis-ci.org/starnight/pymodbus/jobs/584427976 [2] https://www.python.org/dev/peps/pep-0498/ Fixes: commit e6da559 asyncio server implementation (#400) * test: Make assert_called_once() test only with Python 3.6+ If Python is older than 3.6, unittest.mock.assert_called_once() will fail like PR riptideio#400 with "AttributeError: assert_called_once" [1] which is new in Python version 3.6 [2]: > self.loop.create_server.assert_called_once() test/test_server_asyncio.py:76: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <CoroutineMock name='mock.create_server' id='139638313234784'> name = 'assert_called_once' def __getattr__(self, name): if name in {'_mock_methods', '_mock_unsafe'}: raise AttributeError(name) elif self._mock_methods is not None: if name not in self._mock_methods or name in _all_magics: raise AttributeError("Mock object has no attribute %r" % name) elif _is_magic(name): raise AttributeError(name) if not self._mock_unsafe: if name.startswith(('assert', 'assret')): > raise AttributeError(name) E AttributeError: assert_called_once /opt/python/3.5.6/lib/python3.5/unittest/mock.py:585: AttributeError This patch skips the tests if they are not in Python 3.6+. [1] https://travis-ci.org/starnight/pymodbus/jobs/584431003 [2] https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_once Fixes: commit e6da559 asyncio server implementation (#400) * test: Make serve_forever() test only with Python 3.7+ If Python is older than 3.7, asyncio.base_events.Server.serve_forever will fail like PR riptideio#400 with "AttributeError: <class 'asyncio.base_events.Server'> does not have the attribute 'serve_forever'" [1] which is new in Python version 3.7 [2]: @asyncio.coroutine def testTcpServerServeNoDefer(self): ''' Test StartTcpServer without deferred start (immediate execution of server) ''' > with patch('asyncio.base_events.Server.serve_forever', new_callable=asynctest.CoroutineMock) as serve: test/test_server_asyncio.py:81: ... if not self.create and original is DEFAULT: raise AttributeError( > "%s does not have the attribute %r" % (target, name) ) E AttributeError: <class 'asyncio.base_events.Server'> does not have the attribute 'serve_forever' This patch skips the tests if they are not in Python 3.7+. [1] https://travis-ci.org/starnight/pymodbus/jobs/584212511 [2] https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.Server.serve_forever Fixes: commit e6da559 asyncio server implementation (#400)
- Loading branch information