ansible-test - Sanity test code cleanup. (#78497)

pull/78504/head
Matt Clay 2 years ago committed by GitHub
parent 3f1838bf91
commit 89862fda3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ from __future__ import annotations
import datetime
import re
import typing as t
import astroid
@ -144,18 +145,6 @@ class AnsibleDeprecatedChecker(BaseChecker):
}),
)
def __init__(self, *args, **kwargs):
self.collection_version = None
self.collection_name = None
super().__init__(*args, **kwargs)
def set_option(self, optname, value, action=None, optdict=None):
super().set_option(optname, value, action, optdict)
if optname == 'collection-version' and value is not None:
self.collection_version = SemanticVersion(self.config.collection_version)
if optname == 'collection-name' and value is not None:
self.collection_name = self.config.collection_name
def _check_date(self, node, date):
if not isinstance(date, str):
self.add_message('ansible-invalid-deprecated-date', node=node, args=(date,))
@ -205,6 +194,16 @@ class AnsibleDeprecatedChecker(BaseChecker):
except ValueError:
self.add_message('collection-invalid-deprecated-version', node=node, args=(version,))
@property
def collection_name(self) -> t.Optional[str]:
"""Return the collection name, or None if ansible-core is being tested."""
return self.config.collection_name
@property
def collection_version(self) -> t.Optional[SemanticVersion]:
"""Return the collection version, or None if ansible-core is being tested."""
return SemanticVersion(self.config.collection_version) if self.config.collection_version is not None else None
@check_messages(*(MSGS.keys()))
def visit_call(self, node):
"""Visit a call node."""

@ -679,14 +679,14 @@ class ModuleValidator(Validator):
def _ensure_imports_below_docs(self, doc_info, first_callable):
try:
min_doc_line = min(
[doc_info[key]['lineno'] for key in doc_info if doc_info[key]['lineno']]
doc_info[key]['lineno'] for key in doc_info if doc_info[key]['lineno']
)
except ValueError:
# We can't perform this validation, as there are no DOCs provided at all
return
max_doc_line = max(
[doc_info[key]['end_lineno'] for key in doc_info if doc_info[key]['end_lineno']]
doc_info[key]['end_lineno'] for key in doc_info if doc_info[key]['end_lineno']
)
import_lines = []

@ -12,6 +12,11 @@ Text = type(u'')
def main():
"""Main program entry point."""
for path in sys.argv[1:] or sys.stdin.read().splitlines():
compile_source(path)
def compile_source(path):
"""Compile the specified source file, printing an error if one occurs."""
with open(path, 'rb') as source_fd:
source = source_fd.read()
@ -22,7 +27,7 @@ def main():
except BaseException as ex: # pylint: disable=broad-except
extype, message, lineno, offset = type(ex), str(ex), 0, 0
else:
continue
return
# In some situations offset can be None. This can happen for syntax errors on Python 2.6
# (__future__ import following after a regular import).

Loading…
Cancel
Save