mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
code-smell test changes
* Create get_exception and wildcard import code-smell tests * Add more detail to boilerplate and no-basestring descriptions * Remove the no-list-cmp test as the pylint undefined-variable test covers it
This commit is contained in:
parent
33e8c83fde
commit
f4d7b9a596
9 changed files with 149 additions and 56 deletions
|
@ -3,6 +3,7 @@
|
|||
metaclass1=$(find ./bin -type f -exec grep -HL '__metaclass__ = type' '{}' '+')
|
||||
future1=$(find ./bin -type f -exec grep -HL 'from __future__ import (absolute_import, division, print_function)' '{}' '+')
|
||||
|
||||
# We eventually want to remove the module_utils and modules pruning from metaclass2 and future2
|
||||
metaclass2=$(find ./lib/ansible -path ./lib/ansible/modules -prune \
|
||||
-o -path ./lib/ansible/module_utils -prune \
|
||||
-o -path ./lib/ansible/module_utils/six/_six.py -prune \
|
||||
|
@ -60,33 +61,10 @@ future3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -prune
|
|||
-o -path ./lib/ansible/modules/network/vyos -prune \
|
||||
-o -name '*.py' -type f -size +0c -exec egrep -HL 'from __future__ import (?absolute_import, division, print_function)?' '{}' '+')
|
||||
|
||||
# Ordered by approximate work, lowest to highest
|
||||
# Key:
|
||||
# [*]: import * fixes
|
||||
# [!]: many get_exception fixes
|
||||
# [i]: a few get_exception fixes
|
||||
# (everything below needs boilerplate added)
|
||||
# Priorities: import*, get_exception, then boilerplate-only
|
||||
#
|
||||
# network/ios
|
||||
# network/eos [i]
|
||||
# network/netvisor
|
||||
# network/aos [!]
|
||||
# network/vyos [i]
|
||||
# network/lenovo
|
||||
# network/panos [!]
|
||||
# network/junos [i]
|
||||
# files [!]
|
||||
# network/avi
|
||||
# network/f5 [*][i]
|
||||
# monitoring [*][!]
|
||||
# packaging/os [*][i]
|
||||
# cloud/cloudstack [*]
|
||||
# cloud/openstack [*]
|
||||
# cloud/ovirt
|
||||
# network/cloudengine [i]
|
||||
# network/nxos [*][i]
|
||||
# cloud/amazon [*]
|
||||
###
|
||||
### Important: If you're looking for a list of files to cleanup for boilerplate
|
||||
### Look at this wikipage instead: https://github.com/ansible/community/wiki/Testing:-boilerplate,-wildcard-imports,-and-get_exception
|
||||
###
|
||||
|
||||
### TODO:
|
||||
### - module_utils <=== these are important but not well organized so we'd
|
||||
|
|
36
test/sanity/code-smell/no-get-exception.sh
Executable file
36
test/sanity/code-smell/no-get-exception.sh
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
# We're getting rid of get_exception in our code so that we can deprecate it.
|
||||
# get_exception is no longer needed as we no longer support python-2.4 on the controller.
|
||||
|
||||
# We eventually want this list to be empty
|
||||
get_exception=$(find . -path ./test/runner/.tox -prune \
|
||||
-o -path ./lib/ansible/module_utils -prune \
|
||||
-o -path ./lib/ansible/modules/storage/netapp -prune \
|
||||
-o -path ./lib/ansible/modules/packaging/os -prune \
|
||||
-o -path ./lib/ansible/modules/monitoring -prune \
|
||||
-o -path ./lib/ansible/modules/network/panos -prune \
|
||||
-o -path ./lib/ansible/modules/network/nxos -prune \
|
||||
-o -path ./lib/ansible/modules/network/junos -prune \
|
||||
-o -path ./lib/ansible/modules/network/vyos -prune \
|
||||
-o -path ./lib/ansible/modules/network/fortios -prune \
|
||||
-o -path ./lib/ansible/modules/network/f5 -prune \
|
||||
-o -path ./lib/ansible/modules/network/cloudengine -prune \
|
||||
-o -path ./lib/ansible/modules/network/aos -prune \
|
||||
-o -path ./lib/ansible/modules/network/eos -prune \
|
||||
-o -path ./lib/ansible/modules/files -prune \
|
||||
-o -path ./lib/ansible/modules/system -prune \
|
||||
-o -path ./lib/ansible/modules/web_infrastructure -prune \
|
||||
-o -path ./lib/ansible/plugins/action/wait_for_connection.py -prune \
|
||||
-o -name '*.py' -type f -exec grep -H 'get_exception' '{}' '+')
|
||||
|
||||
|
||||
if test -n "$get_exception" ; then
|
||||
printf "\n== Contains get_exception() calls ==\n"
|
||||
printf "%s" "$get_exception"
|
||||
failures=$(printf "%s" "$get_exception"| wc -l)
|
||||
failures=$((failures + 2))
|
||||
exit "$failures"
|
||||
fi
|
||||
|
||||
exit 0
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
CMP_USERS=$(grep -rI ' cmp[^a-zA-Z0-9_:=]' . \
|
||||
--exclude-dir .tox \
|
||||
| grep -v \
|
||||
-e lib/ansible/module_utils/six/_six.py \
|
||||
-e .git \
|
||||
-e docs/docsite/_build/ \
|
||||
-e docs/docsite/rst/dev_guide/testing/sanity/ \
|
||||
-e test/sanity/code-smell/no-list-cmp.sh
|
||||
)
|
||||
|
||||
if [ "${CMP_USERS}" ]; then
|
||||
echo 'cmp has been removed in python3. Alternatives:'
|
||||
echo ' http://python3porting.com/preparing.html#when-sorting-use-key-instead-of-cmp'
|
||||
echo "${CMP_USERS}"
|
||||
exit 1
|
||||
fi
|
42
test/sanity/code-smell/no-wildcard-import.sh
Executable file
42
test/sanity/code-smell/no-wildcard-import.sh
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Only needed until we enable pylint test for wildcard imports
|
||||
|
||||
|
||||
# The first three paths here are valid uses of wildcard imports
|
||||
# unsafe_proxy is backwards compat (pylint disabled added)
|
||||
# module_common.py is picked up from static strings, not from actual imports (pylint won't detect)
|
||||
# test_action.py is picked up from static strings, not from actual imports (pylint won't detect)
|
||||
# mock.py is importing code for an installed library for compat (pylint disabled added)
|
||||
# unittest.py is importing code for an installed library for compat (pylint disabled added)
|
||||
#
|
||||
# Everything else needs to be fixed
|
||||
wildcard_imports=$(find . -path ./test/runner/.tox -prune \
|
||||
-o -path ./lib/ansible/vars/unsafe_proxy.py -prune \
|
||||
-o -path ./lib/ansible/executor/module_common.py -prune \
|
||||
-o -path ./test/units/plugins/action/test_action.py \
|
||||
-o -path ./lib/ansible/compat/tests/mock.py -prune \
|
||||
-o -path ./lib/ansible/compat/tests/unittest.py \
|
||||
-o -path ./lib/ansible/module_utils/api.py -prune \
|
||||
-o -path ./lib/ansible/module_utils/cloud.py -prune \
|
||||
-o -path ./lib/ansible/module_utils/aos.py -prune \
|
||||
-o -path ./test/units/modules/network/cumulus/test_nclu.py -prune \
|
||||
-o -path ./lib/ansible/modules/cloud/amazon -prune \
|
||||
-o -path ./lib/ansible/modules/cloud/openstack -prune \
|
||||
-o -path ./lib/ansible/modules/cloud/cloudstack -prune \
|
||||
-o -path ./lib/ansible/modules/monitoring -prune \
|
||||
-o -path ./lib/ansible/modules/network/f5 -prune \
|
||||
-o -path ./lib/ansible/modules/network/nxos -prune \
|
||||
-o -path ./lib/ansible/modules/packaging/os -prune \
|
||||
-o -name '*.py' -type f -exec grep -H 'import \*' '{}' '+')
|
||||
|
||||
|
||||
if test -n "$wildcard_imports" ; then
|
||||
printf "\n== Wildcard imports detected ==\n"
|
||||
printf "%s" "$wildcard_imports"
|
||||
failures=$(printf "%s" "$wildcard_imports"| wc -l)
|
||||
failures=$((failures + 2))
|
||||
exit "$failures"
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Add table
Add a link
Reference in a new issue