Skip to content

Commit fdfabf9

Browse files
samuel-gauthierrjarry
authored andcommitted
schema: fix type module method
The module function of the Type class was not working. Fix it, and restore the unit test. Note that it returns the module where the type is defined, not the typedef. Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com> Acked-by: Robin Jarry <robin@jarry.cc>
1 parent 7dea0b2 commit fdfabf9

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

libyang/schema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,9 @@ def all_patterns(self) -> Iterator[Tuple[str, bool]]:
626626
yield from self.patterns()
627627

628628
def module(self) -> Module:
629-
# TODO: pointer to the parsed module wehere is the type defined is in self.cdata_parsed.pmod
630-
# however there is no way how to get name of the module from lysp_module
631-
if not self.cdata.der.module:
629+
if not self.cdata_parsed:
632630
return None
633-
return Module(self.context, self.cdata.der.module)
631+
return Module(self.context, self.cdata_parsed.pmod.mod)
634632

635633
def extensions(self) -> Iterator[ExtensionCompiled]:
636634
for extension in ly_array_iter(self.cdata.exts):

tests/test_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ def test_leaf_type_derived(self):
376376
self.assertIsInstance(t, Type)
377377
self.assertEqual(t.name(), "types:host")
378378
self.assertEqual(t.base(), Type.STRING)
379-
# mod = t.module()
380-
# self.assertIsNot(mod, None)
381-
# self.assertEqual(mod.name(), "wtf-types")
379+
mod = t.module()
380+
self.assertIsNot(mod, None)
381+
self.assertEqual(mod.name(), "yolo-system")
382382

383383
def test_leaf_type_status(self):
384384
leaf = next(self.ctx.find_path("/yolo-system:conf/yolo-system:hostname"))

0 commit comments

Comments
 (0)