Skip to content

Commit 6c0727f

Browse files
jeremie6windsamuel-gauthier
authored andcommitted
schema: get features from compiled module
It is not always possible to get the features from the parsed module. It is the case for a module obtained from a sysrepo printed context. Introduce compiled_enabled_features that returns the features from the compiled object. Signed-off-by: Jeremie Leska <jeremie.leska@6wind.com>
1 parent f1898d5 commit 6c0727f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libyang/schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def features(self) -> Iterator["Feature"]:
110110
for i in features_list:
111111
yield Feature(self.context, i)
112112

113+
def compiled_enabled_features(self) -> Iterator[str]:
114+
if self.cdata.compiled:
115+
for f in ly_array_iter(self.cdata.compiled.features):
116+
yield c2str(f)
117+
113118
def get_feature(self, name: str) -> "Feature":
114119
for f in self.features():
115120
if f.name() == name:

tests/test_schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def test_mod_features(self):
108108
features = list(self.module.features())
109109
self.assertEqual(len(features), 2)
110110

111+
def test_mod_compiled_enabled_features(self):
112+
self.module.feature_enable("*")
113+
features = list(self.module.compiled_enabled_features())
114+
self.assertEqual(len(features), 2)
115+
111116
def test_mod_get_feature(self):
112117
self.module.feature_enable("turbo-boost")
113118
feature = self.module.get_feature("turbo-boost")

0 commit comments

Comments
 (0)