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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
import pytest
from docstring_to_markdown.google import google_to_markdown, looks_like_google
BASIC_EXAMPLE = """Do **something**.
Some more detailed description.
Args:
a: some arg
b: some arg
Returns:
Same *stuff*
"""
BASIC_EXAMPLE_MD = """Do **something**.
Some more detailed description.
#### Args
- `a`: some arg
- `b`: some arg
#### Returns
- Same *stuff*
"""
ESCAPE_MAGIC_METHOD = """Example.
Args:
a: see __init__.py
"""
ESCAPE_MAGIC_METHOD_MD = """Example.
#### Args
- `a`: see \\_\\_init\\_\\_.py
"""
PLAIN_SECTION = """Example.
Args:
a: some arg
Note:
Do not use this.
Example:
Do it like this.
"""
PLAIN_SECTION_MD = """Example.
#### Args
- `a`: some arg
#### Note
Do not use this.
#### Example
Do it like this.
"""
MULTILINE_ARG_DESCRIPTION = """Example.
Args:
a (str): This is a long description
spanning over several lines
also with broken indentation
b (str): Second arg
c (str):
On the next line
And also multiple lines
"""
MULTILINE_ARG_DESCRIPTION_MD = """Example.
#### Args
- `a (str)`: This is a long description
spanning over several lines
also with broken indentation
- `b (str)`: Second arg
- `c (str)`: On the next line
And also multiple lines
"""
GOOGLE_CASES = {
"basic example": {
"google": BASIC_EXAMPLE,
"md": BASIC_EXAMPLE_MD,
},
"escape magic method": {
"google": ESCAPE_MAGIC_METHOD,
"md": ESCAPE_MAGIC_METHOD_MD,
},
"plain section": {
"google": PLAIN_SECTION,
"md": PLAIN_SECTION_MD,
},
"multiline arg description": {
"google": MULTILINE_ARG_DESCRIPTION,
"md": MULTILINE_ARG_DESCRIPTION_MD,
},
}
@pytest.mark.parametrize(
"google",
[case["google"] for case in GOOGLE_CASES.values()],
ids=GOOGLE_CASES.keys(),
)
def test_looks_like_google_recognises_google(google):
assert looks_like_google(google)
def test_looks_like_google_ignores_plain_text():
assert not looks_like_google("This is plain text")
assert not looks_like_google("See Also\n--------\n")
@pytest.mark.parametrize(
"google,markdown",
[[case["google"], case["md"]] for case in GOOGLE_CASES.values()],
ids=GOOGLE_CASES.keys(),
)
def test_google_to_markdown(google, markdown):
assert google_to_markdown(google) == markdown
|