Skip to content

Commit

Permalink
KeywordBear.py: Output appropriate message
Browse files Browse the repository at this point in the history
Output appropriate message if the language
given in input is not valid/not supported
for KeywordBear

Fixes #1256
  • Loading branch information
Techievena committed Jan 8, 2017
1 parent 353bce2 commit 44d0cf8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bears/general/KeywordBear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import logging

from coalib.bearlib import deprecate_settings
from coalib.bears.LocalBear import LocalBear
Expand All @@ -18,8 +19,12 @@ def _get_comments(dependency_results):
not isinstance(annotation_bear_results, list)):
return

for result in annotation_bear_results:
yield from result.contents.get('comments', [])
try:
for result in annotation_bear_results:
yield from result.contents.get('comments', [])
except AttributeError:
logging.error(result.contents)
return


def generate_diff(comments, file, filename,
Expand Down
16 changes: 16 additions & 0 deletions tests/general/KeywordBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,19 @@ def test_keyword_regex(self):
self.assertEqual(result[0].message, 'The line contains the keyword'
" 'Issue #123' which resulted "
'in a match with given regex.')

def test_wrong_language(self):
section = Section('')
section.append(Setting('language', 'anything'))
section.append(Setting('keywords', 'TODO'))
uut = KeywordBear(section, Queue())
dep_results = {
'AnnotationBear': HiddenResult(
'coalang specification for anything not found.')
}

text = ['# todo 123']

with execute_bear(uut, 'F', text,
dependency_results=dep_results) as result:
self.assertEqual(result, 'coalang specification for anything not found.')

0 comments on commit 44d0cf8

Please sign in to comment.