Skip to content

Commit 32165ef

Browse files
stewegsamuel-gauthier
authored andcommitted
schema: fix of SLeafList defaults API
This patch fixes defaults API of SLeafList. The returned values are now correctly converted to python types. Closes: #119 Signed-off-by: Stefan Gula <[email protected]> Signed-off-by: Samuel Gauthier <[email protected]>
1 parent e1cefcf commit 32165ef

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

libyang/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,9 @@ def defaults(self) -> Iterator[Union[None, bool, int, str, float]]:
14201420
yield None
14211421
val = c2str(val)
14221422
val_type = Type(self.context, dflt.realtype, None)
1423-
if val_type == Type.BOOL:
1423+
if val_type.base() == Type.BOOL:
14241424
yield val == "true"
1425-
elif val_type in Type.NUM_TYPES:
1425+
elif val_type.base() in Type.NUM_TYPES:
14261426
yield int(val)
14271427
elif val_type.base() == Type.DEC64:
14281428
yield float(val)

tests/test_schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ def test_leaflist_defaults(self):
756756
leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/ratios"))
757757
for d in leaflist.defaults():
758758
self.assertIsInstance(d, float)
759+
leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/bools"))
760+
for d in leaflist.defaults():
761+
self.assertIsInstance(d, bool)
762+
leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/integers"))
763+
for d in leaflist.defaults():
764+
self.assertIsInstance(d, int)
759765

760766
def test_leaf_list_min_max(self):
761767
leaflist1 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list1"))

tests/yang/yolo/yolo-nodetypes.yang

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ module yolo-nodetypes {
4545
default 2.6;
4646
}
4747

48+
leaf-list bools {
49+
type boolean;
50+
default true;
51+
}
52+
53+
leaf-list integers {
54+
type uint32;
55+
default 10;
56+
default 20;
57+
}
58+
4859
list list1 {
4960
key leaf1;
5061
unique "leaf2 leaf3";

0 commit comments

Comments
 (0)