Skip to content

Commit

Permalink
test: Make tests having yield from only with Python 3
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
starnight committed Sep 18, 2019
1 parent 762ebfb commit f01cf8f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/test_server_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '''
Expand All @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand All @@ -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 '''
Expand All @@ -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 '''
Expand All @@ -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 '''
Expand All @@ -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 '''
Expand Down Expand Up @@ -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'''
Expand Down Expand Up @@ -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 '''
Expand Down

0 comments on commit f01cf8f

Please sign in to comment.