diff --git a/bear-requirements.txt b/bear-requirements.txt index 578a2eebd5..897a5f3e57 100644 --- a/bear-requirements.txt +++ b/bear-requirements.txt @@ -35,6 +35,7 @@ restructuredtext-lint~=1.0 rstcheck~=3.1 safety~=1.8.2 scspell3k~=2.0 +six~=1.11.0 sqlparse~=0.2.4 vim-vint~=0.3.12,!=0.3.19 vulture~=0.25.0 diff --git a/bears/python/PycodestyleBear.py b/bears/python/PycodestyleBear.py index 405f369677..eeff751be9 100644 --- a/bears/python/PycodestyleBear.py +++ b/bears/python/PycodestyleBear.py @@ -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) # find all matched 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, + ) diff --git a/test-requirements.txt b/test-requirements.txt index d61b2201e6..37c423025e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -22,7 +22,7 @@ pytest-reorder~=0.1.0 git+https://github.com/jayvdb/pytest-reqs@coala#egg=pytest-reqs pytest-timeout~=1.3.0 pytest-travis-fold~=1.3.0 -pytest-xdist~=1.15 +pytest-xdist==1.15 requests-mock~=1.2 ipdb~=0.11 pip<10 diff --git a/tests/python/PycodestyleBearTest.py b/tests/python/PycodestyleBearTest.py index 1a134955f8..d543832ac0 100644 --- a/tests/python/PycodestyleBearTest.py +++ b/tests/python/PycodestyleBearTest.py @@ -27,6 +27,16 @@ def hello(): print("hello world") ''' + +multiple_style_errors_file = ''' +x = 10 +y = 5; + + +print( 'test' ) +''' + + file_with_very_long_line = ('def ' + 'h' * 1000 + '():\n' + ' print("hello")') @@ -114,3 +124,19 @@ 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_style_errors(self): + content = multiple_style_errors_file.splitlines() + with prepare_file(content, None) as (file, fname): + with execute_bear(self.uut, fname, file) as results: + self.assertEqual(len(results), 4) + result = results[1] + self.assertEqual(result.message, + 'E201 whitespace after \'(\'') + self.assertEqual(result.origin, 'PycodestyleBear (E201)') + self.assertEqual(result.aspect, None) + result = results[3] + self.assertEqual(result.message, + 'W291 trailing whitespace') + self.assertEqual(result.origin, 'PycodestyleBear (W291)') + self.assertEqual(result.aspect, None)