From f01cf8fc76684194ecc2975a54d6b68464eed480 Mon Sep 17 00:00:00 2001 From: Jian-Hong Pan Date: Wed, 18 Sep 2019 23:24:05 +0800 Subject: [PATCH] test: Make tests having yield from only with Python 3 If Python is older than 3.3, "yield from" will be SyntaxError like PR riptideio#400 with "SyntaxError: invalid syntax" [1]. It is defined in PEP 380 -- Syntax for Delegating to a Subgenerator [2]: __import__(modname) E File "/home/travis/build/riptideio/pymodbus/test/test_server_asyncio.py", line 74 E server = yield from StartTcpServer(context=self.context,loop=self.loop,identity=identity) E ^ E SyntaxError: invalid syntax This patch skips the tests if they are not in Python 3. [1] https://travis-ci.org/riptideio/pymodbus/jobs/584493268 [2] https://www.python.org/dev/peps/pep-0380/ --- test/test_server_asyncio.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_server_asyncio.py b/test/test_server_asyncio.py index 372c964791..332f4e788f 100755 --- a/test/test_server_asyncio.py +++ b/test/test_server_asyncio.py @@ -93,6 +93,7 @@ def testTcpServerServeForever(self): yield from server.serve_forever() serve.assert_awaited() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerServeForeverTwice(self): ''' Call on serve_forever() twice should result in a runtime error ''' @@ -106,6 +107,7 @@ def testTcpServerServeForeverTwice(self): yield from server.serve_forever() server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerReceiveData(self): ''' Test data sent on socket is received by internals - doesn't not process data ''' @@ -140,6 +142,7 @@ def eof_received(self): self.assertTrue( process.call_args[1]["data"] == data ) server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerRoundtrip(self): ''' Test sending and receiving data on tcp socket ''' @@ -180,6 +183,7 @@ def eof_received(self): yield from asyncio.sleep(0) server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerConnectionLost(self): ''' Test tcp stream interruption ''' @@ -213,6 +217,7 @@ def connection_made(self, transport): self.assertTrue( len(server.active_connections) == 0 ) server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerCloseActiveConnection(self): ''' Test server_close() while there are active TCP connections ''' @@ -245,6 +250,7 @@ def connection_made(self, transport): yield from asyncio.sleep(0.0) self.assertTrue( len(server.active_connections) == 0 ) + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerException(self): ''' Sending garbage data on a TCP socket should drop the connection ''' @@ -283,6 +289,7 @@ def eof_received(self): # neither of these should timeout if the test is successful server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerNoSlave(self): ''' Test unknown slave unit exception ''' @@ -319,6 +326,7 @@ def eof_received(self): self.assertFalse(eof.done()) server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerModbusError(self): ''' Test sending garbage data on a TCP socket should drop the connection ''' @@ -358,6 +366,7 @@ def eof_received(self): transport.close() server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testTcpServerInternalException(self): ''' Test sending garbage data on a TCP socket should drop the connection ''' @@ -404,6 +413,7 @@ def eof_received(self): # Test ModbusUdpProtocol #-----------------------------------------------------------------------# + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testStartUdpServer(self): ''' Test that the modbus udp asyncio server starts correctly ''' @@ -430,6 +440,7 @@ def testUdpServerServeForeverStart(self): yield from server.serve_forever() serve.assert_awaited() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerServeForeverClose(self): ''' Test StartUdpServer serve_forever() method ''' @@ -446,6 +457,7 @@ def testUdpServerServeForeverClose(self): server.server_close() self.assertTrue(server.protocol.is_closing()) + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerServeForeverTwice(self): ''' Call on serve_forever() twice should result in a runtime error ''' @@ -461,6 +473,7 @@ def testUdpServerServeForeverTwice(self): yield from server.serve_forever() server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerReceiveData(self): ''' Test that the sending data on datagram socket gets data pushed to framer ''' @@ -482,6 +495,7 @@ def testUdpServerReceiveData(self): server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerSendData(self): ''' Test that the modbus udp asyncio server correctly sends data outbound ''' @@ -524,6 +538,7 @@ def datagram_received(self, data, addr): self.assertTrue(server.protocol.is_closing()) yield from asyncio.sleep(0.1) + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerRoundtrip(self): ''' Test sending and receiving data on udp socket''' @@ -562,6 +577,7 @@ def datagram_received(self, data, addr): yield from asyncio.sleep(0) server.server_close() + @pytest.mark.skipif(not IS_PYTHON3, reason="requires python3.4 or above") @asyncio.coroutine def testUdpServerException(self): ''' Test sending garbage data on a TCP socket should drop the connection '''