ansible-doc stay 3.8 python compatible (#77682)

pathlib with_stem will wait till 3.9
  also add tests by listing filters
pull/73239/merge
Brian Coca 2 years ago committed by GitHub
parent c71faec595
commit 749a105956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1004,7 +1004,7 @@ class DocCLI(CLI, RoleMixin):
if doc is None:
# handle test/filters that are in file with diff name
base = plugin.split('.')[-1]
basefile = filename.with_stem(base)
basefile = filename.with_name(base + filename.suffix)
for extension in ('.py', '.yml', '.yaml'): # TODO: constant?
docfile = basefile.with_suffix(extension)
try:

@ -0,0 +1,27 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.utils.display import Display
display = Display()
def nochange(a):
return a
def meaningoflife(a):
return 42
class FilterModule(object):
''' Ansible core jinja2 filters '''
def filters(self):
return {
'noop': nochange,
'ultimatequestion': meaningoflife
}

@ -0,0 +1,21 @@
DOCUMENTATION:
name: ultimatequestion
author: Terry Prachet
version_added: 'histerical'
short_description: Ask any question but it will only respond with the answer to the ulitmate one
description:
- read the book
options:
_input:
description: Anything you want, goign to ignore it anywayss ...
type: raw
required: true
EXAMPLES: |
# set first 10 volumes rw, rest as dp
meaning: "{{ (stuff|ulmtimatequestion }}"
RETURN:
_value:
description: guess
type: int

@ -32,16 +32,20 @@ ansible-doc --list testns.testcol.fakemodule --playbook-dir ./ 2>&1 | grep "Inv
# test listing diff plugin types from collection
for ptype in cache inventory lookup vars
for ptype in cache inventory lookup vars filter
do
# each plugin type adds 1 from collection
# FIXME pre=$(ansible-doc -l -t ${ptype}|wc -l)
# FIXME post=$(ansible-doc -l -t ${ptype} --playbook-dir ./|wc -l)
# FIXME test "$pre" -eq $((post - 1))
if [ "${ptype}" == "filter" ]; then
expected=2
else
expected=1
fi
# ensure we ONLY list from the collection
justcol=$(ansible-doc -l -t ${ptype} --playbook-dir ./ testns.testcol|wc -l)
test "$justcol" -eq 1
test "$justcol" -eq "$expected"
# ensure we get error if passinginvalid collection, much less any plugins
ansible-doc -l -t ${ptype} testns.testcol 2>&1 | grep "unable to locate collection"

Loading…
Cancel
Save