summaryrefslogtreecommitdiff
path: root/tests/functional/ext/docparams/raise/missing_raises_doc.py
blob: 280d9f8e7b475931ac6ca84056eaa438b6955580 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""Tests for missing-raises-doc and missing-raises-type-doc"""
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
# pylint: disable=unused-argument, import-error, unused-variable, no-member, try-except-raise
import collections

from unknown import Unknown


def test_ignores_no_docstring(self):
    raise RuntimeError("hi")


def test_ignores_unknown_style(self):
    """This is a docstring."""
    raise RuntimeError("hi")


def test_ignores_raise_uninferable(self):
    """This is a docstring.

    :raises NameError: Never
    """
    raise Unknown("hi")
    raise NameError("hi")  # [unreachable]


def test_ignores_returns_from_inner_functions(self):  # [missing-raises-doc]
    """This is a docstring.
    We do NOT expect a warning about the OSError in inner_func!

    :raises NameError: Never
    """

    def ex_func(val):
        def inner_func(value):
            return OSError(value)

        return RuntimeError(val)

    raise ex_func("hi")
    raise NameError("hi")  # [unreachable]


def test_ignores_returns_use_only_names():
    """This is a docstring

    :raises NameError: Never
    """

    def inner_func():
        return 42

    raise inner_func()  # [raising-bad-type]


def test_ignores_returns_use_only_exception_instances():
    """This is a docstring

    :raises MyException: Never
    """

    class MyException(Exception):
        """A docstring"""

    def inner_func():
        return MyException

    raise inner_func()


def test_no_crash_when_inferring_handlers():
    """raises

    :raise U: pass
    """
    try:
        pass
    except collections.U as exc:
        raise


def test_no_crash_when_cant_find_exception():
    """raises

    :raise U: pass
    """
    try:
        pass
    except U as exc:
        raise


def test_no_error_notimplemented_documented():
    """
    Raises:
        NotImplementedError: When called.
    """
    raise NotImplementedError