Skip to content

Commit 0664af0

Browse files
committed
TestModbusProtocol add test_client_server
1 parent 94bd27c commit 0664af0

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

tests/protocols_tests.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def test_receive_multikey(self):
167167

168168
def test_client_server(self):
169169

170+
ADDRESS = 'localhost:44818'
171+
170172
try:
171173

172174
# same instance used as server and client
@@ -175,25 +177,21 @@ def test_client_server(self):
175177

176178
# read a multikey
177179
what = ('SENSOR1', 1)
178-
address = 'localhost:44818'
179-
enip._receive(what, address)
180+
enip._receive(what, ADDRESS)
180181

181182
# read a single key
182183
what = ('ACTUATOR1',)
183-
address = 'localhost:44818'
184-
enip._receive(what, address)
184+
enip._receive(what, ADDRESS)
185185

186186
# write a multikey
187187
what = ('SENSOR1', 1)
188-
address = 'localhost:44818'
189188
for value in range(5):
190-
enip._send(what, value, address)
189+
enip._send(what, value, ADDRESS)
191190

192191
# write a single key
193192
what = ('ACTUATOR1',)
194-
address = 'localhost:44818'
195193
for value in range(5):
196-
enip._send(what, value, address)
194+
enip._send(what, value, ADDRESS)
197195

198196
EnipProtocol._stop_server(enip._server_subprocess)
199197

@@ -355,4 +353,37 @@ def test_receive(self):
355353
ModbusProtocol._stop_server(server)
356354
print 'ERROR test_receive: ', error
357355

356+
def test_client_server(self):
357+
358+
ADDRESS = 'localhost:502'
359+
360+
try:
361+
362+
# same instance used as server and client
363+
modbus = ModbusProtocol(
364+
protocol=CLIENT_SERVER_PROTOCOL)
365+
366+
# read a multikey
367+
what = ('CO', 0)
368+
eq_(modbus._receive(what, ADDRESS), [False] * 8)
369+
370+
# read a single key
371+
what = ('HR', 0)
372+
eq_(modbus._receive(what, ADDRESS), [False] * 8)
373+
374+
# write a multikey
375+
what = ('SENSOR1', 1)
376+
for value in range(5):
377+
modbus._send(what, value, ADDRESS)
378+
379+
# write a single key
380+
what = ('ACTUATOR1',)
381+
for value in range(5):
382+
modbus._send(what, value, ADDRESS)
383+
384+
ModbusProtocol._stop_server(modbus._server_subprocess)
385+
386+
except Exception as error:
387+
ModbusProtocol._stop_server(modbus._server_subprocess)
388+
print 'ERROR test_client_server: ', error
358389
# }}}

0 commit comments

Comments
 (0)