Skip to content

Commit

Permalink
Add tests for documentation
Browse files Browse the repository at this point in the history
This is for the 2017 Hackathon
napalm-automation/hackathon-2017#10

This commit validates that each Ansible module has a DOCUMENTATION
and an EXAMPLES variable. It also asserts that those variables are
properly formatted YAML strings.
  • Loading branch information
ogenstad committed Nov 17, 2017
1 parent 9c3d61d commit 186e1f3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ install:
- pip install pylama
- pip install napalm-base
- pip install "ansible>=$ANSIBLE_VERSION.0,<$ANSIBLE_VERSION.99"
- pip install tox

script:
- pylama
- cd tests
- ./run_tests.sh
- ./test_changelog.sh
- cd ..
- tox

deploy:
provider: pypi
Expand Down
8 changes: 4 additions & 4 deletions napalm_ansible/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@
default: None
ignore_notimplemented:
description:
- Ignores NotImplementedError for filters which aren't supported by the driver. Returns
invalid filters in a list called: not_implemented
- "Ignores NotImplementedError for filters which aren't supported by the driver. Returns
invalid filters in a list called: not_implemented"
required: False
default: False
choices: [True, False]
filter:
description:
- A list of facts to retreive from a device and provided though C(ansible_facts)
- "A list of facts to retreive from a device and provided though C(ansible_facts)
The list of facts available are maintained at:
http://napalm.readthedocs.io/en/latest/support/
Note- not all getters are implemented on all supported device types
Note- not all getters are implemented on all supported device types"
required: False
default: ['facts']
args:
Expand Down
1 change: 0 additions & 1 deletion napalm_ansible/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
description:
- If set to True, the entire configuration on the device will be replaced during the
commit. If set to False, we will merge the new config with the existing one.
Default: False
choices: [true,false]
default: False
required: False
Expand Down
9 changes: 4 additions & 5 deletions napalm_ansible/napalm_parse_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
author: "David Barroso (@dbarrosop)"
version_added: "0.0"
short_description: "Parse native config/state from a file or device."
"YANG obje
description:
- "Parse configuration/state from a file or device and returns a dict that"
- "represents a valid YANG object."
Expand Down Expand Up @@ -94,16 +93,16 @@
default: None
file_path:
description:
- Path to a file to load native config/state from.
- "Path to a file to load native config/state from.
Note: Either file_path or data to connect to a device must be
provided.
Note: file_path takes precedence over a live device
Note: file_path takes precedence over a live device"
required: False
defaut: None
mode:
description:
- Whether to parse config/state or both.
Note: `both` is not supported in combination with `file_path`.
- "Whether to parse config/state or both.
Note: `both` is not supported in combination with `file_path`."
required: True
choices: ['config', 'state', 'both']
'''
Expand Down
24 changes: 24 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
import yaml
from glob import glob
from importlib import import_module

module_files = glob('napalm_ansible/napalm_*.py')
modules = [module.split('.')[0].replace('/', '.') for module in module_files]


@pytest.fixture(params=modules)
def ansible_module(request):
return request.param


def test_module_documentation_exists(ansible_module):
module = import_module(ansible_module)
content = dir(module)
assert 'DOCUMENTATION' in content
assert 'EXAMPLES' in content


def test_module_documentation_format(ansible_module):
module = import_module(ansible_module)
yaml.load(module.DOCUMENTATION)
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
envlist = py27

[testenv]
deps =
-rrequirements.txt
pytest
ansible
commands =
py.test

0 comments on commit 186e1f3

Please sign in to comment.