[go: up one dir, main page]

File: test_docstrings.py

package info (click to toggle)
seaborn 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,148 kB
  • sloc: python: 36,560; makefile: 183; javascript: 45; sh: 15
file content (58 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (2)
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
from seaborn._docstrings import DocstringComponents


EXAMPLE_DICT = dict(
    param_a="""
a : str
    The first parameter.
    """,
)


class ExampleClass:
    def example_method(self):
        """An example method.

        Parameters
        ----------
        a : str
           A method parameter.

        """


def example_func():
    """An example function.

    Parameters
    ----------
    a : str
        A function parameter.

    """


class TestDocstringComponents:

    def test_from_dict(self):

        obj = DocstringComponents(EXAMPLE_DICT)
        assert obj.param_a == "a : str\n    The first parameter."

    def test_from_nested_components(self):

        obj_inner = DocstringComponents(EXAMPLE_DICT)
        obj_outer = DocstringComponents.from_nested_components(inner=obj_inner)
        assert obj_outer.inner.param_a == "a : str\n    The first parameter."

    def test_from_function(self):

        obj = DocstringComponents.from_function_params(example_func)
        assert obj.a == "a : str\n    A function parameter."

    def test_from_method(self):

        obj = DocstringComponents.from_function_params(
            ExampleClass.example_method
        )
        assert obj.a == "a : str\n    A method parameter."