Skip to content

Commit 4a8e693

Browse files
committed
TestModbusProtocol test_init passes
1 parent ffbe043 commit 4a8e693

File tree

1 file changed

+5
-109
lines changed

1 file changed

+5
-109
lines changed

tests/protocols_tests.py

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,16 @@ class TestModbusProtocol():
256256
else:
257257
raise OSError
258258

259-
# TODO
260-
@SkipTest
261259
def test_init(self):
262260

263261
# TODO: add _stop_server
264262
modbus = ModbusProtocol(
265263
protocol=TestModbusProtocol.CLIENT_PROTOCOL)
266-
eq_(modbus._name, 'modbustcp')
264+
eq_(modbus._name, 'modbus')
267265
del modbus
268266
modbus = ModbusProtocol(
269267
protocol=TestModbusProtocol.CLIENT_SERVER_PROTOCOL)
270-
eq_(modbus._name, 'modbustcp')
268+
eq_(modbus._name, 'modbus')
271269

272270
@SkipTest
273271
def test_server_stop(self):
@@ -280,19 +278,7 @@ def test_server_stop(self):
280278
except Exception as error:
281279
print 'ERROR test_server_stop: ', error
282280

283-
# TODO
284281
@SkipTest
285-
def test_server_start(self):
286-
287-
ADDRESS = 'localhost:44818' # TEST port
288-
TAGS = (('SENSOR1', 'INT'), ('ACTUATOR1', 'INT'))
289-
try:
290-
print "TEST: client has to kill the cpppo process."
291-
ModbusProtocol._start_server(ADDRESS, TAGS)
292-
# TODO: add _stop_server
293-
except Exception as error:
294-
print 'ERROR test_server_start: ', error
295-
296282
def test_server_start_cmd(self):
297283

298284
try:
@@ -304,102 +290,12 @@ def test_server_start_cmd(self):
304290

305291
# TODO
306292
@SkipTest
307-
def test_server_udp(self):
308-
309-
pass
310-
311-
# TODO
312-
@SkipTest
313-
def test_send_multikey(self):
314-
315-
enip = ModbusProtocol(
316-
protocol=CLIENT_PROTOCOL)
317-
318-
TAGS = (('SENSOR1', 1, 'INT'), ('ACTUATOR1', 'INT'))
319-
cmd = ModbusProtocol._start_server_cmd(tags=TAGS)
320-
try:
321-
server = subprocess.Popen(cmd, shell=False)
322-
323-
# write a multikey
324-
what = ('SENSOR1', 1)
325-
address = 'localhost:44818'
326-
for value in range(5):
327-
enip._send(what, value, address)
328-
329-
# write a single key
330-
what = ('ACTUATOR1',)
331-
address = 'localhost:44818'
332-
for value in range(5):
333-
enip._send(what, value, address)
334-
335-
ModbusProtocol._stop_server(server)
336-
337-
except Exception as error:
338-
ModbusProtocol._stop_server(server)
339-
print 'ERROR test_client: ', error
340-
341-
# TODO
342-
@SkipTest
343-
def test_receive_multikey(self):
344-
345-
enip = ModbusProtocol(
346-
protocol=CLIENT_PROTOCOL)
347-
348-
TAGS = (('SENSOR1', 1, 'INT'), ('ACTUATOR1', 'INT'))
349-
cmd = ModbusProtocol._start_server_cmd(tags=TAGS)
350-
try:
351-
server = subprocess.Popen(cmd, shell=False)
352-
353-
# read a multikey
354-
what = ('SENSOR1', 1)
355-
address = 'localhost:44818'
356-
enip._receive(what, address)
357-
358-
# read a single key
359-
what = ('ACTUATOR1',)
360-
address = 'localhost:44818'
361-
enip._receive(what, address)
362-
363-
ModbusProtocol._stop_server(server)
364-
365-
except Exception as error:
366-
ModbusProtocol._stop_server(server)
367-
print 'ERROR test_client: ', error
368-
369-
# TODO
370-
@SkipTest
371-
def test_client_server(self):
293+
def test_server_start_stop(self):
372294

373295
try:
374-
enip = ModbusProtocol(
375-
protocol=CLIENT_SERVER_PROTOCOL)
376-
377-
# read a multikey
378-
what = ('SENSOR1', 1)
379-
address = 'localhost:44818'
380-
enip._receive(what, address)
381-
382-
# read a single key
383-
what = ('ACTUATOR1',)
384-
address = 'localhost:44818'
385-
enip._receive(what, address)
386-
387-
# write a multikey
388-
what = ('SENSOR1', 1)
389-
address = 'localhost:44818'
390-
for value in range(5):
391-
enip._send(what, value, address)
392-
393-
# write a single key
394-
what = ('ACTUATOR1',)
395-
address = 'localhost:44818'
396-
for value in range(5):
397-
enip._send(what, value, address)
398-
399-
ModbusProtocol._stop_server(enip._server_subprocess)
296+
ModbusProtocol._start_server(ADDRESS, TAGS)
400297

401298
except Exception as error:
402-
ModbusProtocol._stop_server(enip._server_subprocess)
403-
print 'ERROR test_client_server: ', error
299+
print 'ERROR test_server_start: ', error
404300

405301
# }}}

0 commit comments

Comments
 (0)