1
|
|
|
|
2
|
|
|
import unittest |
3
|
|
|
import sys |
4
|
|
|
print("SYS:PATH", sys.path) |
5
|
|
|
sys.path.insert(0, "python-opcua") |
6
|
|
|
sys.path.insert(0, "opcua-widgets") |
7
|
|
|
import os |
8
|
|
|
print("PWD", os.getcwd()) |
9
|
|
|
|
10
|
|
|
from opcua import ua |
11
|
|
|
from opcua import Server |
12
|
|
|
|
13
|
|
|
from PyQt5.QtCore import QTimer, QSettings, QModelIndex, Qt, QCoreApplication |
14
|
|
|
from PyQt5.QtWidgets import QApplication |
15
|
|
|
from PyQt5.QtTest import QTest |
16
|
|
|
|
17
|
|
|
from uaclient.mainwindow import Window |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class TestClient(unittest.TestCase): |
21
|
|
|
def setUp(self): |
22
|
|
|
self.server = Server() |
23
|
|
|
url = "opc.tcp://localhost:48400/freeopcua/server/" |
24
|
|
|
self.server.set_endpoint(url) |
25
|
|
|
self.server.start() |
26
|
|
|
self.client = Window() |
27
|
|
|
self.client.ui.addrComboBox.setCurrentText(url) |
28
|
|
|
self.client.connect() |
29
|
|
|
|
30
|
|
|
def tearDown(self): |
31
|
|
|
self.client.disconnect() |
32
|
|
|
self.server.stop() |
33
|
|
|
|
34
|
|
|
def get_attr_value(self, text): |
35
|
|
|
idxlist = self.client.attrs_ui.model.match(self.client.attrs_ui.model.index(0, 0), Qt.DisplayRole, text, 1, Qt.MatchExactly | Qt.MatchRecursive) |
36
|
|
|
idx = idxlist[0] |
37
|
|
|
idx = idx.sibling(idx.row(), 1) |
38
|
|
|
item = self.client.attrs_ui.model.itemFromIndex(idx) |
39
|
|
|
return item.data(Qt.UserRole).value |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
def test_select_objects(self): |
43
|
|
|
objects = self.server.nodes.objects |
44
|
|
|
self.client.tree_ui.set_current_node("Objects") |
45
|
|
|
self.assertEqual(objects, self.client.tree_ui.get_current_node()) |
46
|
|
|
self.assertGreater(self.client.attrs_ui.model.rowCount(), 6) |
47
|
|
|
|
48
|
|
|
data = self.get_attr_value("NodeId") |
49
|
|
|
self.assertEqual(data, objects.nodeid) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
if __name__ == "__main__": |
53
|
|
|
app = QApplication(sys.argv) |
54
|
|
|
unittest.main() |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
|