Passed
Branch master (fc7bd2)
by Olivier
05:47 queued 02:15
created

TestCmdLines   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
ccs 33
cts 33
cp 1
rs 10
wmc 6
1
import unittest
2
import subprocess
3
4
from opcua import Server
5
6
7
port_num = 48530
8
9
10
class TestCmdLines(unittest.TestCase):
11
12
    '''
13
    Test command lines
14
    '''
15
    @classmethod
16
    def setUpClass(self):
17
        self.srv = Server()
18
        self.srv_url = 'opc.tcp://localhost:%d' % port_num
19
        self.srv.set_endpoint(self.srv_url)
20
        objects = self.srv.get_objects_node()
21
        obj = objects.add_object(4, "directory")
22
        var = obj.add_variable(4, "variable", 1.999)
23
        var2 = obj.add_variable(4, "variable2", 1.777)
24
        var2.set_writable()
25
        self.srv.start()
26
27
    def test_uals(self):
28
        s = subprocess.check_output(["python", "tools/uals", "--url", self.srv_url])
29
        self.assertIn(b"i=85", s)
30
        self.assertNotIn(b"i=89", s)
31
        self.assertNotIn(b"1.999", s)
32
        s = subprocess.check_output(["python", "tools/uals", "--url", self.srv_url, "-d", "3"])
33
        self.assertIn(b"1.999", s)
34
35
    def test_uaread(self):
36
        s = subprocess.check_output(["python", "tools/uaread", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable"])
37
        self.assertIn(b"1.999", s)
38
39
    def test_uawrite(self):
40
        s = subprocess.check_output(["python", "tools/uawrite", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable2", "1.789"])
41
        s = subprocess.check_output(["python", "tools/uaread", "--url", self.srv_url, "--path", "0:Objects,4:directory,4:variable2"])
42
        self.assertIn(b"1.789", s)
43
        self.assertNotIn(b"1.999", s)
44
45
    def test_uadiscover(self):
46
        s = subprocess.check_output(["python", "tools/uadiscover", "--url", self.srv_url])
47
        self.assertIn(b"opc.tcp://localhost", s)
48
        self.assertIn(b"FreeOpcUa", s)
49
        self.assertIn(b"urn:freeopcua:python:server", s)
50
51
    @classmethod
52
    def tearDownClass(self):
53
        self.srv.stop()
54
55
56