Merge pull request #171 from cidrblock/infra
Add basic configurations for pytest, flake8 and black Move the flake8 config into the flake8 file out of the tox file, this allows for the use of flake8 with an IDE Add a gitignore entry for collections, this will allow for GHA CI pytest testing of unit tests in the future Add a pyproject.toml file for the black and pytest config Ignore several pylance and flake8 issues Remove duplicate config from tox.ini Reviewed-by: GomathiselviS <None>pull/164/head^2
commit
de280c5069
|
@ -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
|
|
@ -1,6 +1,9 @@
|
||||||
/tests/output/
|
/tests/output/
|
||||||
/changelogs/.plugin-cache.yaml
|
/changelogs/.plugin-cache.yaml
|
||||||
|
|
||||||
|
# In case a collection directory is present, ignore it
|
||||||
|
/collections/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
trivial:
|
||||||
|
- Update linting and formatting configurations
|
|
@ -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',
|
||||||
|
]
|
|
@ -27,7 +27,7 @@ __metaclass__ = type
|
||||||
# One unittest needs to import builtins via __import__() so we need to have
|
# One unittest needs to import builtins via __import__() so we need to have
|
||||||
# the string that represents it
|
# the string that represents it
|
||||||
try:
|
try:
|
||||||
import __builtin__
|
import __builtin__ # pyright: ignore[reportMissingImports] # noqa F401
|
||||||
except ImportError:
|
except ImportError:
|
||||||
BUILTINS = "builtins"
|
BUILTINS = "builtins"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -23,7 +23,7 @@ __metaclass__ = type
|
||||||
"""
|
"""
|
||||||
Compat module for Python3.x's unittest.mock module
|
Compat module for Python3.x's unittest.mock module
|
||||||
"""
|
"""
|
||||||
import _io
|
import _io # pyright: ignore[reportMissingImports]
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Python 2.7
|
# Python 2.7
|
||||||
|
@ -35,12 +35,12 @@ try:
|
||||||
# Allow wildcard import because we really do want to import all of mock's
|
# Allow wildcard import because we really do want to import all of mock's
|
||||||
# symbols into this compat shim
|
# symbols into this compat shim
|
||||||
# pylint: disable=wildcard-import,unused-wildcard-import
|
# pylint: disable=wildcard-import,unused-wildcard-import
|
||||||
from unittest.mock import *
|
from unittest.mock import * # noqa F403
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Python 2
|
# Python 2
|
||||||
# pylint: disable=wildcard-import,unused-wildcard-import
|
# pylint: disable=wildcard-import,unused-wildcard-import
|
||||||
try:
|
try:
|
||||||
from mock import *
|
from mock import * # pyright: ignore[reportMissingModuleSource] # noqa F403
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("You need the mock library installed on python2.x to run tests")
|
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
|
# Retrieve lines from read_data via a generator so that separate calls to
|
||||||
# readline, read, and readlines are properly interleaved
|
# readline, read, and readlines are properly interleaved
|
||||||
sep = b"\n" if isinstance(read_data, bytes) else "\n"
|
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 data_as_list[-1] == sep:
|
||||||
# If the last line ended in a newline, the list comprehension will have an
|
# 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:
|
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
|
handle.__enter__.return_value = handle
|
||||||
|
|
||||||
_data = _iterate_read_data(read_data)
|
_data = _iterate_read_data(read_data)
|
||||||
|
|
|
@ -32,8 +32,8 @@ import sys
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
try:
|
try:
|
||||||
# Need unittest2 on python2.6
|
# Need unittest2 on python2.6
|
||||||
from unittest2 import *
|
from unittest2 import * # noqa F403
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("You need unittest2 installed on python2.6.x to run tests")
|
print("You need unittest2 installed on python2.6.x to run tests")
|
||||||
else:
|
else:
|
||||||
from unittest import *
|
from unittest import * # noqa F403
|
||||||
|
|
|
@ -19,7 +19,7 @@ from ansible_collections.ansible.utils.plugins.action.fact_diff import (
|
||||||
try:
|
try:
|
||||||
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from mock import MagicMock
|
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
|
||||||
|
|
||||||
|
|
||||||
class TestUpdate_Fact(unittest.TestCase):
|
class TestUpdate_Fact(unittest.TestCase):
|
||||||
|
|
|
@ -20,7 +20,7 @@ from ansible_collections.ansible.utils.plugins.action.update_fact import (
|
||||||
try:
|
try:
|
||||||
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from mock import MagicMock
|
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
|
||||||
|
|
||||||
|
|
||||||
VALID_DATA = {
|
VALID_DATA = {
|
||||||
|
|
|
@ -19,7 +19,7 @@ from ansible_collections.ansible.utils.plugins.action.validate import (
|
||||||
try:
|
try:
|
||||||
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
from unittest.mock import MagicMock # pylint:disable=syntax-error
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from mock import MagicMock
|
from mock import MagicMock # pyright: ignore[reportMissingModuleSource]
|
||||||
|
|
||||||
|
|
||||||
DATA = {
|
DATA = {
|
||||||
|
|
13
tox.ini
13
tox.ini
|
@ -10,22 +10,13 @@ deps = -r{toxinidir}/requirements.txt
|
||||||
[testenv:black]
|
[testenv:black]
|
||||||
install_command = pip install {opts} {packages}
|
install_command = pip install {opts} {packages}
|
||||||
commands =
|
commands =
|
||||||
black -v -l79 {toxinidir}
|
black -v {toxinidir}
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
install_command = pip install {opts} {packages}
|
install_command = pip install {opts} {packages}
|
||||||
commands =
|
commands =
|
||||||
black -v -l79 --check {toxinidir}
|
black -v --check {toxinidir}
|
||||||
flake8 {posargs}
|
flake8 {posargs}
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
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/
|
|
||||||
|
|
Loading…
Reference in New Issue