Skip to content

Commit 3218727

Browse files
authored
Bump coverage to 95,5% (#2658)
1 parent e2f3b39 commit 3218727

13 files changed

+29
-223
lines changed

doc/source/_static/examples.tgz

592 KB
Binary file not shown.

doc/source/_static/examples.zip

-14 Bytes
Binary file not shown.

doc/source/client.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ It is allowed to have multiple client objects that e.g. each communicate with a
1515

1616
Client performance
1717
------------------
18-
There are currently a big performance gap between the 2 clients
19-
(try it on your computer :github:`examples/client_performance.py`).
18+
There are currently a big performance gap between the 2 clients.
19+
2020
This is due to a rather old implementation of the synchronous client, we are currently working to update the client code.
2121
Our aim is to achieve a similar data rate with both clients and at least double the data rate while keeping the stability.
2222
Table below is a test with 1000 calls each reading 10 registers.

doc/source/examples.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ Source: :github:`examples/simple_sync_client.py`
3131
.. literalinclude:: ../../examples/simple_sync_client.py
3232

3333

34-
Client performance sync vs async
35-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36-
Source: :github:`examples/client_performance.py`
37-
38-
.. literalinclude:: ../../examples/client_performance.py
39-
40-
4134
Advanced examples
4235
-----------------
4336

@@ -169,15 +162,6 @@ Source: :github:`examples/message_parser.py`
169162
:noindex:
170163

171164

172-
Modbus forwarder
173-
^^^^^^^^^^^^^^^^
174-
Source: :github:`examples/modbus_forwarder.py`
175-
176-
.. automodule:: examples.modbus_forwarder
177-
:undoc-members:
178-
:noindex:
179-
180-
181165
Examples contributions
182166
----------------------
183167

examples/client_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def template_call(client):
6060
"""Show complete modbus call, sync version."""
6161
try:
6262
rr = client.read_coils(32, count=1, device_id=DEVICE_ID)
63-
except client_sync.ModbusException as exc:
63+
except client_sync.ModbusException as exc: # pragma: no cover
6464
txt = f"ERROR: exception in pymodbus {exc}"
6565
_logger.error(txt)
6666
raise exc

examples/client_performance.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

examples/client_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def setup_sync_client(description=None, cmdline=None):
8383
# UDP setup parameters
8484
# source_address=None,
8585
)
86-
elif args.comm == "serial":
86+
elif args.comm == "serial": # pragma: no cover
8787
client = modbusClient.ModbusSerialClient(
8888
port=args.port, # serial port
8989
# Common optional parameters:
@@ -97,7 +97,7 @@ def setup_sync_client(description=None, cmdline=None):
9797
# stopbits=1,
9898
# handle_local_echo=False,
9999
)
100-
elif args.comm == "tls":
100+
elif args.comm == "tls": # pragma: no cover
101101
client = modbusClient.ModbusTlsClient(
102102
args.host,
103103
port=args.port,

examples/modbus_forwarder.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

examples/package_test_tool.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ def __init__(self, comm: CommType):
119119
host,
120120
port=test_port,
121121
)
122-
elif comm == CommType.SERIAL:
122+
else: # if comm == CommType.SERIAL:
123123
host = f"{NULLMODEM_HOST}:{test_port}"
124124
self.client = modbusClient.AsyncModbusSerialClient(
125125
host,
126126
)
127-
else:
128-
raise RuntimeError("ERROR: CommType not implemented")
129127
server_params = self.client.ctx.comm_params.copy()
130128
server_params.source_address = (host, test_port)
131129
self.stub = TransportStub(server_params, True, simulate_server)
@@ -142,6 +140,7 @@ async def run(self):
142140
await client_calls(self.client)
143141
Log.debug("--> Closing.")
144142
self.client.close()
143+
self.stub.close()
145144

146145

147146
class ServerTester: # pylint: disable=too-few-public-methods
@@ -169,19 +168,14 @@ def __init__(self, comm: CommType):
169168
identity=self.identity,
170169
address=(NULLMODEM_HOST, test_port),
171170
)
172-
elif comm == CommType.SERIAL:
171+
else: # if comm == CommType.SERIAL:
173172
self.server = modbusServer.ModbusSerialServer(
174173
self.context,
175174
framer=FramerType.SOCKET,
176175
identity=self.identity,
177176
port=f"{NULLMODEM_HOST}:{test_port}",
178177
)
179-
else:
180-
raise RuntimeError("ERROR: CommType not implemented")
181178
client_params = self.server.comm_params.copy()
182-
if client_params.source_address:
183-
client_params.host = client_params.source_address[0]
184-
client_params.port = client_params.source_address[1]
185179
client_params.timeout_connect = 1.0
186180
self.stub = TransportStub(client_params, False, simulate_client)
187181
test_port += 1
@@ -195,7 +189,8 @@ async def run(self):
195189
await self.stub.start_run()
196190
await server_calls(self.stub, (self.comm == CommType.TCP))
197191
Log.debug("--> Shutting down.")
198-
await self.server.shutdown()
192+
self.stub.close()
193+
self.server.close()
199194

