Skip to content

Commit 9f46d10

Browse files
committed
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 e232f94 commit 9f46d10

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

bears/general/KeywordBear.py

+5-1
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
@@ -19,7 +20,10 @@ def _get_comments(dependency_results):
1920
return
2021

2122
for result in annotation_bear_results:
22-
yield from result.contents.get('comments', [])
23+
if isinstance(result.contents, str):
24+
logging.error(result.contents)
25+
else:
26+
yield from result.contents.get('comments', [])
2327

2428

2529
def generate_diff(comments, file, filename,

tests/general/KeywordBearTest.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import namedtuple
22
from queue import Queue
33
import unittest
4+
import logging
45

56
from bears.general.KeywordBear import KeywordBear
67
from coalib.results.HiddenResult import HiddenResult
@@ -214,3 +215,27 @@ def test_keyword_regex(self):
214215
self.assertEqual(result[0].message, 'The line contains the keyword'
215216
" 'Issue #123' which resulted "
216217
'in a match with given regex.')
218+
219+
def test_wrong_language(self):
220+
self.section.append(Setting('language', 'anything'))
221+
logger = logging.getLogger()
222+
annotation_bear_result_type = namedtuple('result', 'contents')
223+
dep_results = {
224+
'AnnotationBear': [
225+
annotation_bear_result_type(
226+
'coalang specification for anything not found.')
227+
]
228+
}
229+
230+
text = ['# todo 123']
231+
232+
with self.assertLogs(logger, 'ERROR') as log:
233+
with execute_bear(self.uut, filename='F', file=text,
234+
dependency_results=dep_results) as result:
235+
self.assertEqual(len(result), 1)
236+
self.assertEqual(result[0].diffs, {})
237+
self.assertEqual(result[0].affected_code[0].start.line, 1)
238+
self.assertEqual(len(log.output), 1)
239+
self.assertIn(log.output[0],
240+
'ERROR:root:coalang specification'
241+
' for anything not found.')

0 commit comments

Comments
 (0)