Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,18 @@ def when_conditions(self):
for cond in ly_array_iter(wh):
yield c2str(lib.lyxp_get_expr(cond.cond))

def when_conditions_nodes(self) -> Iterator[Optional["SNode"]]:
wh = ffi.new("struct lysc_when **")
wh = lib.lysc_node_when(self.cdata)
if wh == ffi.NULL:
return
for cond in ly_array_iter(wh):
yield (
None
if cond.context == ffi.NULL
else SNode.new(self.context, cond.context)
)

def parsed(self) -> Optional["PNode"]:
if self.cdata_parsed is None or self.cdata_parsed == ffi.NULL:
return None
Expand Down
8 changes: 8 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,14 @@ def tearDown(self):
self.ctx.destroy()
self.ctx = None

def test_anydata(self):
snode = next(self.ctx.find_path("/yolo-nodetypes:any1"))
self.assertIsInstance(snode, SAnydata)
assert next(snode.when_conditions()) is not None
snode2 = next(snode.when_conditions_nodes())
assert isinstance(snode2, SAnydata)
assert snode2.cdata == snode.cdata

def test_anydata_parsed(self):
snode = next(self.ctx.find_path("/yolo-nodetypes:any1"))
self.assertIsInstance(snode, SAnydata)
Expand Down