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:
Matt Clay 2017-08-18 11:21:53 -07:00 committed by GitHub
parent 343da35381
commit a31f4c178a
2 changed files with 38 additions and 33 deletions

View file

@ -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,23 +324,29 @@ def command_sanity_pep8(args, targets):
'--ignore', ','.join(sorted(current_ignore)), '--ignore', ','.join(sorted(current_ignore)),
] + paths ] + paths
try: if paths:
stdout, stderr = run_command(args, cmd, capture=True) try:
status = 0 stdout, stderr = run_command(args, cmd, capture=True)
except SubprocessError as ex: status = 0
stdout = ex.stdout except SubprocessError as ex:
stderr = ex.stderr stdout = ex.stdout
status = ex.status stderr = ex.stderr
status = ex.status
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)
pattern = '^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): (?P<code>[WE][0-9]{3}) (?P<message>.*)$' if stdout:
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,19 +477,22 @@ def command_sanity_pylint(args, targets):
env = ansible_environment(args) env = ansible_environment(args)
try: if paths:
stdout, stderr = run_command(args, cmd, env=env, capture=True) try:
status = 0 stdout, stderr = run_command(args, cmd, env=env, capture=True)
except SubprocessError as ex: status = 0
stdout = ex.stdout except SubprocessError as ex:
stderr = ex.stderr stdout = ex.stdout
status = ex.status stderr = ex.stderr
status = ex.status
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>.*)$'

View file

@ -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):