Test Our Installed Package
The ydk-gen generate.py utility automatically creates Python UnitTest test cases for verifying that the Python classes that were generated from the YANG models you used can be imported properly.
Run the Unit Test
After your package has been generated, the unit tests will be located in the following location:
ydk-gen/gen-api/python/package_name-bundle/ydk/models/package_name/test/import_tests.py
Change directories into the ydk-gen/gen-api direcotory for this next step:
cd /workspace/ydk-gen/gen-api
To run the test for the classes we generated, perform the following:
python3.6 python/openconfig_interfaces_lab-bundle/ydk/models/openconfig_interfaces_lab/test/import_tests.py
Verify Tests Passed
If all steps were followed correctly, the unit test will have passed and the output will look as follows:
[root@234c5dde8ad6 gen-api]# python3.6 python/openconfig_interfaces_lab-bundle/ydk/models/openconfig_interfaces_lab/test/import_tests.py
./usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/ydk: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/ydk/models: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:18: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:40: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:98: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:182: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:285: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:527: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:595: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:652: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:707: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:746: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:796: DeprecationWarning: invalid escape sequence \-
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:863: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:959: DeprecationWarning: invalid escape sequence \:
"""
/usr/lib/python3.6/site-packages/ydk/models/openconfig_interfaces_lab/openconfig_interfaces.py:1199: DeprecationWarning: invalid escape sequence \-
"""
.
----------------------------------------------------------------------
Ran 2 tests in 0.208s
OK
[root@234c5dde8ad6 gen-api]# python3.6 python/openconfig_interfaces_lab-bundle/ydk/models/openconfig_interfaces_lab/test/import_tests.py
If your tests did not pass, revisit prior modules to confirm all steps were followed exactly.
The Anatomy of the Tests
The unit tests that are generated are very crude and just confirm the ability to import your classes. Let's take a look at what ydk-gen actually created:
import unittest
class ImportTest(unittest.TestCase):
def test_openconfig_extensions(self):
pass
def test_openconfig_interfaces(self):
from ydk.models.openconfig_interfaces_lab.openconfig_interfaces import Interfaces
if __name__ == '__main__':
unittest.main()
This is just foundational Python unittest usage. In the next set of modules, we will explore actually using
YANG models to interact with our device topology.