Completed
Push — dev ( 14d7ed )
by Olivier
02:30
created

tests.TestCmdLines   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 44
ccs 33
cts 33
cp 1
rs 10
wmc 6

6 Methods

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