2016-07-22 21:22:28 +00:00
|
|
|
# Copyright (c) 2016 Luis Escobar <lescobar@vauxoo.com>
|
|
|
|
# Copyright (c) 2016 Claudiu Popa <pcmanticore@gmail.com>
|
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
|
2016-04-13 20:00:00 +00:00
|
|
|
"""Tests for the pylint checker in :mod:`pylint.extensions.check_docstring
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os.path as osp
|
|
|
|
|
|
|
|
from pylint import checkers
|
2016-06-30 13:37:17 +00:00
|
|
|
from pylint.extensions.docstyle import DocStringStyleChecker
|
2016-04-13 20:00:00 +00:00
|
|
|
from pylint.lint import PyLinter
|
2016-12-05 18:29:08 +00:00
|
|
|
from pylint.testutils import MinimalTestReporter
|
2016-04-13 20:00:00 +00:00
|
|
|
|
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
class TestCheckDocStringStyle(object):
|
2016-04-13 20:00:00 +00:00
|
|
|
|
|
|
|
expected_msg = [
|
2016-04-15 02:05:26 +00:00
|
|
|
'First line empty in function docstring',
|
2016-04-13 20:00:00 +00:00
|
|
|
'First line empty in class docstring',
|
2016-04-30 11:11:11 +00:00
|
|
|
'First line empty in method docstring',
|
2016-04-13 20:00:00 +00:00
|
|
|
'Bad docstring quotes in method, expected """, given \'\'\'',
|
|
|
|
'Bad docstring quotes in method, expected """, given "',
|
|
|
|
'Bad docstring quotes in method, expected """, given \'',
|
|
|
|
'Bad docstring quotes in method, expected """, given \'',
|
|
|
|
]
|
|
|
|
expected_symbol = [
|
2016-04-30 11:11:11 +00:00
|
|
|
'docstring-first-line-empty',
|
2016-04-15 02:05:26 +00:00
|
|
|
'docstring-first-line-empty',
|
2016-04-13 20:00:00 +00:00
|
|
|
'docstring-first-line-empty',
|
|
|
|
'bad-docstring-quotes',
|
|
|
|
'bad-docstring-quotes',
|
|
|
|
'bad-docstring-quotes',
|
|
|
|
'bad-docstring-quotes',
|
|
|
|
]
|
|
|
|
|
|
|
|
@classmethod
|
2016-12-06 15:42:53 +00:00
|
|
|
def setup_class(cls):
|
2016-04-13 20:00:00 +00:00
|
|
|
cls._linter = PyLinter()
|
2016-12-05 18:29:08 +00:00
|
|
|
cls._linter.set_reporter(MinimalTestReporter())
|
2016-04-13 20:00:00 +00:00
|
|
|
checkers.initialize(cls._linter)
|
2016-06-30 13:26:17 +00:00
|
|
|
cls._linter.register_checker(DocStringStyleChecker(cls._linter))
|
2016-04-13 20:00:00 +00:00
|
|
|
|
|
|
|
def test_docstring_message(self):
|
|
|
|
docstring_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
|
|
|
|
'docstring.py')
|
|
|
|
self._linter.check([docstring_test])
|
|
|
|
msgs = self._linter.reporter.messages
|
2016-12-02 17:09:18 +00:00
|
|
|
assert len(msgs) == 7
|
2016-04-13 20:00:00 +00:00
|
|
|
for msg, expected_symbol, expected_msg in zip(msgs,
|
|
|
|
self.expected_symbol,
|
|
|
|
self.expected_msg):
|
2016-12-02 17:09:18 +00:00
|
|
|
assert msg.symbol == expected_symbol
|
|
|
|
assert msg.msg == expected_msg
|
2016-04-13 20:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-12-06 15:42:53 +00:00
|
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
pytest.main(sys.argv)
|