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."
|