Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 860c536

Browse files
committedJan 8, 2017
KeywordBear.py: Output appropriate message
Output appropriate message if the language given in input is not valid/not supported for KeywordBear Fixes coala#1256
1 parent 353bce2 commit 860c536

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
 

‎bears/general/KeywordBear.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import logging
23

34
from coalib.bearlib import deprecate_settings
45
from coalib.bears.LocalBear import LocalBear
@@ -18,8 +19,12 @@ def _get_comments(dependency_results):
1819
not isinstance(annotation_bear_results, list)):
1920
return
2021

21-
for result in annotation_bear_results:
22-
yield from result.contents.get('comments', [])
22+
try:
23+
for result in annotation_bear_results:
24+
yield from result.contents.get('comments', [])
25+
except AttributeError:
26+
logging.error(result.contents)
27+
return
2328

2429

2530
def generate_diff(comments, file, filename,

‎tests/general/KeywordBearTest.py

+17
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,20 @@ def test_keyword_regex(self):
214214
self.assertEqual(result[0].message, 'The line contains the keyword'
215215
" 'Issue #123' which resulted "
216216
'in a match with given regex.')
217+
218+
def test_wrong_language(self):
219+
section = Section('')
220+
section.append(Setting('language', 'anything'))
221+
section.append(Setting('keywords', 'TODO'))
222+
uut = KeywordBear(section, Queue())
223+
dep_results = {
224+
'AnnotationBear': HiddenResult(
225+
'coalang specification for anything not found.')
226+
}
227+
228+
text = ['# todo 123']
229+
230+
with execute_bear(uut, 'F', text,
231+
dependency_results=dep_results) as result:
232+
self.assertEqual(
233+
result.contents, 'coalang specification for anything not found.')

0 commit comments

Comments
 (0)
Please sign in to comment.