13
13
import pytest_asyncio
14
14
15
15
from examples .client_async import run_async_client , setup_async_client
16
- from examples .client_calls import run_async_calls , run_sync_calls
16
+ from examples .client_calls import run_sync_calls
17
17
from examples .client_sync import run_sync_client , setup_sync_client
18
+ from examples .client_test import run_async_calls as run_async_simple_calls
18
19
from examples .helper import get_commandline
19
20
from examples .server_async import run_async_server , setup_server
20
21
from examples .server_sync import run_sync_server
21
22
from pymodbus import pymodbus_apply_logging_config
22
23
from pymodbus .server import ServerAsyncStop , ServerStop
23
- from pymodbus .transaction import (
24
- ModbusAsciiFramer ,
25
- ModbusBinaryFramer ,
26
- ModbusRtuFramer ,
27
- ModbusSocketFramer ,
28
- ModbusTlsFramer ,
29
- )
30
24
31
25
32
26
_logger = logging .getLogger ()
33
27
_logger .setLevel ("DEBUG" )
34
28
pymodbus_apply_logging_config ("DEBUG" )
35
29
TEST_COMMS_FRAMER = [
36
30
("tcp" , "socket" , 5020 ),
37
- ("tcp" , "rtu" , 5021 ),
31
+ ("tcp" , "rtu" , 5020 ),
38
32
("tls" , "tls" , 5020 ),
39
33
("udp" , "socket" , 5020 ),
40
- ("udp" , "rtu" , 5021 ),
41
- ("serial" , "rtu" , 5020 ),
42
- ("serial" , "ascii" , 5021 ),
43
- ("serial" , "binary" , 5022 ),
34
+ ("udp" , "rtu" , 5020 ),
35
+ ("serial" , "rtu" , "socket://127.0.0.1: 5020" ),
36
+ # awaiting fix: ("serial", "ascii", "socket://127.0.0.1:5020" ),
37
+ # awaiting fix: ("serial", "binary", "socket://127.0.0.1:5020" ),
44
38
]
45
- TEST_CONVERT_FRAMER = {
46
- "socket" : ModbusSocketFramer ,
47
- "rtu" : ModbusRtuFramer ,
48
- "tls" : ModbusTlsFramer ,
49
- "ascii" : ModbusAsciiFramer ,
50
- "binary" : ModbusBinaryFramer ,
51
- }
52
39
53
40
54
41
@pytest_asyncio .fixture (name = "mock_run_server" )
55
42
async def _helper_server (
56
43
test_comm ,
57
44
test_framer ,
58
- test_port_offset ,
59
45
test_port ,
60
46
):
61
47
"""Run server."""
62
- if pytest .IS_WINDOWS and test_comm == "serial" :
63
- yield
64
- return
65
- port = test_port + test_port_offset
66
- if test_comm == "serial" :
67
- port = f"socket://127.0.0.1:{ port } "
68
48
cmdline = [
69
49
"--comm" ,
70
50
test_comm ,
71
51
"--port" ,
72
- str (port ),
52
+ str (test_port ),
73
53
"--framer" ,
74
54
test_framer ,
75
55
"--baudrate" ,
@@ -86,37 +66,6 @@ async def _helper_server(
86
66
await task
87
67
88
68
89
- async def run_client (test_comm , test_type , port = None , cmdline = None ):
90
- """Help run async client."""
91
- if not cmdline :
92
- cmdline = [
93
- "--comm" ,
94
- test_comm ,
95
- "--host" ,
96
- "127.0.0.1" ,
97
- "--baudrate" ,
98
- "9600" ,
99
- "--log" ,
100
- "debug" ,
101
- ]
102
- if test_comm == "serial" :
103
- port = f"socket://127.0.0.1:{ port } "
104
-
105
- cmdline .extend (
106
- [
107
- "--port" ,
108
- str (port ),
109
- ]
110
- )
111
-
112
- test_client = setup_async_client (cmdline = cmdline )
113
- if not test_type :
114
- await run_async_client (test_client )
115
- else :
116
- await run_async_client (test_client , modbus_calls = test_type )
117
- await asyncio .sleep (0.1 )
118
-
119
-
120
69
def test_get_commandline ():
121
70
"""Test helper get_commandline()"""
122
71
args = get_commandline (cmdline = ["--log" , "info" ])
@@ -125,56 +74,46 @@ def test_get_commandline():
125
74
126
75
127
76
@pytest .mark .xdist_group (name = "server_serialize" )
128
- @pytest .mark .parametrize ("test_port_offset" , [10 ])
129
77
@pytest .mark .parametrize ("test_comm, test_framer, test_port" , TEST_COMMS_FRAMER )
130
78
async def test_exp_async_server_client (
131
79
test_comm ,
132
80
test_framer ,
133
- test_port_offset ,
134
81
test_port ,
135
82
mock_run_server ,
136
83
):
137
84
"""Run async client and server."""
138
- # JAN WAITING
139
- if pytest .IS_WINDOWS and test_comm == "serial" :
140
- return
141
- if test_comm in {"tcp" , "tls" }:
142
- return
143
85
assert not mock_run_server
144
-
145
- port = test_port + test_port_offset
146
86
cmdline = [
147
87
"--comm" ,
148
88
test_comm ,
149
89
"--host" ,
150
90
"127.0.0.1" ,
151
91
"--framer" ,
152
92
test_framer ,
93
+ "--port" ,
94
+ str (test_port ),
153
95
"--baudrate" ,
154
96
"9600" ,
155
97
"--log" ,
156
98
"debug" ,
157
99
]
158
-
159
- await run_client ( test_comm , None , port = port , cmdline = cmdline )
100
+ test_client = setup_async_client ( cmdline = cmdline )
101
+ await run_async_client ( test_client , modbus_calls = run_async_simple_calls )
160
102
161
103
162
104
@pytest .mark .xdist_group (name = "server_serialize" )
163
- @pytest .mark .parametrize ("test_port_offset" , [20 ])
164
105
@pytest .mark .parametrize ("test_comm, test_framer, test_port" , [TEST_COMMS_FRAMER [0 ]])
165
106
def test_exp_sync_server_client (
166
107
test_comm ,
167
108
test_framer ,
168
- test_port_offset ,
169
109
test_port ,
170
110
):
171
111
"""Run sync client and server."""
172
- port = test_port + test_port_offset
173
112
cmdline = [
174
113
"--comm" ,
175
114
test_comm ,
176
115
"--port" ,
177
- str (port ),
116
+ str (test_port ),
178
117
"--baudrate" ,
179
118
"9600" ,
180
119
"--log" ,
@@ -190,36 +129,3 @@ def test_exp_sync_server_client(
190
129
test_client = setup_sync_client (cmdline = cmdline )
191
130
run_sync_client (test_client , modbus_calls = run_sync_calls )
192
131
ServerStop ()
193
-
194
-
195
- # JAN
196
- @pytest .mark .xdist_group (name = "server_serialize" )
197
- @pytest .mark .parametrize ("test_port_offset" , [30 ])
198
- @pytest .mark .parametrize ("test_comm, test_framer, test_port" , TEST_COMMS_FRAMER )
199
- async def xtest_exp_framers_calls (
200
- test_comm ,
201
- test_framer ,
202
- test_port_offset ,
203
- test_port ,
204
- mock_run_server ,
205
- ):
206
- """Test client-server async with different framers and calls."""
207
- assert not mock_run_server
208
- if test_comm == "serial" and test_framer in (ModbusAsciiFramer , ModbusBinaryFramer ):
209
- return
210
- if pytest .IS_WINDOWS and test_comm == "serial" :
211
- return
212
- port = test_port + test_port_offset
213
- cmdline = [
214
- "--comm" ,
215
- test_comm ,
216
- "--host" ,
217
- "127.0.0.1" ,
218
- "--framer" ,
219
- test_framer ,
220
- "--baudrate" ,
221
- "9600" ,
222
- "--log" ,
223
- "debug" ,
224
- ]
225
- await run_client (test_comm , run_async_calls , port = port , cmdline = cmdline )
0 commit comments