mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-02 02:57:52 +00:00
YANG: Prepare for distributing YANG modules
I'm using a second-level module namespace (gnpy.yang) for the same reasons as when shipping the example data via gnpy/example-data/ -- these will be used in the subsequent commits when we actually start adding YANG models. There is also some code (not much now, a lot more in future) for working with these models, and in future also for loading actual data. These *could* be put into gnpy.tools.*, but I think it's more straightforward to just keep them in the YANG namespace. Change-Id: Ic40738ddd8346429bde01e591d19fd2ce8cb687d
This commit is contained in:
46
tests/test_yang_validation.py
Normal file
46
tests/test_yang_validation.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
# Tests for YANG models of GNPy
|
||||
#
|
||||
# Copyright (C) 2020 Telecom Infra Project and GNPy contributors
|
||||
# see LICENSE.md for a list of contributors
|
||||
#
|
||||
|
||||
from gnpy.yang import external_path, model_path
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
import pytest
|
||||
import subprocess
|
||||
|
||||
|
||||
def _get_basename(filename: Path) -> str:
|
||||
try:
|
||||
return filename.name
|
||||
except AttributeError:
|
||||
return filename
|
||||
|
||||
|
||||
@pytest.mark.parametrize("yang_model", external_path().glob('*.yang'), ids=_get_basename)
|
||||
def test_lint_external_yang(yang_model):
|
||||
'''Run a basic linter on all third-party models'''
|
||||
_validate_yang_model(yang_model, [])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("yang_model", model_path().glob('*.yang'), ids=_get_basename)
|
||||
def test_lint_gnpy_yang(yang_model):
|
||||
'''Run a linter on GNPy's YANG models'''
|
||||
_validate_yang_model(yang_model, ('--canonical', '--strict', '--lint'))
|
||||
|
||||
|
||||
def _validate_yang_model(filename: Path, options: List[str]):
|
||||
'''Run actual validation'''
|
||||
# I would have loved to use pyang programatically from here, but it seems that the API is really designed
|
||||
# around that interactive use case where code just expects an OptParser as a part of the library context,
|
||||
# etc.
|
||||
# Given that I'm only interested in a simple pass/fail scenario, let's just invoke the linter as a standalone
|
||||
# process and check if it screams.
|
||||
proc = subprocess.run(
|
||||
('pyang', '-p', ':'.join((str(external_path()), str(model_path()))), *options, filename),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True)
|
||||
assert proc.stderr == ''
|
||||
assert proc.stdout == ''
|
||||
Reference in New Issue
Block a user