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
d552f1f2
Commit
d552f1f2
authored
May 23, 2018
by
jobasto
Committed by
oroulet
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for structs containing enums
parent
db91a3be
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
258 additions
and
2 deletions
+258
-2
tests/enum_struct_test_nodes.xml
tests/enum_struct_test_nodes.xml
+206
-0
tests/tests_client.py
tests/tests_client.py
+12
-2
tests/tests_enum_struct.py
tests/tests_enum_struct.py
+40
-0
No files found.
tests/enum_struct_test_nodes.xml
0 → 100644
View file @
d552f1f2
This diff is collapsed.
Click to expand it.
tests/tests_client.py
View file @
d552f1f2
...
...
@@ -10,6 +10,8 @@ from tests_subscriptions import SubscriptionTests
from
tests_common
import
CommonTests
,
add_server_methods
from
tests_xml
import
XmlTests
from
tests_enum_struct
import
add_server_custom_enum_struct
port_num1
=
48510
...
...
@@ -26,6 +28,7 @@ class TestClient(unittest.TestCase, CommonTests, SubscriptionTests, XmlTests):
cls
.
srv
=
Server
()
cls
.
srv
.
set_endpoint
(
'opc.tcp://127.0.0.1:{0:d}'
.
format
(
port_num1
))
add_server_methods
(
cls
.
srv
)
add_server_custom_enum_struct
(
cls
.
srv
)
cls
.
srv
.
start
()
# start admin client
...
...
@@ -110,7 +113,7 @@ class TestClient(unittest.TestCase, CommonTests, SubscriptionTests, XmlTests):
nenumstrings
=
self
.
clt
.
get_node
(
ua
.
ObjectIds
.
AxisScaleEnumeration_EnumStrings
)
with
self
.
assertNotRaises
(
Exception
):
value
=
ua
.
Variant
(
nenumstrings
.
get_value
())
def
test_uasocketclient_connect_disconnect
(
self
):
"""Initialize, connect, and disconnect a UaSocketClient
"""
...
...
@@ -118,8 +121,15 @@ class TestClient(unittest.TestCase, CommonTests, SubscriptionTests, XmlTests):
uaclt
.
connect_socket
(
'127.0.0.1'
,
port_num1
)
self
.
assertTrue
(
uaclt
.
_thread
.
is_alive
())
self
.
assertIsInstance
(
uaclt
.
_socket
,
SocketWrapper
)
# disconnect_socket() should shut down the receiving thread
uaclt
.
disconnect_socket
()
self
.
assertFalse
(
uaclt
.
_thread
.
is_alive
())
def
test_custom_enum_struct
(
self
):
self
.
ro_clt
.
load_type_definitions
()
ns
=
self
.
ro_clt
.
get_namespace_index
(
'http://yourorganisation.org/struct_enum_example/'
)
myvar
=
self
.
ro_clt
.
get_node
(
ua
.
NodeId
(
6009
,
ns
))
val
=
myvar
.
get_value
()
self
.
assertEqual
(
val
.
IntVal1
,
242
)
self
.
assertEqual
(
val
.
EnumVal
,
ua
.
ExampleEnum
.
EnumVal2
)
tests/tests_enum_struct.py
0 → 100644
View file @
d552f1f2
from
opcua
import
ua
from
opcua.ua
import
uatypes
from
enum
import
IntEnum
class
ExampleEnum
(
IntEnum
):
EnumVal1
=
0
EnumVal2
=
1
EnumVal3
=
2
import
opcua.ua
setattr
(
opcua
.
ua
,
'ExampleEnum'
,
ExampleEnum
)
class
ExampleStruct
(
uatypes
.
FrozenClass
):
ua_types
=
[
(
'IntVal1'
,
'Int16'
),
(
'EnumVal'
,
'ExampleEnum'
),
]
def
__init__
(
self
):
self
.
IntVal1
=
0
self
.
EnumVal
=
ExampleEnum
(
0
)
self
.
_freeze
=
True
def
__str__
(
self
):
return
'ExampleStruct('
+
'IntVal1:'
+
str
(
self
.
IntVal1
)
+
', '
+
\
'EnumVal:'
+
str
(
self
.
EnumVal
)
+
')'
__repr__
=
__str__
def
add_server_custom_enum_struct
(
server
):
# import some nodes from xml
server
.
import_xml
(
"tests/enum_struct_test_nodes.xml"
)
ns
=
server
.
get_namespace_index
(
'http://yourorganisation.org/struct_enum_example/'
)
uatypes
.
register_extension_object
(
'ExampleStruct'
,
ua
.
NodeId
(
5001
,
ns
),
ExampleStruct
)
val
=
ua
.
ExampleStruct
()
val
.
IntVal1
=
242
val
.
EnumVal
=
ua
.
ExampleEnum
.
EnumVal2
myvar
=
server
.
get_node
(
ua
.
NodeId
(
6009
,
ns
))
myvar
.
set_value
(
val
)
\ No newline at end of file
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