ansible/test/runner/lib/sanity/ignores.py
Matt Clay 66654475e1 Update ansible-test Python version handling.
Minimum version requirements for sanity tests have been standardized:

- All single version sanity tests now require Python 3.5 or later.
- All multiple version sanity tests continue to use all supported Python versions.
- All version neutral sanity tests continue to work on any supported Python version.

Previously some tests required 3.5 or later with most of the remaining tests requiring 2.7 or later.

When using the `--python` option to specify a Python version:

- Tests which do not support the specified Python version will be skipped with a warning.
- If the specified Python version is not available, any test attempting to use it will generate an error.

When not using the `--python` option to specify a Python version:

- Multiple version tests will attempt to run on all supported versions.
- Single version tests will use the current version if supported and available, or if no supported version is available.
- Single version tests will use the lowest available and supported version if the current version is not supported.
- Any versions which are not available or supported will be skipped with a warning.

Unit tests automatically skip unavailable Python versions unless `--python` was used to specify a version.
2019-07-29 11:54:03 -07:00

87 lines
2.8 KiB
Python

"""Sanity test for the sanity ignore file."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from lib.sanity import (
SanityFailure,
SanityIgnoreParser,
SanityVersionNeutral,
SanitySuccess,
SanityMessage,
)
from lib.test import (
calculate_confidence,
calculate_best_confidence,
)
from lib.config import (
SanityConfig,
)
class IgnoresTest(SanityVersionNeutral):
"""Sanity test for sanity test ignore entries."""
@property
def can_ignore(self): # type: () -> bool
"""True if the test supports ignore entries."""
return False
@property
def can_skip(self): # type: () -> bool
"""True if the test supports skip entries."""
return False
# noinspection PyUnusedLocal
def test(self, args, targets): # pylint: disable=locally-disabled, unused-argument
"""
:type args: SanityConfig
:type targets: SanityTargets
:rtype: TestResult
"""
sanity_ignore = SanityIgnoreParser.load(args)
messages = []
# parse errors
messages.extend(SanityMessage(
message=message,
path=sanity_ignore.relative_path,
line=line,
column=column,
confidence=calculate_confidence(sanity_ignore.path, line, args.metadata) if args.metadata.changes else None,
) for line, column, message in sanity_ignore.parse_errors)
# file not found errors
messages.extend(SanityMessage(
message="File '%s' does not exist" % path,
path=sanity_ignore.relative_path,
line=line,
column=1,
confidence=calculate_best_confidence(((sanity_ignore.path, line), (path, 0)), args.metadata) if args.metadata.changes else None,
) for line, path in sanity_ignore.file_not_found_errors)
# conflicting ignores and skips
for test_name, ignores in sanity_ignore.ignores.items():
for ignore_path, ignore_entry in ignores.items():
skip_line_no = sanity_ignore.skips.get(test_name, {}).get(ignore_path)
if not skip_line_no:
continue
for ignore_line_no in ignore_entry.values():
messages.append(SanityMessage(
message="Ignoring '%s' is unnecessary due to skip entry on line %d" % (ignore_path, skip_line_no),
path=sanity_ignore.relative_path,
line=ignore_line_no,
column=1,
confidence=calculate_confidence(sanity_ignore.path, ignore_line_no, args.metadata) if args.metadata.changes else None,
))
if messages:
return SanityFailure(self.name, messages=messages)
return SanitySuccess(self.name)