Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
7e9f42f2
Commit
7e9f42f2
authored
Aug 06, 2016
by
maljac
Committed by
ORD
Aug 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Server] Respect parentid in xml import, Add tests and fix
parent
14a33c98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+9
-2
tests/tests_unit.py
tests/tests_unit.py
+29
-1
No files found.
opcua/common/xmlparser.py
View file @
7e9f42f2
...
...
@@ -141,15 +141,19 @@ class XMLParser(object):
# inserted nodes
if
node
.
parent
in
sorted_nodes_ids
:
insert
=
-
1
if
insert
in
[
0
,
-
1
]:
if
insert
==
0
:
sorted_nodes
.
insert
(
insert
,
node
)
sorted_nodes_ids
.
insert
(
insert
,
node
.
nodeid
)
pop_nodes
.
append
(
node
)
elif
insert
==
-
1
:
sorted_nodes
.
append
(
node
)
sorted_nodes_ids
.
append
(
node
.
nodeid
)
pop_nodes
.
append
(
node
)
# Remove inserted nodes from the list
for
node
in
pop_nodes
:
_nodes
.
pop
(
_nodes
.
index
(
node
))
return
sorted_nodes
def
_split_node_id
(
self
,
value
):
...
...
@@ -183,6 +187,9 @@ class XMLParser(object):
return
result
def
_parse_node
(
self
,
name
,
child
):
"""
Parse a XML node and create a NodeData object.
"""
obj
=
NodeData
()
obj
.
nodetype
=
name
for
key
,
val
in
child
.
attrib
.
items
():
...
...
tests/tests_unit.py
View file @
7e9f42f2
...
...
@@ -4,6 +4,7 @@ import logging
import
io
from
datetime
import
datetime
import
unittest
from
collections
import
namedtuple
from
opcua
import
ua
from
opcua.ua
import
extensionobject_from_binary
...
...
@@ -413,7 +414,7 @@ class TestUnit(unittest.TestCase):
n
=
ua
.
NodeId
(
0
,
3
)
self
.
assertFalse
(
n
.
is_null
())
self
.
assertTrue
(
n
.
has_null_identifier
())
def
test_where_clause
(
self
):
cf
=
ua
.
ContentFilter
()
...
...
@@ -458,6 +459,33 @@ class TestUnit(unittest.TestCase):
res4
=
parser
.
_get_node_id
(
'ns=2;i=1001'
)
self
.
assertEqual
(
res4
,
'ns=2;i=1001'
)
def
test_xmlparser_sort_nodes_by_parentid
(
self
):
NodeMock
=
namedtuple
(
'NodeMock'
,
'nodeid parent'
)
server
=
None
# We actually dont need this. Thus we just pass the available file
xml_path
=
'tests/custom_nodes.xml'
unordered_nodes
=
[
NodeMock
(
'ns=1;i=1001'
,
None
),
NodeMock
(
'ns=1;i=1002'
,
'ns=1;i=1003'
),
NodeMock
(
'ns=1;i=1003'
,
'ns=1;i=1001'
),
NodeMock
(
'ns=1;i=1004'
,
'ns=1;i=1002'
)
]
ordered_nodes
=
[
unordered_nodes
[
0
],
unordered_nodes
[
2
],
unordered_nodes
[
1
],
unordered_nodes
[
3
],
]
namespaces
=
{
'1'
:
(
1
,
'http://someuri.com'
)}
parser
=
XMLParser
(
xml_path
,
server
)
parser
.
namespaces
=
namespaces
res
=
parser
.
_sort_nodes_by_parentid
(
unordered_nodes
)
self
.
assertEqual
(
res
,
ordered_nodes
)
class
TestMaskEnum
(
unittest
.
TestCase
):
class
MyEnum
(
_MaskEnum
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment