Skip to content

Commit d164c08

Browse files
Sascha Bleidnerrjarry
authored andcommitted
data: fix attribute error in find_all
Fixes: 49fd8ea ("Add data tree support")
1 parent b01eb98 commit d164c08

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ struct lys_node_list {
316316

317317
union ly_set_set {
318318
struct lys_node **s;
319+
struct lyd_node **d;
319320
...;
320321
};
321322

libyang/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def find_all(self, xpath: str) -> Iterator["DNode"]:
241241
raise self.context.error("cannot find path")
242242
try:
243243
for i in range(node_set.number):
244-
yield DNode.new(self.context, node_set.d[i])
244+
yield DNode.new(self.context, node_set.set.d[i])
245245
finally:
246246
lib.ly_set_free(node_set)
247247

tests/test_data.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest.mock import patch
88

99
from _libyang import lib
10-
from libyang import Context, DContainer, DDiff, DRpc, LibyangError
10+
from libyang import Context, DContainer, DDiff, DNode, DRpc, LibyangError
1111

1212

1313
YANG_DIR = os.path.join(os.path.dirname(__file__), "yang")
@@ -565,3 +565,34 @@ def test_data_diff(self):
565565

566566
dnode1.free()
567567
dnode2.free()
568+
569+
def test_find_one(self):
570+
dnode = self.ctx.parse_data_mem(self.JSON_CONFIG, "json", config=True)
571+
self.assertIsInstance(dnode, DContainer)
572+
try:
573+
hostname = dnode.find_one("hostname")
574+
self.assertIsInstance(hostname, DNode)
575+
self.assertEqual(hostname.name(), "hostname")
576+
finally:
577+
dnode.free()
578+
579+
def test_find_all(self):
580+
dnode = self.ctx.parse_data_mem(self.JSON_CONFIG, "json", config=True)
581+
self.assertIsInstance(dnode, DContainer)
582+
try:
583+
urls = dnode.find_all("url")
584+
urls = list(urls)
585+
self.assertEqual(len(urls), 2)
586+
expected_url = {
587+
"url": [
588+
{
589+
"proto": "https",
590+
"host": "github.com",
591+
"path": "/CESNET/libyang-python",
592+
"enabled": False,
593+
}
594+
]
595+
}
596+
self.assertEqual(urls[0].print_dict(absolute=False), expected_url)
597+
finally:
598+
dnode.free()

0 commit comments

Comments
 (0)