diff --git a/test/sanity/code-smell/deprecated-config.py b/test/sanity/code-smell/deprecated-config.py index 7056ca2746f..828f12e3136 100644 --- a/test/sanity/code-smell/deprecated-config.py +++ b/test/sanity/code-smell/deprecated-config.py @@ -83,9 +83,7 @@ def main(): data = {} data['doc'], data['examples'], data['return'], data['metadata'] = get_docstring(plugin, fragment_loader) for result in find_deprecations(data['doc']): - print( - '%s: %s is scheduled for removal in %s' % (plugin, '.'.join(str(i) for i in result[0][:-2]), result[1]) - ) + print('%s: %s is scheduled for removal in %s' % (plugin, '.'.join(str(i) for i in result[0][:-2]), result[1])) base = os.path.join(os.path.dirname(ansible.config.__file__), 'base.yml') root_path = os.path.dirname(os.path.dirname(os.path.dirname(ansible.__file__))) diff --git a/test/sanity/code-smell/mypy.py b/test/sanity/code-smell/mypy.py index 4c22e7c33e1..63579a5fdd9 100644 --- a/test/sanity/code-smell/mypy.py +++ b/test/sanity/code-smell/mypy.py @@ -33,13 +33,10 @@ def main() -> None: contexts = ( MyPyContext('ansible-test', ['test/lib/ansible_test/'], controller_python_versions), MyPyContext('ansible-test', ['test/lib/ansible_test/_util/target/'], remote_only_python_versions), - MyPyContext('ansible-core', ['lib/ansible/'], controller_python_versions), MyPyContext('ansible-core', ['lib/ansible/modules/', 'lib/ansible/module_utils/'], remote_only_python_versions), - MyPyContext('ansible-core', ['test/units/'], controller_python_versions), MyPyContext('ansible-core', ['test/units/modules/', 'test/units/module_utils/'], remote_only_python_versions), - MyPyContext('packaging', ['packaging/'], controller_python_versions), ) @@ -61,14 +58,16 @@ def main() -> None: match = re.search(r'^(?P.*) {2}\[(?P.*)]$', message.message) - messages.append(SanityMessage( - message=match.group('message'), - path=message.path, - line=message.line, - column=message.column, - level=message.level, - code=match.group('code'), - )) + messages.append( + SanityMessage( + message=match.group('message'), + path=message.path, + line=message.line, + column=message.column, + level=message.level, + code=match.group('code'), + ) + ) # FUTURE: provide a way for script based tests to report non-error messages (in this case, notices) @@ -172,14 +171,17 @@ def test_context( parsed = parse_to_list_of_dict(pattern, stdout or '') - messages = [SanityMessage( - level=r['level'], - message=r['message'], - path=r['path'], - line=int(r['line']), - column=int(r.get('column') or '0'), - code='', # extracted from error level messages later - ) for r in parsed] + messages = [ + SanityMessage( + level=r['level'], + message=r['message'], + path=r['path'], + line=int(r['line']), + column=int(r.get('column') or '0'), + code='', # extracted from error level messages later + ) + for r in parsed + ] return messages diff --git a/test/sanity/code-smell/no-unwanted-characters.py b/test/sanity/code-smell/no-unwanted-characters.py index cbace21653e..e4152d0609d 100644 --- a/test/sanity/code-smell/no-unwanted-characters.py +++ b/test/sanity/code-smell/no-unwanted-characters.py @@ -20,8 +20,7 @@ def main(): match = re.search('(\u00a0)', text) if match: - print('%s:%d:%d: use an ASCII space instead of a Unicode no-break space' % ( - path, line + 1, match.start(1) + 1)) + print('%s:%d:%d: use an ASCII space instead of a Unicode no-break space' % (path, line + 1, match.start(1) + 1)) if __name__ == '__main__': diff --git a/test/sanity/code-smell/no-unwanted-files.py b/test/sanity/code-smell/no-unwanted-files.py index db2fa2ac073..8ff8f139786 100644 --- a/test/sanity/code-smell/no-unwanted-files.py +++ b/test/sanity/code-smell/no-unwanted-files.py @@ -43,7 +43,7 @@ def main(): continue ext = os.path.splitext(path)[1] - if ext in ('.yml', ) and any(path.startswith(yaml_directory) for yaml_directory in allow_yaml): + if ext in ('.yml',) and any(path.startswith(yaml_directory) for yaml_directory in allow_yaml): continue if ext not in allowed_extensions: diff --git a/test/sanity/code-smell/package-data.py b/test/sanity/code-smell/package-data.py index 9a77941c2aa..86537fc1e8b 100644 --- a/test/sanity/code-smell/package-data.py +++ b/test/sanity/code-smell/package-data.py @@ -167,10 +167,7 @@ def check_files(source: str, expected: list[str], actual: list[str]) -> list[str filter_fuzzy_matches(missing, extra) - errors = ( - [f'{path}: missing from {source}' for path in sorted(missing)] + - [f'{path}: unexpected in {source}' for path in sorted(extra)] - ) + errors = [f'{path}: missing from {source}' for path in sorted(missing)] + [f'{path}: unexpected in {source}' for path in sorted(extra)] return errors diff --git a/test/sanity/code-smell/pymarkdown.py b/test/sanity/code-smell/pymarkdown.py index 044fb546a4e..853d94d54f3 100644 --- a/test/sanity/code-smell/pymarkdown.py +++ b/test/sanity/code-smell/pymarkdown.py @@ -15,8 +15,10 @@ def main() -> None: cmd = [ sys.executable, - '-m', 'pymarkdown', - '--config', pathlib.Path(__file__).parent / 'pymarkdown.config.json', + '-m', + 'pymarkdown', + '--config', + pathlib.Path(__file__).parent / 'pymarkdown.config.json', '--strict-config', 'scan', ] + paths diff --git a/test/sanity/code-smell/test-constraints.py b/test/sanity/code-smell/test-constraints.py index 4e01655394d..452e5e27b64 100644 --- a/test/sanity/code-smell/test-constraints.py +++ b/test/sanity/code-smell/test-constraints.py @@ -72,10 +72,10 @@ def check_ansible_test(path: str, requirements: list[tuple[int, str, re.Match]]) from ansible_test._internal.coverage_util import COVERAGE_VERSIONS from ansible_test._internal.util import version_to_str - expected_lines = set(( + expected_lines = { f"coverage == {item.coverage_version} ; python_version >= '{version_to_str(item.min_python)}' and python_version <= '{version_to_str(item.max_python)}'" for item in COVERAGE_VERSIONS - )) + } for idx, requirement in enumerate(requirements): lineno, line, match = requirement @@ -92,8 +92,10 @@ def check_ansible_test(path: str, requirements: list[tuple[int, str, re.Match]]) def parse_requirements(lines): # see https://www.python.org/dev/peps/pep-0508/#names - pattern = re.compile(r'^(?P[A-Z0-9][A-Z0-9._-]*[A-Z0-9]|[A-Z0-9])(?P *\[[^]]*])?(?P[^;#]*)(?P[^#]*)(?P.*)$', - re.IGNORECASE) + pattern = re.compile( + pattern=r'^(?P[A-Z0-9][A-Z0-9._-]*[A-Z0-9]|[A-Z0-9])(?P *\[[^]]*])?(?P[^;#]*)(?P[^#]*)(?P.*)$', + flags=re.IGNORECASE, + ) matches = [(lineno, line, pattern.search(line)) for lineno, line in enumerate(lines, start=1)] requirements = [] diff --git a/test/sanity/code-smell/update-bundled.py b/test/sanity/code-smell/update-bundled.py index 1c0e3f5e9cf..9072d0c440f 100644 --- a/test/sanity/code-smell/update-bundled.py +++ b/test/sanity/code-smell/update-bundled.py @@ -88,18 +88,17 @@ def get_bundled_metadata(filename): return None if line.strip().startswith('# CANT_UPDATE'): - print( - '{0} marked as CANT_UPDATE, so skipping. Manual ' - 'check for CVEs required.'.format(filename)) + print(f'{filename} marked as CANT_UPDATE, so skipping. Manual check for CVEs required.') return None if line.strip().startswith('_BUNDLED_METADATA'): - data = line[line.index('{'):].strip() + data = line[line.index('{') :].strip() break else: - raise ValueError('Unable to check bundled library for update. Please add' - ' _BUNDLED_METADATA dictionary to the library file with' - ' information on pypi name and bundled version.') + raise ValueError( + 'Unable to check bundled library for update. ' + 'Please add _BUNDLED_METADATA dictionary to the library file with information on pypi name and bundled version.' + ) metadata = json.loads(data) return metadata @@ -138,20 +137,20 @@ def main(): if filename.startswith('test/support/'): continue # bundled support code does not need to be updated or tracked - print('{0}: ERROR: File contains _BUNDLED_METADATA but needs to be added to' - ' test/sanity/code-smell/update-bundled.py'.format(filename)) + print(f'{filename}: ERROR: File contains _BUNDLED_METADATA but needs to be added to test/sanity/code-smell/update-bundled.py') for filename in bundled_libs: try: metadata = get_bundled_metadata(filename) except ValueError as e: - print('{0}: ERROR: {1}'.format(filename, e)) + print(f'{filename}: ERROR: {e}') continue except (IOError, OSError) as e: if e.errno == 2: - print('{0}: ERROR: {1}. Perhaps the bundled library has been removed' - ' or moved and the bundled library test needs to be modified as' - ' well?'.format(filename, e)) + print( + f'{filename}: ERROR: {e}. ' + 'Perhaps the bundled library has been removed or moved and the bundled library test needs to be modified as well?' + ) if metadata is None: continue @@ -163,12 +162,11 @@ def main(): latest_version = get_latest_applicable_version(pypi_data, constraints) if LooseVersion(metadata['version']) < LooseVersion(latest_version): - print('{0}: UPDATE {1} from {2} to {3} {4}'.format( - filename, - metadata['pypi_name'], - metadata['version'], - latest_version, - 'https://pypi.org/pypi/{0}/json'.format(metadata['pypi_name']))) + name = metadata['pypi_name'] + version = metadata['version'] + url = f"https://pypi.org/pypi/{name}/json" + + print(f"{filename}: UPDATE {name} from {version} to {latest_version} {url}") if __name__ == '__main__':