Skip to content

Commit 7edc1c4

Browse files
committed
fix tests
1 parent f5a7cf5 commit 7edc1c4

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
.idea/workspace.xml
55
.idea/vcs.xml
66
.idea/misc.xml
7-
.idea/modules.xml
7+
.idea/modules.xml
8+
*.sw*
9+
.mypy*
10+
dist*
11+
*.egg*

.travis.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ language: python
22
python:
33
- "3.6"
44
env:
5-
- DISPLAY=:99.0
6-
before_install:
7-
- sh -e /etc/init.d/xvfb start
5+
- QT_QPA_PLATFORM=minimal
86
install:
9-
- pip install python-dateutil
10-
- pip install cryptography
117
- pip install pytest
128
- pip install pyqt5
13-
- pip install pytz
14-
- pip install lxml
15-
- git clone https://github.com/FreeOpcUa/python-opcua.git
16-
- git clone https://github.com/FreeOpcUa/opcua-widgets.git
9+
- pip install opcua
10+
- pip install opcua-widgets
1711
# command to run tests
18-
script: pytest -v
12+
script: pytest -v -s

test_uamodeler.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
import sys
33
import pytest
4+
import time
45

56
from opcua import ua
67

7-
from PyQt5.QtCore import QTimer, QSettings, QModelIndex, Qt, QCoreApplication
8+
from PyQt5.QtCore import QTimer, QSettings, QModelIndex, Qt, QCoreApplication, QEventLoop
89
from PyQt5.QtWidgets import QApplication, QAbstractItemDelegate
910

1011
from uamodeler.uamodeler import UaModeler
@@ -51,7 +52,7 @@ def test_save_open_xml(modeler, mgr):
5152
val = 0.99
5253
mgr.new_model()
5354
modeler.tree_ui.expand_to_node("Objects")
54-
node = mgr.add_variable(1, "myvar", val)
55+
node = mgr.add_variable(0, "myvar", val)
5556
mgr.save_xml(path)
5657
mgr.close_model()
5758
with pytest.raises(Exception):
@@ -88,13 +89,12 @@ def test_delete_save(modeler, mgr, model):
8889
modeler.tree_ui.expand_to_node("Objects")
8990
obj_node = mgr.add_folder(1, "myobj")
9091
obj2_node = mgr.add_folder(1, "myobj2")
91-
QApplication.processEvents()
92+
QApplication.processEvents(QEventLoop.WaitForMoreEvents|QEventLoop.AllEvents)
9293
modeler.tree_ui.expand_to_node("myobj2")
9394
var_node = mgr.add_variable(1, "myvar", val)
9495
mgr.save_ua_model(path)
9596
mgr.save_xml(path)
96-
97-
QApplication.processEvents()
97+
QApplication.processEvents(QEventLoop.WaitForMoreEvents|QEventLoop.AllEvents)
9898
modeler.tree_ui.expand_to_node(obj2_node)
9999
mgr.delete_node(obj2_node)
100100
mgr.save_ua_model(path)
@@ -165,6 +165,8 @@ def test_structs_2(modeler, mgr):
165165
modeler.tree_ui.expand_to_node(struct_node)
166166
mystruct = mgr.add_data_type(1, "MyStruct")
167167
QApplication.processEvents()
168+
QApplication.processEvents()
169+
QApplication.processEvents()
168170
modeler.tree_ui.expand_to_node("MyStruct")
169171
var_node = mgr.add_variable(1, "myvar", 0.1)
170172

uamodeler/model_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _get_path(self, path):
211211
path = self.current_path
212212
if path is None:
213213
raise ValueError("No path is defined")
214-
self.current_path = os.path.splitext(path)[0]
214+
self.current_path = os.path.splitext(path)[0]
215215
self.titleChanged.emit(self.current_path)
216216
return self.current_path
217217

@@ -347,7 +347,11 @@ def _save_structs(self):
347347
struct_node = self.server_mgr.get_node(ua.ObjectIds.Structure)
348348
dict_name = "TypeDictionary"
349349
idx = 1
350-
urn = self.server_mgr.get_namespace_array()[1]
350+
ar = self.server_mgr.get_namespace_array()
351+
if len(ar) == 1:
352+
#no custom namepsace defined, there should not be any structures
353+
return
354+
urn = self.server_mgr.get_namespace_array()[idx]
351355
to_delete = []
352356
have_structs = False
353357
to_add = []

0 commit comments

Comments
 (0)