Skip to content

Commit

Permalink
Add a test for the add_notification() function with structures
Browse files Browse the repository at this point in the history
  • Loading branch information
msfur committed Oct 8, 2024
1 parent bb00d34 commit 12d480b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,32 @@ def my_callback(*_):

self.assertAdsRequestsCount(3) # READWRITE, ADDNOTE and DELNOTE

def test_add_notification_structure(self):
"""Test notification registering for structures"""
structure_def = (
("a", pyads.PLCTYPE_INT, 1),
("b", pyads.PLCTYPE_INT, 1),
("s", pyads.PLCTYPE_STRING, 1)
)
values = [{"a": 1, "b": 2, "s": "foo"}, {"a": 3, "b": 4, "s": "bar"}]
data = bytes(bytes_from_dict(values, structure_def))

self.handler.add_variable(
PLCVariable("TestStructure", data, constants.ADST_VOID, symbol_type="TestStructure"))

def my_callback(*_):
return

with self.plc:

symbol = self.plc.get_symbol("TestStructure", structure_def=structure_def, array_size=2)

handles = symbol.add_device_notification(my_callback)

symbol.del_device_notification(handles)

self.assertAdsRequestsCount(3) # READWRITE, ADDNOTE and DELNOTE

def test_add_notification_delete(self):
"""Test notification registering"""

Expand Down

0 comments on commit 12d480b

Please sign in to comment.