Add support for skipping files

Track files being skipped along with reason (e.g. error opening file,
file has bad syntax and can't be parsed) and include in final output.
This commit is contained in:
Jamie Finnigan 2014-07-17 12:10:18 -07:00
parent 7c94d3625e
commit 6d8b7b552b
3 changed files with 14 additions and 4 deletions

View File

@ -47,6 +47,7 @@ class BanditManager():
sys.exit(2)
except IOError as e:
self.logger.error("%s" % e.strerror)
b_rs.skip(fname, e.strerror)
sys.stdout.write("]\n")
sys.stdout.flush()
else:
@ -63,8 +64,7 @@ class BanditManager():
try:
res.visit(ast.parse("".join(fdata.readlines())))
except SyntaxError as e:
self.logger.error("syntax error while parsing AST from file: %s" % fname)
sys.exit(2)
b_rs.skip(fname, "syntax error while parsing AST from file")
def _init_logger(self, debug=False):
log_level = logging.INFO

View File

@ -11,11 +11,16 @@ import utils
class BanditResultStore():
resstore = OrderedDict()
count = 0
skipped = None
def __init__(self, logger):
self.count = 0
self.skipped = []
self.logger = logger
def skip(self, filename, reason):
self.skipped.append((filename, reason))
def add(self, context, issue):
filename, lineno = context['filename'], context['lineno']
(issue_type, issue_text) = issue
@ -31,9 +36,13 @@ class BanditResultStore():
tmpstr = ""
if self.count > 0:
tmpstr += "%sFiles tested (%s):%s\n\t" % (utils.color['HEADER'], len(scope), utils.color['DEFAULT']) if is_tty else "File tested (%s):\n\t" % (len(scope))
tmpstr += "%s\n" % "\n\t".join(scope)
tmpstr += "%sTest results:%s\n" % (utils.color['HEADER'], utils.color['DEFAULT']) if is_tty else "Test results:\n"
tmpstr += "%sFiles skipped (%s):%s" % (utils.color['HEADER'], len(self.skipped), utils.color['DEFAULT']) if is_tty else "File skipped (%s):\n\t" % (len(self.skipped))
for (fname, reason) in self.skipped:
tmpstr += "\n\t%s (%s)" % (fname, reason)
tmpstr += "\n%sTest results:%s\n" % (utils.color['HEADER'], utils.color['DEFAULT']) if is_tty else "Test results:\n"
for filename,issues in self.resstore.items():
for lineno, issue_type, issue_text in issues:

1
examples/nonsense.py Normal file
View File

@ -0,0 +1 @@
test(hi