def find_pep8_errors(cls, filename=None, lines=None):
try:
sys.stdout = cStringIO.StringIO()
config = {}
# Ignore long lines on test files, as the test names can get long
# when following our test naming standards.
if cls._is_test(filename):
config['ignore'] = ['E501']
checker = pep8.Checker(filename=filename, lines=lines,
**config)
checker.check_all()
output = sys.stdout.getvalue()
finally:
sys.stdout = sys.__stdout__
errors = []
for line in output.split('\n'):
parts = line.split(' ', 2)
if len(parts) == 3:
location, error, desc = parts
line_no = location.split(':')[1]
errors.append('%s ln:%s %s' % (error, line_no, desc))
return errors
评论列表
文章目录