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 11, 2017
1 parent 0abe3d7 commit 75ae1c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bears/general/KeywordBear.py
@@ -1,4 +1,5 @@
import re
import logging

from coalib.bearlib import deprecate_settings
from coalib.bears.LocalBear import LocalBear
Expand All @@ -19,7 +20,10 @@ def _get_comments(dependency_results):
return

for result in annotation_bear_results:
yield from result.contents.get('comments', [])
if isinstance(result.contents, str):
logging.error(result.contents)
else:
yield from result.contents.get('comments', [])


def generate_diff(comments, file, filename,
Expand Down
25 changes: 25 additions & 0 deletions tests/general/KeywordBearTest.py
@@ -1,6 +1,7 @@
from collections import namedtuple
from queue import Queue
import unittest
import logging

from bears.general.KeywordBear import KeywordBear
from coalib.results.HiddenResult import HiddenResult
Expand Down Expand Up @@ -214,3 +215,27 @@ 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):
self.section.append(Setting('language', 'anything'))
logger = logging.getLogger()
annotation_bear_result_type = namedtuple('result', 'contents')
dep_results = {
'AnnotationBear': [
annotation_bear_result_type(
'coalang specification for anything not found.')
]
}

text = ['# todo 123']

with self.assertLogs(logger, 'ERROR') as log:
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(len(result), 1)
self.assertEqual(result[0].diffs, {})
self.assertEqual(result[0].affected_code[0].start.line, 1)
self.assertEqual(len(log.output), 1)
self.assertIn(log.output[0],
'ERROR:root:coalang specification'
' for anything not found.')

0 comments on commit 75ae1c9

Please sign in to comment.