summaryrefslogtreecommitdiff
path: root/pylint/test/extensions/test_docstyle.py
blob: cad929d3185dd637243527d7db66645e0d50f9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2016-2017 Claudiu Popa <pcmanticore@gmail.com>
# Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
# Copyright (c) 2016 Luis Escobar <lescobar@vauxoo.com>

# 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

"""Tests for the pylint checker in :mod:`pylint.extensions.check_docstring
"""

from os.path import abspath, dirname, join

import pytest

from pylint.extensions.docstyle import DocStringStyleChecker

EXPECTED_MSGS = [
    'First line empty in function docstring',
    'First line empty in class docstring',
    'First line empty in method docstring',
    '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_SYMBOLS = [
    'docstring-first-line-empty',
    'docstring-first-line-empty',
    'docstring-first-line-empty',
    'bad-docstring-quotes',
    'bad-docstring-quotes',
    'bad-docstring-quotes',
    'bad-docstring-quotes',
]


@pytest.fixture(scope="module")
def checker(checker):
    return DocStringStyleChecker


def test_docstring_message(linter):
    docstring_test = join(dirname(abspath(__file__)), 'data', 'docstring.py')
    linter.check([docstring_test])
    msgs = linter.reporter.messages
    assert len(msgs) == 7
    for msg, expected_symbol, expected_msg in zip(msgs,
                                                  EXPECTED_SYMBOLS,
                                                  EXPECTED_MSGS):
        assert msg.symbol == expected_symbol
        assert msg.msg == expected_msg