Fix pep8/pylint tests when deleting files. (#28410)
* Fix pep8/pylint tests when deleting files. * Improve static analysis in PyCharm. * Use success instead of skipped for explain.
This commit is contained in:
parent
343da35381
commit
a31f4c178a
2 changed files with 38 additions and 33 deletions
|
@ -206,7 +206,7 @@ def command_sanity_validate_modules(args, targets):
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
messages = json.loads(stdout)
|
messages = json.loads(stdout)
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ def command_sanity_shellcheck(args, targets):
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
# json output is missing file paths in older versions of shellcheck, so we'll use xml instead
|
# json output is missing file paths in older versions of shellcheck, so we'll use xml instead
|
||||||
root = fromstring(stdout) # type: Element
|
root = fromstring(stdout) # type: Element
|
||||||
|
@ -317,9 +317,6 @@ def command_sanity_pep8(args, targets):
|
||||||
|
|
||||||
paths = sorted(i.path for i in targets.include if (os.path.splitext(i.path)[1] == '.py' or i.path.startswith('bin/')) and i.path not in skip_paths_set)
|
paths = sorted(i.path for i in targets.include if (os.path.splitext(i.path)[1] == '.py' or i.path.startswith('bin/')) and i.path not in skip_paths_set)
|
||||||
|
|
||||||
if not paths:
|
|
||||||
return SanitySkipped(test)
|
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
'pycodestyle',
|
'pycodestyle',
|
||||||
'--max-line-length', '160',
|
'--max-line-length', '160',
|
||||||
|
@ -327,6 +324,7 @@ def command_sanity_pep8(args, targets):
|
||||||
'--ignore', ','.join(sorted(current_ignore)),
|
'--ignore', ','.join(sorted(current_ignore)),
|
||||||
] + paths
|
] + paths
|
||||||
|
|
||||||
|
if paths:
|
||||||
try:
|
try:
|
||||||
stdout, stderr = run_command(args, cmd, capture=True)
|
stdout, stderr = run_command(args, cmd, capture=True)
|
||||||
status = 0
|
status = 0
|
||||||
|
@ -337,13 +335,18 @@ def command_sanity_pep8(args, targets):
|
||||||
|
|
||||||
if stderr:
|
if stderr:
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
else:
|
||||||
|
stdout = None
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
|
if stdout:
|
||||||
pattern = '^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): (?P<code>[WE][0-9]{3}) (?P<message>.*)$'
|
pattern = '^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): (?P<code>[WE][0-9]{3}) (?P<message>.*)$'
|
||||||
|
|
||||||
results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()]
|
results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()]
|
||||||
|
else:
|
||||||
|
results = []
|
||||||
|
|
||||||
results = [SanityMessage(
|
results = [SanityMessage(
|
||||||
message=r['message'],
|
message=r['message'],
|
||||||
|
@ -460,9 +463,6 @@ def command_sanity_pylint(args, targets):
|
||||||
|
|
||||||
paths = sorted(i.path for i in targets.include if (os.path.splitext(i.path)[1] == '.py' or i.path.startswith('bin/')) and i.path not in skip_paths_set)
|
paths = sorted(i.path for i in targets.include if (os.path.splitext(i.path)[1] == '.py' or i.path.startswith('bin/')) and i.path not in skip_paths_set)
|
||||||
|
|
||||||
if not paths:
|
|
||||||
return SanitySkipped(test)
|
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
'pylint',
|
'pylint',
|
||||||
'--jobs', '0',
|
'--jobs', '0',
|
||||||
|
@ -477,6 +477,7 @@ def command_sanity_pylint(args, targets):
|
||||||
|
|
||||||
env = ansible_environment(args)
|
env = ansible_environment(args)
|
||||||
|
|
||||||
|
if paths:
|
||||||
try:
|
try:
|
||||||
stdout, stderr = run_command(args, cmd, env=env, capture=True)
|
stdout, stderr = run_command(args, cmd, env=env, capture=True)
|
||||||
status = 0
|
status = 0
|
||||||
|
@ -487,9 +488,11 @@ def command_sanity_pylint(args, targets):
|
||||||
|
|
||||||
if stderr or status >= 32:
|
if stderr or status >= 32:
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
else:
|
||||||
|
stdout = None
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
if stdout:
|
if stdout:
|
||||||
messages = json.loads(stdout)
|
messages = json.loads(stdout)
|
||||||
|
@ -557,7 +560,7 @@ def command_sanity_yamllint(args, targets):
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): \[(?P<level>warning|error)\] (?P<message>.*)$'
|
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): \[(?P<level>warning|error)\] (?P<message>.*)$'
|
||||||
|
|
||||||
|
@ -611,7 +614,7 @@ def command_sanity_rstcheck(args, targets):
|
||||||
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
||||||
|
|
||||||
if args.explain:
|
if args.explain:
|
||||||
return SanitySkipped(test)
|
return SanitySuccess(test)
|
||||||
|
|
||||||
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+): \((?P<level>INFO|WARNING|ERROR|SEVERE)/[0-4]\) (?P<message>.*)$'
|
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+): \((?P<level>INFO|WARNING|ERROR|SEVERE)/[0-4]\) (?P<message>.*)$'
|
||||||
|
|
||||||
|
|
|
@ -200,8 +200,10 @@ class TestFailure(TestResult):
|
||||||
|
|
||||||
if messages:
|
if messages:
|
||||||
messages = sorted(messages, key=lambda m: m.sort_key)
|
messages = sorted(messages, key=lambda m: m.sort_key)
|
||||||
|
else:
|
||||||
|
messages = []
|
||||||
|
|
||||||
self.messages = messages or []
|
self.messages = messages
|
||||||
self.summary = summary
|
self.summary = summary
|
||||||
|
|
||||||
def write(self, args):
|
def write(self, args):
|
||||||
|
|
Loading…
Reference in a new issue