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

TestCmdLines.test_uawrite()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
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