mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-01 18:47:48 +00:00
YANG: tests: validate our sample data against the YANG model
I'm using the yagnson library for this, and that library needs two
pieces of data as its inputs:
- a "YANG Module Library", which is usually a JSON description of all
available and activated YANG modules along its enabled features, etc,
- actual YANG models, typically specified as a list of filesystem paths
which hold them.
I generated that ietf-yanglib file via something like:
$ python path/to/yangson/tools/python/mkylib.py \
gnpy/yang/ext \
gnpy/yang/tip \
> gnpy/yang/yanglib.json`
When this adds support for `ietf-geo-location` in future, make sure to
edit the output so that it does not accidentally enable all of the
geolocation features (but that's for later, anyway). And we might
actually not end up doing that.
Change-Id: I51e342cd556ecc381ff0bf35df2bfa70f5f83ba8
This commit is contained in:
@@ -6,11 +6,12 @@
|
||||
# see LICENSE.md for a list of contributors
|
||||
#
|
||||
|
||||
from gnpy.yang import external_path, model_path
|
||||
from gnpy.yang import external_path, model_path, create_datamodel
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
import pytest
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
def _get_basename(filename: Path) -> str:
|
||||
@@ -44,3 +45,18 @@ def _validate_yang_model(filename: Path, options: List[str]):
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True)
|
||||
assert proc.stderr == ''
|
||||
assert proc.stdout == ''
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _yangson_datamodel():
|
||||
return create_datamodel
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filename", (Path(__file__).parent / 'yang').glob('*.json'), ids=_get_basename)
|
||||
def test_validate_yang_data(_yangson_datamodel, filename: Path):
|
||||
'''Validate a JSON file against our YANG models'''
|
||||
dm = _yangson_datamodel()
|
||||
with open(filename, 'r') as f:
|
||||
raw_json = json.load(f)
|
||||
data = dm.from_raw(raw_json)
|
||||
data.validate()
|
||||
|
||||
Reference in New Issue
Block a user