Linting and test config

pull/171/head
cidrblock 2022-04-13 06:01:59 -07:00
parent 284642f010
commit c533f5c758
10 changed files with 62 additions and 22 deletions

33
.flake8 Normal file
View File

@ -0,0 +1,33 @@
[flake8]
builtins = _
# Print the total number of errors:
count = true
# Don't even try to analyze these:
extend-exclude =
# project env vars
.env,
# GitHub configs
.github,
# Cache files of pytest
.pytest_cache,
# Occasional virtualenv dirs
.venv
venv
# VS Code
.vscode,
# IMPORTANT: avoid using ignore option, always use extend-ignore instead
# Completely and unconditionally ignore the following errors:
extend-ignore =
E203, # annoy black by allowing white space before : https://github.com/psf/black/issues/315
E402, # ansible requires import after doc strings
E501, # given the ansible_collections this is nearly impossible
# Accessibility/large fonts and PEP8 unfriendly:
max-line-length = 100
# Count the number of occurrences of each error/warning code and print a report:
statistics = true

3
.gitignore vendored
View File

@ -1,6 +1,9 @@
/tests/output/
/changelogs/.plugin-cache.yaml
# In case a collection directory is present, ignore it
/collections/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

12
pyproject.toml Normal file
View File

@ -0,0 +1,12 @@
[tool.black]
line-length = 79
[tool.pytest.ini_options]
addopts = "-n auto"
testpaths = [
"tests",
]
filterwarnings = [
'ignore:AnsibleCollectionFinder has already been configured',
]

View File

@ -27,7 +27,7 @@ __metaclass__ = type
# One unittest needs to import builtins via __import__() so we need to have
# the string that represents it
try:
import __builtin__
import __builtin__ # pyright: ignore[reportMissingImports] # noqa F401
except ImportError:
BUILTINS = "builtins"
else:

View File

@ -23,7 +23,7 @@ __metaclass__ = type
"""
Compat module for Python3.x's unittest.mock module
"""
import _io
import _io # pyright: ignore[reportMissingImports]
import sys
# Python 2.7
@ -35,12 +35,12 @@ try:
# Allow wildcard import because we really do want to import all of mock's
# symbols into this compat shim
# pylint: disable=wildcard-import,unused-wildcard-import
from unittest.mock import *
from unittest.mock import * # noqa F403
except ImportError:
# Python 2
# pylint: disable=wildcard-import,unused-wildcard-import
try:
from mock import *
from mock import * # pyright: ignore[reportMissingModuleSource] # noqa F403
except ImportError:
print("You need the mock library installed on python2.x to run tests")
@ -54,7 +54,7 @@ if sys.version_info >= (3,) and sys.version_info < (3, 4, 4):
# Retrieve lines from read_data via a generator so that separate calls to
# readline, read, and readlines are properly interleaved
sep = b"\n" if isinstance(read_data, bytes) else "\n"
data_as_list = [l + sep for l in read_data.split(sep)]
data_as_list = [line + sep for line in read_data.split(sep)]
if data_as_list[-1] == sep:
# If the last line ended in a newline, the list comprehension will have an
@ -107,9 +107,9 @@ if sys.version_info >= (3,) and sys.version_info < (3, 4, 4):
)
if mock is None:
mock = MagicMock(name="open", spec=open)
mock = MagicMock(name="open", spec=open) # noqa F405
handle = MagicMock(spec=file_spec)
handle = MagicMock(spec=file_spec) # noqa F405
handle.__enter__.return_value = handle
_data = _iterate_read_data(read_data)

View File

@ -32,8 +32,8 @@ import sys
if sys.version_info < (2, 7):
try:
# Need unittest2 on python2.6
from unittest2 import *
from unittest2 import * # noqa F403
except ImportError:
print("You need unittest2 installed on python2.6.x to run tests")
else:
from unittest import *
from unittest import * # noqa F403

View File

@ -19,7 +19,7 @@ from ansible_collections.ansible.utils.plugins.action.fact_diff import (
try:
from unittest.mock import MagicMock # pylint:disable=syntax-error
except ImportError:
from mock import MagicMock
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
class TestUpdate_Fact(unittest.TestCase):

View File

@ -20,7 +20,7 @@ from ansible_collections.ansible.utils.plugins.action.update_fact import (
try:
from unittest.mock import MagicMock # pylint:disable=syntax-error
except ImportError:
from mock import MagicMock
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
VALID_DATA = {

View File

@ -19,7 +19,7 @@ from ansible_collections.ansible.utils.plugins.action.validate import (
try:
from unittest.mock import MagicMock # pylint:disable=syntax-error
except ImportError:
from mock import MagicMock
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
DATA = {

12
tox.ini
View File

@ -10,22 +10,14 @@ deps = -r{toxinidir}/requirements.txt
[testenv:black]
install_command = pip install {opts} {packages}
commands =
black -v -l79 {toxinidir}
black -v {toxinidir}
[testenv:linters]
install_command = pip install {opts} {packages}
commands =
black -v -l79 --check {toxinidir}
black -v --check {toxinidir}
flake8 {posargs}
[testenv:venv]
commands = {posargs}
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125,E402,W503
max-line-length = 160
builtins = _
exclude = .git,.tox,tests/unit/compat/