forked from FreeOpcUa/python-opcua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_cmd_lines.py
55 lines (42 loc) · 1.81 KB
/
tests_cmd_lines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import unittest
import subprocess
from opcua import Server
port_num = 48530
class TestCmdLines(unittest.TestCase):
'''
Test command lines
'''
@classmethod
def setUpClass(cls):
cls.srv = Server()
cls.srv_url = 'opc.tcp://127.0.0.1:{0:d}'.format(port_num)
cls.srv.set_endpoint(cls.srv_url)
objects = cls.srv.get_objects_node()
obj = objects.add_object(4, "directory")
var = obj.add_variable(4, "variable", 1.999)
var2 = obj.add_variable(4, "variable2", 1.777)
var2.set_writable()
cls.srv.start()
def test_uals(self):
s = subprocess.check_output(["python", "tools/uals", "--url", self.srv_url])
self.assertIn(b"i=85", s)
self.assertNotIn(b"i=89", s)
self.assertNotIn(b"1.999", s)
s = subprocess.check_output(["python", "tools/uals", "--url", self.srv_url, "-d", "3"])
self.assertIn(b"1.999", s)
def test_uaread(self):
s = subprocess.check_output(["python", "tools/uaread", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable"])
self.assertIn(b"1.999", s)
def test_uawrite(self):
s = subprocess.check_output(["python", "tools/uawrite", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable2", "1.789"])
s = subprocess.check_output(["python", "tools/uaread", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable2"])
self.assertIn(b"1.789", s)
self.assertNotIn(b"1.999", s)
def test_uadiscover(self):
s = subprocess.check_output(["python", "tools/uadiscover", "--url", self.srv_url])
self.assertIn(b"opc.tcp://127.0.0.1", s)
self.assertIn(b"FreeOpcUa", s)
self.assertIn(b"urn:freeopcua:python:server", s)
@classmethod
def tearDownClass(cls):
cls.srv.stop()