summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_internal/commands/sanity
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_internal/commands/sanity')
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/__init__.py22
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/bin_symlinks.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/compile.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/ignores.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/import.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/integration_aliases.py2
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/mypy.py4
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/pep8.py3
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/pslint.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/pylint.py4
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/sanity_docs.py1
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/shellcheck.py3
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/validate_modules.py2
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/yamllint.py1
15 files changed, 38 insertions, 10 deletions
diff --git a/test/lib/ansible_test/_internal/commands/sanity/__init__.py b/test/lib/ansible_test/_internal/commands/sanity/__init__.py
index 00b30310d5..4089dce51d 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/__init__.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/__init__.py
@@ -325,6 +325,7 @@ def collect_code_smell_tests() -> tuple[SanityTest, ...]:
class SanityIgnoreParser:
"""Parser for the consolidated sanity test ignore file."""
+
NO_CODE = '_'
def __init__(self, args: SanityConfig) -> None:
@@ -526,11 +527,13 @@ class SanityIgnoreParser:
class SanityIgnoreProcessor:
"""Processor for sanity test ignores for a single run of one sanity test."""
- def __init__(self,
- args: SanityConfig,
- test: SanityTest,
- python_version: t.Optional[str],
- ) -> None:
+
+ def __init__(
+ self,
+ args: SanityConfig,
+ test: SanityTest,
+ python_version: t.Optional[str],
+ ) -> None:
name = test.name
code = test.error_code
@@ -618,18 +621,21 @@ class SanityIgnoreProcessor:
class SanitySuccess(TestSuccess):
"""Sanity test success."""
+
def __init__(self, test: str, python_version: t.Optional[str] = None) -> None:
super().__init__(COMMAND, test, python_version)
class SanitySkipped(TestSkipped):
"""Sanity test skipped."""
+
def __init__(self, test: str, python_version: t.Optional[str] = None) -> None:
super().__init__(COMMAND, test, python_version)
class SanityFailure(TestFailure):
"""Sanity test failure."""
+
def __init__(
self,
test: str,
@@ -646,6 +652,7 @@ class SanityMessage(TestMessage):
class SanityTargets:
"""Sanity test target information."""
+
def __init__(self, targets: tuple[TestTarget, ...], include: tuple[TestTarget, ...]) -> None:
self.targets = targets
self.include = include
@@ -695,6 +702,7 @@ class SanityTargets:
class SanityTest(metaclass=abc.ABCMeta):
"""Sanity test base class."""
+
ansible_only = False
def __init__(self, name: t.Optional[str] = None) -> None:
@@ -811,6 +819,7 @@ class SanityTest(metaclass=abc.ABCMeta):
class SanitySingleVersion(SanityTest, metaclass=abc.ABCMeta):
"""Base class for sanity test plugins which should run on a single python version."""
+
@property
def require_libyaml(self) -> bool:
"""True if the test requires PyYAML to have libyaml support."""
@@ -827,6 +836,7 @@ class SanitySingleVersion(SanityTest, metaclass=abc.ABCMeta):
class SanityCodeSmellTest(SanitySingleVersion):
"""Sanity test script."""
+
def __init__(self, path) -> None:
name = os.path.splitext(os.path.basename(path))[0]
config_path = os.path.splitext(path)[0] + '.json'
@@ -1030,6 +1040,7 @@ class SanityCodeSmellTest(SanitySingleVersion):
class SanityVersionNeutral(SanityTest, metaclass=abc.ABCMeta):
"""Base class for sanity test plugins which are idependent of the python version being used."""
+
@abc.abstractmethod
def test(self, args: SanityConfig, targets: SanityTargets) -> TestResult:
"""Run the sanity test and return the result."""
@@ -1046,6 +1057,7 @@ class SanityVersionNeutral(SanityTest, metaclass=abc.ABCMeta):
class SanityMultipleVersion(SanityTest, metaclass=abc.ABCMeta):
"""Base class for sanity test plugins which should run on multiple python versions."""
+
@abc.abstractmethod
def test(self, args: SanityConfig, targets: SanityTargets, python: PythonConfig) -> TestResult:
"""Run the sanity test and return the result."""
diff --git a/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py b/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py
index 6815f8847d..04080f60c0 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py
@@ -48,6 +48,7 @@ from ...host_configs import (
class AnsibleDocTest(SanitySingleVersion):
"""Sanity test for ansible-doc."""
+
def filter_targets(self, targets: list[TestTarget]) -> list[TestTarget]:
"""Return the given list of test targets, filtered to include only those relevant for the test."""
plugin_paths = [plugin_path for plugin_type, plugin_path in data_context().content.plugin_paths.items() if plugin_type in DOCUMENTABLE_PLUGINS]
diff --git a/test/lib/ansible_test/_internal/commands/sanity/bin_symlinks.py b/test/lib/ansible_test/_internal/commands/sanity/bin_symlinks.py
index 7539f4ab2e..8f4fe8a4c5 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/bin_symlinks.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/bin_symlinks.py
@@ -38,6 +38,7 @@ from ...util import (
class BinSymlinksTest(SanityVersionNeutral):
"""Sanity test for symlinks in the bin directory."""
+
ansible_only = True
@property
diff --git a/test/lib/ansible_test/_internal/commands/sanity/compile.py b/test/lib/ansible_test/_internal/commands/sanity/compile.py
index 4505338379..a0f599f111 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/compile.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/compile.py
@@ -43,6 +43,7 @@ from ...host_configs import (
class CompileTest(SanityMultipleVersion):
"""Sanity test for proper python syntax."""
+
def filter_targets(self, targets: list[TestTarget]) -> list[TestTarget]:
"""Return the given list of test targets, filtered to include only those relevant for the test."""
return [target for target in targets if os.path.splitext(target.path)[1] == '.py' or is_subdir(target.path, 'bin')]
diff --git a/test/lib/ansible_test/_internal/commands/sanity/ignores.py b/test/lib/ansible_test/_internal/commands/sanity/ignores.py
index 6d9837d07b..251f8326e7 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/ignores.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/ignores.py
@@ -25,6 +25,7 @@ from ...config import (
class IgnoresTest(SanityVersionNeutral):
"""Sanity test for sanity test ignore entries."""
+
@property
def can_ignore(self) -> bool:
"""True if the test supports ignore entries."""
diff --git a/test/lib/ansible_test/_internal/commands/sanity/import.py b/test/lib/ansible_test/_internal/commands/sanity/import.py
index 8511d7ac89..b808332478 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/import.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/import.py
@@ -84,6 +84,7 @@ def _get_module_test(module_restrictions: bool) -> c.Callable[[str], bool]:
class ImportTest(SanityMultipleVersion):
"""Sanity test for proper import exception handling."""
+
def filter_targets(self, targets: list[TestTarget]) -> list[TestTarget]:
"""Return the given list of test targets, filtered to include only those relevant for the test."""
if data_context().content.is_ansible:
diff --git a/test/lib/ansible_test/_internal/commands/sanity/integration_aliases.py b/test/lib/ansible_test/_internal/commands/sanity/integration_aliases.py
index 010d8311ed..32b70c2465 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/integration_aliases.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/integration_aliases.py
@@ -61,6 +61,7 @@ from ...host_configs import (
class IntegrationAliasesTest(SanitySingleVersion):
"""Sanity test to evaluate integration test aliases."""
+
CI_YML = '.azure-pipelines/azure-pipelines.yml'
TEST_ALIAS_PREFIX = 'shippable' # this will be changed at some point in the future
@@ -424,5 +425,6 @@ class IntegrationAliasesTest(SanitySingleVersion):
@dataclasses.dataclass
class Results:
"""Check results."""
+
comments: list[str]
labels: dict[str, bool]
diff --git a/test/lib/ansible_test/_internal/commands/sanity/mypy.py b/test/lib/ansible_test/_internal/commands/sanity/mypy.py
index cb8ed12c1a..57ce1277cf 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/mypy.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/mypy.py
@@ -58,6 +58,7 @@ from ...host_configs import (
class MypyTest(SanityMultipleVersion):
"""Sanity test which executes mypy."""
+
ansible_only = True
vendored_paths = (
@@ -221,7 +222,7 @@ class MypyTest(SanityMultipleVersion):
# Below are context specific arguments.
# They are primarily useful for listing individual 'ignore_missing_imports' entries instead of using a global ignore.
'--config-file', config_path,
- ]
+ ] # fmt: skip
cmd.extend(context_paths)
@@ -254,6 +255,7 @@ class MypyTest(SanityMultipleVersion):
@dataclasses.dataclass(frozen=True)
class MyPyContext:
"""Context details for a single run of mypy."""
+
name: str
paths: list[str]
python_versions: tuple[str, ...]
diff --git a/test/lib/ansible_test/_internal/commands/sanity/pep8.py b/test/lib/ansible_test/_internal/commands/sanity/pep8.py
index 5df9ace728..610dbd649a 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/pep8.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/pep8.py
@@ -43,6 +43,7 @@ from ...host_configs import (
class Pep8Test(SanitySingleVersion):
"""Sanity test for PEP 8 style guidelines using pycodestyle."""
+
@property
def error_code(self) -> t.Optional[str]:
"""Error code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes."""
@@ -66,7 +67,7 @@ class Pep8Test(SanitySingleVersion):
'--max-line-length', '160',
'--config', '/dev/null',
'--ignore', ','.join(sorted(current_ignore)),
- ] + paths
+ ] + paths # fmt: skip
if paths:
try:
diff --git a/test/lib/ansible_test/_internal/commands/sanity/pslint.py b/test/lib/ansible_test/_internal/commands/sanity/pslint.py
index 9136d51ce5..1694488d4d 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/pslint.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/pslint.py
@@ -45,6 +45,7 @@ from ...data import (
class PslintTest(SanityVersionNeutral):
"""Sanity test using PSScriptAnalyzer."""
+
@property
def error_code(self) -> t.Optional[str]:
"""Error code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes."""
diff --git a/test/lib/ansible_test/_internal/commands/sanity/pylint.py b/test/lib/ansible_test/_internal/commands/sanity/pylint.py
index e6a20b579b..fe5fbac952 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/pylint.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/pylint.py
@@ -63,6 +63,7 @@ from ...host_configs import (
class PylintTest(SanitySingleVersion):
"""Sanity test using pylint."""
+
def __init__(self) -> None:
super().__init__()
self.optional_error_codes.update([
@@ -111,6 +112,7 @@ class PylintTest(SanitySingleVersion):
def filter_path(path_filter: str = None) -> c.Callable[[str], bool]:
"""Return a function that filters out paths which are not a subdirectory of the given path."""
+
def context_filter(path_to_filter: str) -> bool:
"""Return true if the given path matches, otherwise return False."""
return is_subdir(path_to_filter, path_filter)
@@ -232,7 +234,7 @@ class PylintTest(SanitySingleVersion):
'--rcfile', rcfile,
'--output-format', 'json',
'--load-plugins', ','.join(sorted(load_plugins)),
- ] + paths
+ ] + paths # fmt: skip
if data_context().content.collection:
cmd.extend(['--collection-name', data_context().content.collection.full_name])
diff --git a/test/lib/ansible_test/_internal/commands/sanity/sanity_docs.py b/test/lib/ansible_test/_internal/commands/sanity/sanity_docs.py
index 4f14a3a2f2..48f1b0b100 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/sanity_docs.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/sanity_docs.py
@@ -27,6 +27,7 @@ from ...data import (
class SanityDocsTest(SanityVersionNeutral):
"""Sanity test for documentation of sanity tests."""
+
ansible_only = True
@property
diff --git a/test/lib/ansible_test/_internal/commands/sanity/shellcheck.py b/test/lib/ansible_test/_internal/commands/sanity/shellcheck.py
index 7de0bdae87..4576622c12 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/shellcheck.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/shellcheck.py
@@ -44,6 +44,7 @@ from ...config import (
class ShellcheckTest(SanityVersionNeutral):
"""Sanity test using shellcheck."""
+
@property
def error_code(self) -> t.Optional[str]:
"""Error code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes."""
@@ -68,7 +69,7 @@ class ShellcheckTest(SanityVersionNeutral):
'shellcheck',
'-e', ','.join(sorted(exclude)),
'--format', 'checkstyle',
- ] + paths
+ ] + paths # fmt: skip
try:
stdout, stderr = run_command(args, cmd, capture=True)
diff --git a/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py b/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
index e1dacb7c9f..182c30574b 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
@@ -115,7 +115,7 @@ class ValidateModulesTest(SanitySingleVersion):
os.path.join(SANITY_ROOT, 'validate-modules', 'validate.py'),
'--format', 'json',
'--arg-spec',
- ]
+ ] # fmt: skip
if data_context().content.collection:
cmd.extend(['--collection', data_context().content.collection.directory])
diff --git a/test/lib/ansible_test/_internal/commands/sanity/yamllint.py b/test/lib/ansible_test/_internal/commands/sanity/yamllint.py
index a0d859f0a6..0af8d65ef3 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/yamllint.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/yamllint.py
@@ -47,6 +47,7 @@ from ...host_configs import (
class YamllintTest(SanitySingleVersion):
"""Sanity test using yamllint."""
+
@property
def error_code(self) -> t.Optional[str]:
"""Error code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes."""