Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions bears/python/PycodestyleBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,22 @@ def create_arguments(
def process_output(self, output, filename, file):
if not output: # backwards compatible no results
return
result = re.match(OUTPUT_REGEX, output)
result = re.findall(OUTPUT_REGEX, output)
if not result: # backwards compatible no results
self.warn('{}: Unexpected output {}'.format(filename, output))
return
line, column, message, rule = result.groups()
if rule == 'E501':
aspect = LineLength('py')
else:
aspect = None
yield Result.from_values(
origin='{} ({})'.format(self.name, rule),
message=message,
file=filename,
line=int(line),
column=int(column),
aspect=aspect,
)

for line, column, message, rule in result:
if rule == 'E501':
aspect = LineLength('py')
else:
aspect = None

yield Result.from_values(
origin='{} ({})'.format(self.name, rule),
message=message,
file=filename,
line=int(line),
column=int(column),
aspect=aspect,
)
11 changes: 11 additions & 0 deletions tests/python/PycodestyleBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def hello():
print("hello world")
'''

multiple_error_file = '''
y = 10;
print( 'hello' )
'''

file_with_very_long_line = ('def ' + 'h' * 1000 + '():\n' +
' print("hello")')

Expand Down Expand Up @@ -114,3 +119,9 @@ def test_line_length(self):
'E501 line too long (106 > 30 characters)')
self.assertEqual(result.origin, 'PycodestyleBear (E501)')
self.assertEqual(result.aspect, LineLength('py'))

def test_multiple_errors(self):
content = multiple_error_file.splitlines()
with prepare_file(content, None) as (file, fname):
with execute_bear(self.uut, fname, file) as results:
self.assertTrue(len(results) == 3)