|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from docstring_to_markdown.google import google_to_markdown, looks_like_google
|
2 | 4 |
|
3 | 5 | BASIC_EXAMPLE = """Do **something**.
|
4 | 6 |
|
| 7 | +Some more detailed description. |
| 8 | +
|
5 | 9 | Args:
|
6 | 10 | a: some arg
|
7 | 11 | b: some arg
|
|
12 | 16 |
|
13 | 17 | BASIC_EXAMPLE_MD = """Do **something**.
|
14 | 18 |
|
15 |
| -# Args |
| 19 | +Some more detailed description. |
| 20 | +
|
| 21 | +#### Args |
16 | 22 |
|
17 |
| -- a: some arg |
18 |
| -- b: some arg |
| 23 | +- `a`: some arg |
| 24 | +- `b`: some arg |
19 | 25 |
|
20 |
| -# Returns |
| 26 | +#### Returns |
21 | 27 |
|
22 | 28 | - Same *stuff*
|
23 | 29 | """
|
24 | 30 |
|
| 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 | + |
25 | 109 |
|
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) |
28 | 117 |
|
29 | 118 |
|
30 | 119 | def test_looks_like_google_ignores_plain_text():
|
31 | 120 | assert not looks_like_google("This is plain text")
|
32 | 121 | assert not looks_like_google("See Also\n--------\n")
|
33 | 122 |
|
34 | 123 |
|
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