ansible-test - Cleanup to prepare for pylint update. (#75469)

* ansible-test - Fix use of abstractproperty
* ansible-test - Use dict.items() where possible.
* ansible-test - Remove unused code.
* ansible-test - Cleanup issues reported by pylint.
* ansible-test - Use dict.items() where possible.
* ansible-test - Use generator.
pull/75491/head
Matt Clay 3 years ago committed by GitHub
parent 39605cdcce
commit ca2d2c5f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -241,12 +241,14 @@ class Validator(with_metaclass(abc.ABCMeta, object)):
def __init__(self, reporter=None):
self.reporter = reporter
@abc.abstractproperty
@property
@abc.abstractmethod
def object_name(self):
"""Name of the object we validated"""
pass
@abc.abstractproperty
@property
@abc.abstractmethod
def object_path(self):
"""Path of the object we validated"""
pass

@ -156,17 +156,17 @@ def categorize_changes(args, paths, verbose_command=None):
if none_count > 0 and args.verbosity < 2:
display.notice('Omitted %d file(s) that triggered no tests.' % none_count)
for command in commands:
commands[command].discard('none')
for command, targets in commands.items():
targets.discard('none')
if any(target == 'all' for target in commands[command]):
if any(target == 'all' for target in targets):
commands[command] = set(['all'])
commands = dict((c, sorted(commands[c])) for c in commands if commands[c])
focused_commands = dict((c, sorted(focused_commands[c])) for c in focused_commands)
commands = dict((c, sorted(targets)) for c, targets in commands.items() if targets)
focused_commands = dict((c, sorted(targets)) for c, targets in focused_commands.items())
for command in commands:
if commands[command] == ['all']:
for command, targets in commands.items():
if targets == ['all']:
commands[command] = [] # changes require testing all targets, do not filter targets
changes = ChangeDescription()

@ -41,8 +41,8 @@ def get_csharp_module_utils_imports(powershell_targets, csharp_targets):
imports = dict([(module_util, set()) for module_util in module_utils])
for target_path in imports_by_target_path:
for module_util in imports_by_target_path[target_path]:
for target_path, modules in imports_by_target_path.items():
for module_util in modules:
imports[module_util].add(target_path)
for module_util in sorted(imports):

@ -37,8 +37,8 @@ def get_powershell_module_utils_imports(powershell_targets):
imports = dict([(module_util, set()) for module_util in module_utils])
for target_path in imports_by_target_path:
for module_util in imports_by_target_path[target_path]:
for target_path, modules in imports_by_target_path.items():
for module_util in modules:
imports[module_util].add(target_path)
for module_util in sorted(imports):

@ -97,17 +97,17 @@ def get_python_module_utils_imports(compile_targets):
module_util_imports.remove(module_util)
# add recursive imports to all path entries which import this module_util
for target_path in imports_by_target_path:
if module_util in imports_by_target_path[target_path]:
for target_path, modules in imports_by_target_path.items():
if module_util in modules:
for module_util_import in sorted(module_util_imports):
if module_util_import not in imports_by_target_path[target_path]:
if module_util_import not in modules:
display.info('%s inherits import %s via %s' % (target_path, module_util_import, module_util), verbosity=6)
imports_by_target_path[target_path].add(module_util_import)
modules.add(module_util_import)
imports = dict([(module_util, set()) for module_util in module_utils | virtual_utils])
for target_path in imports_by_target_path:
for module_util in imports_by_target_path[target_path]:
for target_path, modules in imports_by_target_path.items():
for module_util in modules:
imports[module_util].add(target_path)
# for purposes of mapping module_utils to paths, treat imports of virtual utils the same as the parent package

@ -1050,6 +1050,6 @@ def sanity_init():
import_plugins('commands/sanity')
sanity_plugins = {} # type: t.Dict[str, t.Type[SanityFunc]]
load_plugins(SanityFunc, sanity_plugins)
sanity_tests = tuple([plugin() for plugin in sanity_plugins.values() if data_context().content.is_ansible or not plugin.ansible_only])
sanity_tests = tuple(plugin() for plugin in sanity_plugins.values() if data_context().content.is_ansible or not plugin.ansible_only)
global SANITY_TESTS # pylint: disable=locally-disabled, global-statement
SANITY_TESTS = tuple(sorted(sanity_tests + collect_code_smell_tests(), key=lambda k: k.name))

@ -126,13 +126,13 @@ class AnsibleCoreCI:
else:
self.provider = None
for candidate in self.PROVIDERS:
for candidate, platforms in self.PROVIDERS.items():
choices = [
platform,
'%s arch=%s' % (platform, arch),
]
if any(choice in self.PROVIDERS[candidate] for choice in choices):
if any(choice in platforms for choice in choices):
# assign default provider based on platform
self.provider = candidate
break

@ -87,8 +87,8 @@ def open_binary_file(path, mode='rb'): # type: (str, str) -> t.BinaryIO
class SortedSetEncoder(json.JSONEncoder):
"""Encode sets as sorted lists."""
def default(self, obj): # pylint: disable=method-hidden, arguments-differ
if isinstance(obj, set):
return sorted(obj)
def default(self, o):
if isinstance(o, set):
return sorted(o)
return json.JSONEncoder.default(self, obj)
return json.JSONEncoder.default(self, o)

@ -16,9 +16,6 @@ from . import (
class CollectionLayout(LayoutProvider):
"""Layout provider for Ansible collections."""
__module_path = 'plugins/modules'
__unit_path = 'test/unit'
@staticmethod
def is_content_root(path): # type: (str) -> bool
"""Return True if the given path is a content root for this provider."""

Loading…
Cancel
Save