aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/traitlets/py3/tests/test_traitlets_docstring.py
blob: 685ea71f695d892198585c0bd787d9176ca60d30 (plain) (blame)
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
"""Tests for traitlets.traitlets."""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
#
from __future__ import annotations

from traitlets import Dict, Instance, Integer, Unicode, Union
from traitlets.config import Configurable


def test_handle_docstring():
    class SampleConfigurable(Configurable):
        pass

    class TraitTypesSampleConfigurable(Configurable):
        """TraitTypesSampleConfigurable docstring"""

        trait_integer = Integer(
            help="""trait_integer help text""",
            config=True,
        )
        trait_integer_nohelp = Integer(
            config=True,
        )
        trait_integer_noconfig = Integer(
            help="""trait_integer_noconfig help text""",
        )

        trait_unicode = Unicode(
            help="""trait_unicode help text""",
            config=True,
        )
        trait_unicode_nohelp = Unicode(
            config=True,
        )
        trait_unicode_noconfig = Unicode(
            help="""trait_unicode_noconfig help text""",
        )

        trait_dict = Dict(
            help="""trait_dict help text""",
            config=True,
        )
        trait_dict_nohelp = Dict(
            config=True,
        )
        trait_dict_noconfig = Dict(
            help="""trait_dict_noconfig help text""",
        )

        trait_instance = Instance(
            klass=SampleConfigurable,
            help="""trait_instance help text""",
            config=True,
        )
        trait_instance_nohelp = Instance(
            klass=SampleConfigurable,
            config=True,
        )
        trait_instance_noconfig = Instance(
            klass=SampleConfigurable,
            help="""trait_instance_noconfig help text""",
        )

        trait_union = Union(
            [Integer(), Unicode()],
            help="""trait_union help text""",
            config=True,
        )
        trait_union_nohelp = Union(
            [Integer(), Unicode()],
            config=True,
        )
        trait_union_noconfig = Union(
            [Integer(), Unicode()],
            help="""trait_union_noconfig help text""",
        )

    base_names = SampleConfigurable().trait_names()
    for name in TraitTypesSampleConfigurable().trait_names():
        if name in base_names:
            continue
        doc = getattr(TraitTypesSampleConfigurable, name).__doc__
        if "nohelp" not in name:
            assert doc == f"{name} help text"