mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-28 21:11:41 -09:00
package/python-libyang: new package
Python CFFI bindings for the libyang YANG library, providing the 'libyang' Python module for YANG data modeling operations. This package is used by higher-level tooling such as python-sysrepo. https://github.com/CESNET/libyang-python Signed-off-by: Vincent Jardin <vjardin@free.fr> Signed-off-by: Vincent Cruz <mooz@blockos.org> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
committed by
Thomas Petazzoni
parent
50d017a2d6
commit
3872cf8a75
46
support/testing/tests/package/sample_python_libyang.py
Normal file
46
support/testing/tests/package/sample_python_libyang.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# test from https://github.com/CESNET/libyang-python/blob/master/README.rst
|
||||
|
||||
import libyang
|
||||
from xml.etree import ElementTree
|
||||
|
||||
ctx = libyang.Context()
|
||||
|
||||
module = ctx.parse_module_str('''
|
||||
module example {
|
||||
namespace "urn:example";
|
||||
prefix "ex";
|
||||
container data {
|
||||
list interface {
|
||||
key name;
|
||||
leaf name {
|
||||
type string;
|
||||
}
|
||||
leaf address {
|
||||
type string;
|
||||
}
|
||||
}
|
||||
leaf hostname {
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
''')
|
||||
|
||||
node = module.parse_data_dict({
|
||||
'data': {
|
||||
'hostname': 'foobar',
|
||||
'interface': [
|
||||
{'name': 'eth0', 'address': '1.2.3.4/24'},
|
||||
{'name': 'lo', 'address': '127.0.0.1'},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
xml = node.print_mem('xml', pretty=True)
|
||||
tree = ElementTree.fromstringlist(xml)
|
||||
assert tree.tag == '{urn:example}data'
|
||||
assert tree.find('.//{*}hostname').text == 'foobar'
|
||||
assert len(tree.find('.//{*}interface')) == 2
|
||||
|
||||
node.free()
|
||||
ctx.destroy()
|
||||
12
support/testing/tests/package/test_python_libyang.py
Normal file
12
support/testing/tests/package/test_python_libyang.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from tests.package.test_python import TestPythonPackageBase
|
||||
|
||||
|
||||
class TestPythonLibyang(TestPythonPackageBase):
|
||||
__test__ = True
|
||||
config = TestPythonPackageBase.config + \
|
||||
"""
|
||||
BR2_PACKAGE_PYTHON3=y
|
||||
BR2_PACKAGE_PYTHON3_PYEXPAT=y
|
||||
BR2_PACKAGE_PYTHON_LIBYANG=y
|
||||
"""
|
||||
sample_scripts = ["tests/package/sample_python_libyang.py"]
|
||||
Reference in New Issue
Block a user