Fix ansible-test pylint and pep8 issues. (#24245)

* Fix pylint useless-super-delegation issues.
* Fix miscellaneous pylint issues.
* Fix PEP 8 issues.
* Fix warnings reported by PyCharm.
This commit is contained in:
Matt Clay 2017-05-03 23:19:44 +08:00 committed by GitHub
parent a93aa6dc04
commit 6522d703a1
15 changed files with 22 additions and 71 deletions

View file

@ -39,11 +39,7 @@ class InvalidBranch(ApplicationError):
class ChangeDetectionNotSupported(ApplicationError):
"""Exception for cases where change detection is not supported."""
def __init__(self, message):
"""
:type message: str
"""
super(ChangeDetectionNotSupported, self).__init__(message)
pass
class ShippableChanges(object):

View file

@ -77,7 +77,7 @@ def categorize_changes(paths, verbose_command=None):
# identify targeted integration tests (those which only target a single integration command)
if 'integration' in verbose_command and tests.get(verbose_command):
if not any('integration' in command for command in tests.keys() if command != verbose_command):
if not any('integration' in command for command in tests if command != verbose_command):
result += ' (targeted)'
else:
result = '%s' % tests
@ -91,7 +91,7 @@ def categorize_changes(paths, verbose_command=None):
if any(t == 'all' for t in commands[command]):
commands[command] = set(['all'])
commands = dict((c, sorted(commands[c])) for c in commands.keys() if commands[c])
commands = dict((c, sorted(commands[c])) for c in commands if commands[c])
return commands

View file

@ -29,7 +29,6 @@ from lib.manage_ci import (
)
from lib.util import (
CommonConfig,
EnvironmentConfig,
ApplicationWarning,
ApplicationError,
@ -83,10 +82,6 @@ from lib.test import (
TestSkipped,
)
from lib.metadata import (
Metadata,
)
SUPPORTED_PYTHON_VERSIONS = (
'2.6',
'2.7',
@ -478,9 +473,9 @@ def command_integration_filtered(args, targets):
run_command(args, ['ssh', '-o', 'BatchMode=yes', 'localhost', 'id'], capture=True)
display.info('SSH service responded.')
break
except SubprocessError as ex:
except SubprocessError:
if i == max_tries:
raise ex
raise
seconds = 3
display.warning('SSH service not responding. Waiting %d second(s) before checking again.' % seconds)
time.sleep(seconds)

View file

@ -84,7 +84,7 @@ class Git(object):
"""
output = self.run_git(cmd).strip(separator)
if len(output) == 0:
if not output:
return []
return output.split(separator)

View file

@ -10,7 +10,7 @@ import json
try:
from urllib import urlencode
except ImportError:
# noinspection PyCompatibility,PyUnresolvedReferences,PyUnresolvedReferences
# noinspection PyCompatibility, PyUnresolvedReferences
from urllib.parse import urlencode # pylint: disable=locally-disabled, import-error, no-name-in-module
from lib.util import (

View file

@ -4,7 +4,6 @@ from __future__ import absolute_import, print_function
import ast
import os
import uuid
from lib.util import (
display,
@ -110,7 +109,7 @@ def get_python_module_utils_imports(compile_targets):
display.info('%s reports imports from parent package %s' % (virtual_util, parent_package), verbosity=6)
for module_util in sorted(imports):
if not len(imports[module_util]):
if not imports[module_util]:
display.warning('No imports found which use the "%s" module_util.' % module_util)
return imports

View file

@ -9,7 +9,6 @@ from lib.util import (
from lib.diff import (
parse_diff,
FileDiff,
)

View file

@ -673,22 +673,13 @@ def collect_code_smell_tests():
skip_tests = skip_fd.read().splitlines()
paths = glob.glob('test/sanity/code-smell/*')
paths = sorted(p for p in paths
if os.access(p, os.X_OK)
and os.path.isfile(p)
and os.path.basename(p) not in skip_tests)
paths = sorted(p for p in paths if os.access(p, os.X_OK) and os.path.isfile(p) and os.path.basename(p) not in skip_tests)
tests = tuple(SanityFunc(os.path.splitext(os.path.basename(p))[0], command_sanity_code_smell, script=p, intercept=False) for p in paths)
return tests
def sanity_init():
"""Initialize full sanity test list (includes code-smell scripts determined at runtime)."""
global SANITY_TESTS # pylint: disable=locally-disabled, global-statement
SANITY_TESTS = tuple(sorted(SANITY_TESTS + collect_code_smell_tests(), key=lambda k: k.name))
def sanity_get_tests():
"""
:rtype: tuple(SanityFunc)
@ -730,17 +721,7 @@ class SanityFailure(TestFailure):
class SanityMessage(TestMessage):
"""Single sanity test message for one file."""
def __init__(self, message, path, line=0, column=0, level='error', code=None, confidence=None):
"""
:type message: str
:type path: str
:type line: int
:type column: int
:type level: str
:type code: str | None
:type confidence: int | None
"""
super(SanityMessage, self).__init__(message, path, line, column, level, code, confidence)
pass
class SanityTargets(object):
@ -788,3 +769,9 @@ SANITY_TESTS = (
SanityFunc('validate-modules', command_sanity_validate_modules, intercept=False),
SanityFunc('ansible-doc', command_sanity_ansible_doc),
)
def sanity_init():
"""Initialize full sanity test list (includes code-smell scripts determined at runtime)."""
global SANITY_TESTS # pylint: disable=locally-disabled, global-statement
SANITY_TESTS = tuple(sorted(SANITY_TESTS + collect_code_smell_tests(), key=lambda k: k.name))

View file

@ -323,7 +323,7 @@ class CompletionTarget(object):
def __eq__(self, other):
if isinstance(other, CompletionTarget):
return self.__repr__() == other.__repr__()
else:
return False
def __ne__(self, other):

View file

@ -192,14 +192,6 @@ class TestResult(object):
class TestSuccess(TestResult):
"""Test success."""
def __init__(self, command, test, python_version=None):
"""
:type command: str
:type test: str
:type python_version: str
"""
super(TestSuccess, self).__init__(command, test, python_version)
def write_junit(self, args):
"""
:type args: TestConfig
@ -211,14 +203,6 @@ class TestSuccess(TestResult):
class TestSkipped(TestResult):
"""Test skipped."""
def __init__(self, command, test, python_version=None):
"""
:type command: str
:type test: str
:type python_version: str
"""
super(TestSkipped, self).__init__(command, test, python_version)
def write_console(self):
"""Write results to console."""
display.info('No tests applicable.', verbosity=1)

View file

@ -19,6 +19,7 @@ class WrappedThread(threading.Thread):
"""
:type action: () -> any
"""
# noinspection PyOldStyleClasses
super(WrappedThread, self).__init__()
self._result = queue.Queue()
self.action = action

View file

@ -372,20 +372,12 @@ class Display(object):
class ApplicationError(Exception):
"""General application error."""
def __init__(self, message=None):
"""
:type message: str | None
"""
super(ApplicationError, self).__init__(message)
pass
class ApplicationWarning(Exception):
"""General application warning which interrupts normal program flow."""
def __init__(self, message=None):
"""
:type message: str | None
"""
super(ApplicationWarning, self).__init__(message)
pass
class SubprocessError(ApplicationError):

View file

@ -4,6 +4,7 @@
from __future__ import absolute_import, print_function
# noinspection PyCompatibility
import argparse
import errno
import os

View file

@ -391,7 +391,6 @@ def add_lint(parser):
help='exit successfully on failed tests after saving results')
def add_changes(parser, argparse):
"""
:type parser: argparse.ArgumentParser

View file

@ -964,8 +964,6 @@ test/integration/gce_credentials.py
test/integration/setup_gce.py
test/integration/targets/async/library/async_test.py
test/integration/targets/uri/files/testserver.py
test/runner/lib/sanity.py
test/runner/test.py
test/sanity/code-smell/ansible-var-precedence-check.py
test/sanity/validate-modules/module_args.py
test/sanity/validate-modules/schema.py