diff options
author | Matt Clay <mclay@redhat.com> | 2021-09-20 18:39:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-20 18:39:07 -0700 |
commit | 4ea8d9a7824827cf3d4a206599ffd7fe3a09eafd (patch) | |
tree | 57b4ea491f6f93b6b938037e28dca90098754ca2 /test/lib/ansible_test/_internal/commands/sanity/yamllint.py | |
parent | 989eeb243fcf9236bd54d4df60c01f6db4e642a7 (diff) | |
download | ansible-4ea8d9a7824827cf3d4a206599ffd7fe3a09eafd.tar.gz |
ansible-test - split controller/target testing (#75605)
Diffstat (limited to 'test/lib/ansible_test/_internal/commands/sanity/yamllint.py')
-rw-r--r-- | test/lib/ansible_test/_internal/commands/sanity/yamllint.py | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/test/lib/ansible_test/_internal/commands/sanity/yamllint.py b/test/lib/ansible_test/_internal/commands/sanity/yamllint.py index 42a69acedf..4ca6dfe8c1 100644 --- a/test/lib/ansible_test/_internal/commands/sanity/yamllint.py +++ b/test/lib/ansible_test/_internal/commands/sanity/yamllint.py @@ -1,25 +1,23 @@ """Sanity test using yamllint.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json import os - -from ... import types as t - -from ...ansible_util import ( - check_pyyaml, -) +import typing as t from . import ( SanitySingleVersion, SanityMessage, SanityFailure, - SanitySkipped, SanitySuccess, + SanityTargets, SANITY_ROOT, ) +from ...test import ( + TestResult, +) + from ...target import ( TestTarget, ) @@ -28,7 +26,6 @@ from ...util import ( SubprocessError, display, is_subdir, - find_python, ) from ...util_common import ( @@ -43,6 +40,10 @@ from ...data import ( data_context, ) +from ...host_configs import ( + PythonConfig, +) + class YamllintTest(SanitySingleVersion): """Sanity test using yamllint.""" @@ -51,6 +52,11 @@ class YamllintTest(SanitySingleVersion): """Error code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes.""" return 'ansible-test' + @property + def require_libyaml(self): # type: () -> bool + """True if the test requires PyYAML to have libyaml support.""" + return True + def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget] """Return the given list of test targets, filtered to include only those relevant for the test.""" yaml_targets = [target for target in targets if os.path.splitext(target.path)[1] in ('.yml', '.yaml')] @@ -66,25 +72,11 @@ class YamllintTest(SanitySingleVersion): return yaml_targets - def test(self, args, targets, python_version): - """ - :type args: SanityConfig - :type targets: SanityTargets - :type python_version: str - :rtype: TestResult - """ - pyyaml_presence = check_pyyaml(args, python_version, quiet=True) - if not pyyaml_presence['cloader']: - display.warning("Skipping sanity test '%s' due to missing libyaml support in PyYAML." - % self.name) - return SanitySkipped(self.name) - + def test(self, args, targets, python): # type: (SanityConfig, SanityTargets, PythonConfig) -> TestResult settings = self.load_processor(args) paths = [target.path for target in targets.include] - python = find_python(python_version) - results = self.test_paths(args, paths, python) results = settings.process_errors(results, paths) @@ -94,15 +86,10 @@ class YamllintTest(SanitySingleVersion): return SanitySuccess(self.name) @staticmethod - def test_paths(args, paths, python): - """ - :type args: SanityConfig - :type paths: list[str] - :type python: str - :rtype: list[SanityMessage] - """ + def test_paths(args, paths, python): # type: (SanityConfig, t.List[str], PythonConfig) -> t.List[SanityMessage] + """Test the specified paths using the given Python and return the results.""" cmd = [ - python, + python.path, os.path.join(SANITY_ROOT, 'yamllint', 'yamllinter.py'), ] |