200195

201196
async def main(comm: CommType, use_server: bool):
@@ -215,11 +210,11 @@ async def client_calls(client):
215210
Log.debug("--> Client calls starting.")
216211
try:
217212
resp = await client.read_holding_registers(address=124, count=4, device_id=1)
218-
except ModbusException as exc:
213+
except ModbusException as exc: # pragma: no cover
219214
txt = f"ERROR: exception in pymodbus {exc}"
220215
Log.error(txt)
221216
return
222-
if resp.isError():
217+
if resp.isError(): # pragma: no cover
223218
txt = "ERROR: pymodbus returned an error!"
224219
Log.error(txt)
225220
await asyncio.sleep(1)
@@ -231,7 +226,7 @@ async def server_calls(transport: ModbusProtocol, is_tcp: bool):
231226
Log.debug("--> Server calls starting.")
232227

233228
if is_tcp:
234-
request = b'\x00\x02\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01'
229+
request = b'\x00\x02\x00\x00\x00\x06\x00\x03\x00\x00\x00\x01'
235230
else:
236231
# 2 responses:
237232
# response = b'\x00\x02\x00\x00\x00\x06\x01\x03\x00\x00\x00\x01' +
@@ -247,7 +242,7 @@ def simulate_server(transport: ModbusProtocol, is_tcp: bool, request: bytes):
247242
"""Respond to request at transport level."""
248243
Log.debug("--> Server simulator called with request {}.", request, ":hex")
249244
if is_tcp:
250-
response = b'\x00\x01\x00\x00\x00\x06\x00\x03\x00\x7c\x00\x04'
245+
response = b'\x00\x01\x00\x00\x00\x06\x01\x03\x00\x7c\x00\x04'
251246
else:
252247
response = b'\x01\x03\x08\x00\x05\x00\x05\x00\x00\x00\x00\x0c\xd7'
253248

@@ -260,12 +255,15 @@ def simulate_server(transport: ModbusProtocol, is_tcp: bool, request: bytes):
260255

261256
def simulate_client(_transport: ModbusProtocol, _is_tcp: bool, response: bytes):
262257
"""Respond to request at transport level."""
263-
Log.debug("--> Client simulator called with response {}.", response, ":hex")
258+
Log.debug("--> Client simulator called with response {}.", response, ":hex") # pragma: no cover
264259

260+
async def run_test():
261+
"""Run whole test."""
262+
await main(CommType.SERIAL, False)
263+
await main(CommType.SERIAL, True)
264+
await main(CommType.TCP, False)
265+
await main(CommType.TCP, True)
265266

266267
if __name__ == "__main__":
267268
# True for Server test, False for Client test
268-
asyncio.run(main(CommType.SERIAL, False), debug=True)
269-
asyncio.run(main(CommType.SERIAL, True), debug=True)
270-
asyncio.run(main(CommType.TCP, False), debug=True)
271-
asyncio.run(main(CommType.TCP, True), debug=True)
269+
asyncio.run(run_test(), debug=True)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ exclude_also = [
244244
"if __name__ == .__main__.:",
245245
]
246246
skip_covered = true
247-
fail_under = 93.0
247+
fail_under = 95.5
248248

249249
[tool.coverage.html]
250250
directory = "build/cov"

test/examples/test_client_server_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ async def test_server_client_twice(self, mock_server, use_comm, mock_clc):
6565
await run_async_client(test_client, modbus_calls=run_a_few_calls)
6666
await asyncio.sleep(0.5)
6767
await run_async_client(test_client, modbus_calls=run_a_few_calls)
68+
await run_async_client(test_client)
6869

6970
async def test_client_no_server(self, mock_clc):
7071
"""Run async client without server."""

test/examples/test_client_server_sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def test_server_client_twice(self, mock_cls, mock_clc, use_comm):
8787
run_sync_client(test_client, modbus_calls=run_a_few_calls)
8888
sleep(SLEEPING)
8989
run_sync_client(test_client, modbus_calls=run_a_few_calls)
90+
run_sync_client(test_client)
9091
ServerStop()
9192

9293
def test_client_no_server(self, mock_clc):

0 commit comments

Comments
 (0)