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
dee4543e
Commit
dee4543e
authored
Oct 28, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix NodeId ordering
parent
1f3680bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
9 deletions
+28
-9
opcua/ua/uatypes.py
opcua/ua/uatypes.py
+11
-9
tests/tests_unit.py
tests/tests_unit.py
+17
-0
No files found.
opcua/ua/uatypes.py
View file @
dee4543e
...
...
@@ -221,7 +221,7 @@ class StatusCode(FrozenClass):
return
not
self
.
__eq__
(
other
)
class
NodeIdType
(
Enum
):
class
NodeIdType
(
Int
Enum
):
TwoByte
=
0
FourByte
=
1
Numeric
=
2
...
...
@@ -271,28 +271,30 @@ class NodeId(FrozenClass):
self
.
NodeIdType
=
NodeIdType
.
String
elif
isinstance
(
self
.
Identifier
,
bytes
):
self
.
NodeIdType
=
NodeIdType
.
ByteString
elif
isinstance
(
self
.
Identifier
,
uuid
.
UUID
):
self
.
NodeIdType
=
NodeIdType
.
Guid
else
:
raise
UaError
(
"NodeId: Could not guess type of NodeId, set NodeIdType"
)
def
_
_
key
(
self
):
if
self
.
NodeIdType
in
(
NodeIdType
.
TwoByte
,
NodeIdType
.
FourByte
,
NodeIdType
.
Numeric
):
# twobyte, fourbyte and numeric may represent the same node
return
self
.
NamespaceIndex
,
self
.
Identifier
else
:
return
self
.
NodeIdType
,
self
.
NamespaceIndex
,
self
.
Identifier
def
_key
(
self
):
if
self
.
NodeIdType
in
(
NodeIdType
.
TwoByte
,
NodeIdType
.
FourByte
,
NodeIdType
.
Numeric
):
# twobyte, fourbyte and numeric may represent the same node
return
(
NodeIdType
.
Numeric
,
self
.
NamespaceIndex
,
self
.
Identifier
)
return
(
self
.
NodeIdType
,
self
.
NamespaceIndex
,
self
.
Identifier
)
def
__eq__
(
self
,
node
):
return
isinstance
(
node
,
NodeId
)
and
self
.
_
_key
()
==
node
.
_
_key
()
return
isinstance
(
node
,
NodeId
)
and
self
.
_
key
()
==
node
.
_key
()
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
def
__hash__
(
self
):
return
hash
(
self
.
_
_
key
())
return
hash
(
self
.
_key
())
def
__lt__
(
self
,
other
):
if
not
isinstance
(
other
,
NodeId
):
raise
AttributeError
(
"Can only compare to NodeId"
)
return
self
.
_
_hash__
()
<
other
.
__hash__
()
return
self
.
_
key
()
<
other
.
_key
()
def
is_null
(
self
):
if
self
.
NamespaceIndex
!=
0
:
...
...
tests/tests_unit.py
View file @
dee4543e
...
...
@@ -24,6 +24,23 @@ class TestUnit(unittest.TestCase):
Simple unit test that do not need to setup a server or a client
'''
def
test_nodeid_ordering
(
self
):
a
=
ua
.
NodeId
(
2000
,
1
)
b
=
ua
.
NodeId
(
3000
,
1
)
c
=
ua
.
NodeId
(
20
,
0
)
d
=
ua
.
NodeId
(
"tititu"
,
1
)
e
=
ua
.
NodeId
(
"aaaaa"
,
1
)
f
=
ua
.
NodeId
(
"aaaaa"
,
2
)
g
=
ua
.
NodeId
(
uuid
.
uuid4
(),
1
)
h
=
ua
.
TwoByteNodeId
(
2001
)
i
=
ua
.
NodeId
(
b"lkjkl"
,
1
)
j
=
ua
.
NodeId
(
b"aaa"
,
5
)
mylist
=
[
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
i
,
j
]
mylist
.
sort
()
expected
=
[
c
,
h
,
a
,
b
,
e
,
d
,
f
,
g
,
i
,
j
]
self
.
assertEqual
(
mylist
,
expected
)
def
test_string_to_variant_int
(
self
):
s_arr_uint
=
"[1, 2, 3, 4]"
arr_uint
=
[
1
,
2
,
3
,
4
]
...
...
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