Skip to content
Merged
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
4 changes: 2 additions & 2 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def default(self) -> Union[None, bool, int, str, float]:
val_type_cdata,
ffi.NULL,
)
if ret != lib.LY_SUCCESS:
if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE):
raise self.context.error("Unable to get real type of default value")
self.cdata_default_realtype = Type(self.context, val_type_cdata[0], None)

Expand Down Expand Up @@ -1619,7 +1619,7 @@ def defaults(self) -> Iterator[Union[None, bool, int, str, float]]:
val_type_cdata,
ffi.NULL,
)
if ret != lib.LY_SUCCESS:
if ret not in (lib.LY_SUCCESS, lib.LY_EINCOMPLETE):
raise self.context.error("Unable to get real type of default value")
self.cdata_default_realtypes.append(
Type(self.context, val_type_cdata[0], None)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ def test_must(self):
def test_leaf_default(self):
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage"))
self.assertIsInstance(leaf.default(), float)
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/leafref1"))
self.assertIsInstance(leaf.default(), str)
self.assertEqual("ASD", leaf.default())

def test_leaf_parsed(self):
leaf = next(self.ctx.find_path("/yolo-nodetypes:conf/percentage"))
Expand Down Expand Up @@ -789,6 +792,9 @@ def test_leaflist_defaults(self):
leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/integers"))
for d in leaflist.defaults():
self.assertIsInstance(d, int)
leaflist3 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list3"))
for d in leaflist3.defaults():
self.assertIsInstance(d, str)

def test_leaf_list_min_max(self):
leaflist1 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list1"))
Expand Down
14 changes: 14 additions & 0 deletions tests/yang/yolo/yolo-nodetypes.yang
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ module yolo-nodetypes {
leaf-list leaf-list2 {
type string;
}

leaf leafref1 {
type leafref {
path "/records/name";
}
default "ASD";
}

leaf-list leaf-list3 {
type leafref {
path "/records/name";
}
default "ASD";
}
}

leaf test1 {
Expand Down