Skip to content

Commit

Permalink
Standardize results reporting
Browse files Browse the repository at this point in the history
On regular mode, only log FAILed files, but on verbose
mode, log PASSed as well.

Signed-off-by: Lucas Meneghel Rodrigues <lookkas@gmail.com>
  • Loading branch information
lmr committed Aug 9, 2017
1 parent a720ce7 commit 4090f51
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 4 additions & 3 deletions inspektor/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def check_file(self, path):
didn't find problems, path is not a python module or
script.
"""
checker = PathChecker(path=path, args=self.args, label='Indent')
checker = PathChecker(path=path, args=self.args, label='Indent',
logger=self.log)
if not checker.check_attributes('text', 'python', 'not_empty'):
return True

Expand All @@ -219,15 +220,15 @@ def check_file(self, path):
f.close()
try:
if r.run():
self.log.error('Indentation check fail : %s', path)
self.failed_paths.append(path)
if self.args.fix:
f = open(path, "w")
r.write(f)
f.close()
self.log.info('FIX OK')
checker.log_status(status='FAIL')
return False
else:
checker.log_status(status='PASS')
return True
except IndentationError:
self.log.error("Indentation check fail : %s", path)
Expand Down
6 changes: 4 additions & 2 deletions inspektor/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def check_dir(self, path):
return not self.failed_paths

def check_file(self, path):
checker = PathChecker(path=path, args=self.args, label='License')
checker = PathChecker(path=path, args=self.args, label='License',
logger=self.log)
# Don't put license info in empty __init__.py files.
if not checker.check_attributes('text', 'python', 'not_empty'):
return True
Expand All @@ -98,9 +99,10 @@ def check_file(self, path):
inspected_file.write(new_content)

self.failed_paths.append(path)
self.log.error('License check (%s) fail: %s', self.license_type, path)
checker.log_status(status='FAIL')
return False
else:
checker.log_status(status='PASS')
return True

def check(self, path):
Expand Down
8 changes: 6 additions & 2 deletions inspektor/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,23 @@ def check_file(self, path):
:return: False, if pylint found syntax problems, True, if pylint didn't
find problems, or path is not a python module or script.
"""
checker = PathChecker(path=path, args=self.args, label='Lint')
checker = PathChecker(path=path, args=self.args, label='Lint',
logger=self.log)
if not checker.check_attributes('text', 'python', 'not_empty'):
return True
try:
runner = Run(self.get_opts() + [path], exit=False)
if runner.linter.msg_status != 0:
self.log.error('Pylint check fail: %s', path)
self.failed_paths.append(path)
checker.log_status(status='FAIL')
else:
checker.log_status(status='PASS')
return runner.linter.msg_status == 0
except Exception as details:
self.log.error('Pylint check fail: %s (pylint exception: %s)',
path, details)
self.failed_paths.append(path)
checker.log_status(status='FAIL')
return False

def check(self, path):
Expand Down
8 changes: 6 additions & 2 deletions inspektor/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def check_attributes(self, *args):
checks_passed = True
for arg in args:
checks_passed &= getattr(self.path, arg)
if checks_passed:
self.log.debug('%s: %s', self.label, self.path)
return checks_passed

def log_status(self, status):
if status == 'PASS':
self.log.debug('%s: %s %s', self.label, self.path, status)
elif status == 'FAIL':
self.log.error('%s: %s %s', self.label, self.path, status)
7 changes: 5 additions & 2 deletions inspektor/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def check_file(self, path):
:return: False, if pylint found syntax problems, True, if pylint didn't
find problems, or path is not a python module or script.
"""
checker = PathChecker(path=path, args=self.args, label='Style')
checker = PathChecker(path=path, args=self.args, label='Style',
logger=self.log)
if not checker.check_attributes('text', 'python', 'not_empty'):
return True

Expand All @@ -82,7 +83,7 @@ def check_file(self, path):
status = 1

if status != 0:
self.log.error('Style check fail: %s', path)
checker.log_status(status='FAIL')
self.failed_paths.append(path)
if AUTOPEP8_CAPABLE:
if self.args.fix:
Expand All @@ -96,6 +97,8 @@ def check_file(self, path):
else:
self.log.error('Python library autopep8 not installed. '
'Please install it if you want to use --fix')
else:
checker.log_status(status='PASS')

return status == 0

Expand Down

0 comments on commit 4090f51

Please sign in to comment.