Skip to content

Commit a2d9a88

Browse files
committed
Add tests
1 parent 1cbb473 commit a2d9a88

File tree

1 file changed

+102
-8
lines changed

1 file changed

+102
-8
lines changed

tests/test_google.py

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import pytest
2+
13
from docstring_to_markdown.google import google_to_markdown, looks_like_google
24

35
BASIC_EXAMPLE = """Do **something**.
46
7+
Some more detailed description.
8+
59
Args:
610
a: some arg
711
b: some arg
@@ -12,25 +16,115 @@
1216

1317
BASIC_EXAMPLE_MD = """Do **something**.
1418
15-
# Args
19+
Some more detailed description.
20+
21+
#### Args
1622
17-
- a: some arg
18-
- b: some arg
23+
- `a`: some arg
24+
- `b`: some arg
1925
20-
# Returns
26+
#### Returns
2127
2228
- Same *stuff*
2329
"""
2430

31+
ESCAPE_MAGIC_METHOD = """Example.
32+
33+
Args:
34+
a: see __init__.py
35+
"""
36+
37+
ESCAPE_MAGIC_METHOD_MD = """Example.
38+
39+
#### Args
40+
41+
- `a`: see \\_\\_init\\_\\_.py
42+
"""
43+
44+
PLAIN_SECTION = """Example.
45+
46+
Args:
47+
a: some arg
48+
49+
Note:
50+
Do not use this.
51+
52+
Example:
53+
Do it like this.
54+
"""
55+
56+
PLAIN_SECTION_MD = """Example.
57+
58+
#### Args
59+
60+
- `a`: some arg
61+
62+
#### Note
63+
64+
Do not use this.
65+
66+
#### Example
67+
68+
Do it like this.
69+
"""
70+
71+
MULTILINE_ARG_DESCRIPTION = """Example.
72+
73+
Args:
74+
a (str): This is a long description
75+
spanning over several lines
76+
also with broken indentation
77+
b (str): Second arg
78+
"""
79+
80+
MULTILINE_ARG_DESCRIPTION_MD = """Example.
81+
82+
#### Args
83+
84+
- `a (str)`: This is a long description
85+
spanning over several lines
86+
also with broken indentation
87+
- `b (str)`: Second arg
88+
"""
89+
90+
GOOGLE_CASES = {
91+
"basic example": {
92+
"google": BASIC_EXAMPLE,
93+
"md": BASIC_EXAMPLE_MD,
94+
},
95+
"escape magic method": {
96+
"google": ESCAPE_MAGIC_METHOD,
97+
"md": ESCAPE_MAGIC_METHOD_MD,
98+
},
99+
"plain section": {
100+
"google": PLAIN_SECTION,
101+
"md": PLAIN_SECTION_MD,
102+
},
103+
"multiline arg description": {
104+
"google": MULTILINE_ARG_DESCRIPTION,
105+
"md": MULTILINE_ARG_DESCRIPTION_MD,
106+
},
107+
}
108+
25109

26-
def test_looks_like_google_recognises_google():
27-
assert looks_like_google(BASIC_EXAMPLE)
110+
@pytest.mark.parametrize(
111+
"google",
112+
[case["google"] for case in GOOGLE_CASES.values()],
113+
ids=GOOGLE_CASES.keys(),
114+
)
115+
def test_looks_like_google_recognises_google(google):
116+
assert looks_like_google(google)
28117

29118

30119
def test_looks_like_google_ignores_plain_text():
31120
assert not looks_like_google("This is plain text")
32121
assert not looks_like_google("See Also\n--------\n")
33122

34123

35-
def test_google_to_markdown():
36-
assert google_to_markdown(BASIC_EXAMPLE) == BASIC_EXAMPLE_MD
124+
@pytest.mark.parametrize(
125+
"google,markdown",
126+
[[case["google"], case["md"]] for case in GOOGLE_CASES.values()],
127+
ids=GOOGLE_CASES.keys(),
128+
)
129+
def test_google_to_markdown(google, markdown):
130+
assert google_to_markdown(google) == markdown

0 commit comments

Comments
 (0)