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
0beb0005
Commit
0beb0005
authored
Jan 23, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for CustomVariant, remove Encoding attribute of Variant
parent
b90da16a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
opcua/ua/uatypes.py
opcua/ua/uatypes.py
+12
-9
tests/tests.py
tests/tests.py
+15
-0
No files found.
opcua/ua/uatypes.py
View file @
0beb0005
...
@@ -776,11 +776,16 @@ class VariantTypeCustom(object):
...
@@ -776,11 +776,16 @@ class VariantTypeCustom(object):
def
__init__
(
self
,
val
):
def
__init__
(
self
,
val
):
self
.
name
=
"Custom"
self
.
name
=
"Custom"
self
.
value
=
val
self
.
value
=
val
if
self
.
value
>
0b00111111
:
raise
UAError
(
"Cannot create VariantType. VariantType must be %s > x > %s"
,
0b111111
,
25
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"VariantType.Custom:{}"
.
format
(
self
.
value
)
return
"VariantType.Custom:{}"
.
format
(
self
.
value
)
__repr__
=
__str__
__repr__
=
__str__
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
class
Variant
(
FrozenClass
):
class
Variant
(
FrozenClass
):
...
@@ -796,8 +801,7 @@ class Variant(FrozenClass):
...
@@ -796,8 +801,7 @@ class Variant(FrozenClass):
:vartype VariantType: VariantType
:vartype VariantType: VariantType
"""
"""
def
__init__
(
self
,
value
=
None
,
varianttype
=
None
,
encoding
=
0
,
dimensions
=
None
):
def
__init__
(
self
,
value
=
None
,
varianttype
=
None
,
dimensions
=
None
):
self
.
Encoding
=
encoding
self
.
Value
=
value
self
.
Value
=
value
self
.
VariantType
=
varianttype
self
.
VariantType
=
varianttype
self
.
Dimensions
=
dimensions
self
.
Dimensions
=
dimensions
...
@@ -851,18 +855,17 @@ class Variant(FrozenClass):
...
@@ -851,18 +855,17 @@ class Variant(FrozenClass):
def
to_binary
(
self
):
def
to_binary
(
self
):
b
=
[]
b
=
[]
mask
=
self
.
Encoding
&
0b00111111
encoding
=
self
.
VariantType
.
value
&
0b111111
self
.
Encoding
=
(
self
.
VariantType
.
value
|
mask
)
if
type
(
self
.
Value
)
in
(
list
,
tuple
):
if
type
(
self
.
Value
)
in
(
list
,
tuple
):
if
self
.
Dimensions
is
not
None
:
if
self
.
Dimensions
is
not
None
:
self
.
Encoding
=
set_bit
(
self
.
E
ncoding
,
6
)
encoding
=
set_bit
(
e
ncoding
,
6
)
self
.
Encoding
=
set_bit
(
self
.
E
ncoding
,
7
)
encoding
=
set_bit
(
e
ncoding
,
7
)
b
.
append
(
uatype_UInt8
.
pack
(
self
.
E
ncoding
))
b
.
append
(
uatype_UInt8
.
pack
(
e
ncoding
))
b
.
append
(
pack_uatype_array
(
self
.
VariantType
.
name
,
flatten
(
self
.
Value
)))
b
.
append
(
pack_uatype_array
(
self
.
VariantType
.
name
,
flatten
(
self
.
Value
)))
if
self
.
Dimensions
is
not
None
:
if
self
.
Dimensions
is
not
None
:
b
.
append
(
pack_uatype_array
(
"Int32"
,
self
.
Dimensions
))
b
.
append
(
pack_uatype_array
(
"Int32"
,
self
.
Dimensions
))
else
:
else
:
b
.
append
(
uatype_UInt8
.
pack
(
self
.
E
ncoding
))
b
.
append
(
uatype_UInt8
.
pack
(
e
ncoding
))
b
.
append
(
pack_uatype
(
self
.
VariantType
.
name
,
self
.
Value
))
b
.
append
(
pack_uatype
(
self
.
VariantType
.
name
,
self
.
Value
))
return
b""
.
join
(
b
)
return
b""
.
join
(
b
)
...
@@ -886,7 +889,7 @@ class Variant(FrozenClass):
...
@@ -886,7 +889,7 @@ class Variant(FrozenClass):
dimensions
=
unpack_uatype_array
(
"Int32"
,
data
)
dimensions
=
unpack_uatype_array
(
"Int32"
,
data
)
value
=
reshape
(
value
,
dimensions
)
value
=
reshape
(
value
,
dimensions
)
return
Variant
(
value
,
vtype
,
encoding
,
dimensions
)
return
Variant
(
value
,
vtype
,
dimensions
)
def
reshape
(
flat
,
dims
):
def
reshape
(
flat
,
dims
):
...
...
tests/tests.py
View file @
0beb0005
...
@@ -134,6 +134,21 @@ class Unit(unittest.TestCase):
...
@@ -134,6 +134,21 @@ class Unit(unittest.TestCase):
self
.
assertEqual
(
dims
,
[
4
])
self
.
assertEqual
(
dims
,
[
4
])
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
l
,
l2
)
def
test_custom_variant
(
self
):
with
self
.
assertRaises
(
ua
.
UAError
):
v
=
ua
.
Variant
(
b"ljsdfljds"
,
ua
.
VariantTypeCustom
(
89
))
v
=
ua
.
Variant
(
b"ljsdfljds"
,
ua
.
VariantTypeCustom
(
61
))
v2
=
ua
.
Variant
.
from_binary
(
ua
.
utils
.
Buffer
(
v
.
to_binary
()))
self
.
assertEqual
(
v
.
VariantType
,
v2
.
VariantType
)
self
.
assertEqual
(
v
,
v2
)
def
test_custom_variant_array
(
self
):
v
=
ua
.
Variant
([
b"ljsdfljds"
,
b"lkjsdljksdf"
],
ua
.
VariantTypeCustom
(
40
))
v2
=
ua
.
Variant
.
from_binary
(
ua
.
utils
.
Buffer
(
v
.
to_binary
()))
self
.
assertEqual
(
v
.
VariantType
,
v2
.
VariantType
)
self
.
assertEqual
(
v
,
v2
)
def
test_guid
(
self
):
def
test_guid
(
self
):
g
=
ua
.
Guid
()
g
=
ua
.
Guid
()
sc
=
ua
.
StatusCode
()
sc
=
ua
.
StatusCode
()
...
...
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