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
1ca9874f
Commit
1ca9874f
authored
Jan 24, 2021
by
oroulet
Committed by
oroulet
Mar 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial use of dataclass
parent
7a86b031
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
432 additions
and
370 deletions
+432
-370
asyncua/ua/ua_binary.py
asyncua/ua/ua_binary.py
+97
-52
asyncua/ua/uatypes.py
asyncua/ua/uatypes.py
+303
-295
tests/test_unit.py
tests/test_unit.py
+32
-23
No files found.
asyncua/ua/ua_binary.py
View file @
1ca9874f
This diff is collapsed.
Click to expand it.
asyncua/ua/uatypes.py
View file @
1ca9874f
This diff is collapsed.
Click to expand it.
tests/test_unit.py
View file @
1ca9874f
...
...
@@ -28,13 +28,13 @@ EXAMPLE_BSD_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "exam
def
test_variant_array_none
():
v
=
ua
.
Variant
(
None
,
variantt
ype
=
ua
.
VariantType
.
Int32
,
is_array
=
True
)
v
=
ua
.
Variant
(
None
,
VariantT
ype
=
ua
.
VariantType
.
Int32
,
is_array
=
True
)
data
=
variant_to_binary
(
v
)
v2
=
variant_from_binary
(
ua
.
utils
.
Buffer
(
data
))
assert
v
==
v2
assert
v2
.
is_array
v
=
ua
.
Variant
(
None
,
variantt
ype
=
ua
.
VariantType
.
Null
,
is_array
=
True
)
v
=
ua
.
Variant
(
None
,
VariantT
ype
=
ua
.
VariantType
.
Null
,
is_array
=
True
)
data
=
variant_to_binary
(
v
)
v2
=
variant_from_binary
(
ua
.
utils
.
Buffer
(
data
))
assert
v
==
v2
...
...
@@ -42,7 +42,7 @@ def test_variant_array_none():
def
test_variant_empty_list
():
v
=
ua
.
Variant
([],
variantt
ype
=
ua
.
VariantType
.
Int32
,
is_array
=
True
)
v
=
ua
.
Variant
([],
VariantT
ype
=
ua
.
VariantType
.
Int32
,
is_array
=
True
)
data
=
variant_to_binary
(
v
)
v2
=
variant_from_binary
(
ua
.
utils
.
Buffer
(
data
))
assert
v
==
v2
...
...
@@ -135,14 +135,14 @@ def test_custom_structs_array(tmpdir):
def
test_nodeid_nsu
():
n
=
ua
.
NodeId
(
100
,
2
)
n
.
NamespaceUri
=
"http://freeopcua/tests"
n
.
ServerIndex
=
4
data
=
nodeid_to_binary
(
n
)
n1
=
ua
.
ExpandedNodeId
(
100
,
2
,
NamespaceUri
=
"http://freeopcua/tests"
,
ServerIndex
=
4
)
data
=
nodeid_to_binary
(
n1
)
n2
=
nodeid_from_binary
(
ua
.
utils
.
Buffer
(
data
))
assert
n
==
n2
n3
=
ua
.
NodeId
.
from_string
(
n
.
to_string
())
assert
n
==
n3
assert
n1
==
n2
string
=
n1
.
to_string
()
print
(
string
)
n3
=
ua
.
NodeId
.
from_string
(
string
)
assert
n1
==
n3
def
test_nodeid_ordering
():
...
...
@@ -153,7 +153,7 @@ def test_nodeid_ordering():
e
=
ua
.
NodeId
(
"aaaaa"
,
1
)
f
=
ua
.
NodeId
(
"aaaaa"
,
2
)
g
=
ua
.
NodeId
(
uuid
.
uuid4
(),
1
)
h
=
ua
.
TwoByteNodeId
(
20
0
1
)
h
=
ua
.
TwoByteNodeId
(
201
)
i
=
ua
.
NodeId
(
b"lkjkl"
,
1
,
ua
.
NodeIdType
.
ByteString
)
j
=
ua
.
NodeId
(
b"aaa"
,
5
,
ua
.
NodeIdType
.
ByteString
)
...
...
@@ -333,7 +333,7 @@ def test_guid():
def
test_nodeid_guid_string
():
n
=
ua
.
GuidNodeId
(
i
dentifier
=
uuid
.
uuid4
())
n
=
ua
.
GuidNodeId
(
I
dentifier
=
uuid
.
uuid4
())
s
=
n
.
to_string
()
n2
=
ua
.
NodeId
.
from_string
(
s
)
s2
=
n2
.
to_string
()
...
...
@@ -361,9 +361,8 @@ def test__nodeid():
s1
=
ua
.
StringNodeId
(
"53"
,
0
)
bs
=
ua
.
ByteStringNodeId
(
b"53"
,
0
)
gid
=
uuid
.
uuid4
()
g
=
ua
.
ByteStringNodeId
(
str
(
gid
)
,
0
)
g
=
ua
.
ByteStringNodeId
(
gid
.
bytes
,
0
)
guid
=
ua
.
GuidNodeId
(
gid
)
assert
tb
==
fb
assert
tb
==
n
assert
tb
==
n1
assert
n1
==
fb
...
...
@@ -416,18 +415,18 @@ def test_expandednodeid():
def
test_null_guid
():
with
pytest
.
raises
(
ua
.
UaError
):
n
=
ua
.
NodeId
(
b'000000'
,
0
,
nodeidt
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000000000000'
),
0
,
nodeidt
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
b'000000'
,
0
,
NodeIdT
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000000000000'
),
0
,
NodeIdT
ype
=
ua
.
NodeIdType
.
Guid
)
assert
n
.
is_null
()
assert
n
.
has_null_identifier
()
with
pytest
.
raises
(
ua
.
UaError
):
n
=
ua
.
NodeId
(
b'000000'
,
1
,
nodeidt
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000000000000'
),
1
,
nodeidt
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
b'000000'
,
1
,
NodeIdT
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000000000000'
),
1
,
NodeIdT
ype
=
ua
.
NodeIdType
.
Guid
)
assert
not
n
.
is_null
()
assert
n
.
has_null_identifier
()
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000001000000'
),
1
,
nodeidt
ype
=
ua
.
NodeIdType
.
Guid
)
n
=
ua
.
NodeId
(
uuid
.
UUID
(
'00000000-0000-0000-0000-000001000000'
),
1
,
NodeIdT
ype
=
ua
.
NodeIdType
.
Guid
)
assert
not
n
.
is_null
()
assert
not
n
.
has_null_identifier
()
...
...
@@ -520,7 +519,7 @@ def test_unicode_string_nodeid():
def
test_numeric_nodeid
():
nid
=
ua
.
NodeId
(
999
,
2
)
nid
=
ua
.
N
umericN
odeId
(
999
,
2
)
assert
nid
.
NamespaceIndex
==
2
assert
nid
.
Identifier
==
999
assert
nid
.
NodeIdType
==
ua
.
NodeIdType
.
Numeric
...
...
@@ -588,7 +587,7 @@ def test_variant_array():
def
test_variant_array_dim
():
v
=
ua
.
Variant
([
1
,
2
,
3
,
4
,
5
,
6
],
d
imensions
=
[
2
,
3
])
v
=
ua
.
Variant
([
1
,
2
,
3
,
4
,
5
,
6
],
D
imensions
=
[
2
,
3
])
assert
v
.
Value
[
1
]
==
2
v2
=
variant_from_binary
(
ua
.
utils
.
Buffer
(
variant_to_binary
(
v
)))
assert
_reshape
(
v
.
Value
,
(
2
,
3
))
==
v2
.
Value
...
...
@@ -607,13 +606,23 @@ def test_text():
assert
t1
==
t4
def
test_text_simple
():
t
=
ua
.
LocalizedText
(
'Root'
)
b
=
struct_to_binary
(
t
)
print
(
"BIN"
,
b
)
buf
=
ua
.
utils
.
Buffer
(
b
)
print
(
"BUF"
,
buf
)
t2
=
struct_from_binary
(
ua
.
LocalizedText
,
buf
)
assert
t
==
t2
def
test_text_with_locale
():
t0
=
ua
.
LocalizedText
(
'Root'
)
t1
=
ua
.
LocalizedText
(
'Root'
,
'de-AT'
)
t2
=
ua
.
LocalizedText
(
'Root'
,
'de-AT'
)
t3
=
ua
.
LocalizedText
(
'Root'
,
'de-DE'
)
t4
=
ua
.
LocalizedText
(
l
ocale
=
'de-DE'
)
t5
=
ua
.
LocalizedText
(
l
ocale
=
'de-DE'
)
t4
=
ua
.
LocalizedText
(
L
ocale
=
'de-DE'
)
t5
=
ua
.
LocalizedText
(
L
ocale
=
'de-DE'
)
assert
t0
!=
t1
assert
t1
==
t2
assert
t1
!=
t3
...
...
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