mktestdocs 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/PKG-INFO +3 -2
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/README.md +1 -1
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs/__init__.py +1 -1
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs/__main__.py +8 -3
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs.egg-info/PKG-INFO +3 -2
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs.egg-info/SOURCES.txt +1 -0
- mktestdocs-0.2.3/tests/test_actual_docstrings.py +74 -0
- mktestdocs-0.2.3/tests/test_format_docstring.py +61 -0
- mktestdocs-0.2.1/tests/test_actual_docstrings.py +0 -60
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/LICENSE +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs.egg-info/dependency_links.txt +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs.egg-info/requires.txt +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/mktestdocs.egg-info/top_level.txt +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/setup.cfg +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/setup.py +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/tests/test_class.py +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/tests/test_codeblock.py +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/tests/test_markdown.py +0 -0
- {mktestdocs-0.2.1 → mktestdocs-0.2.3}/tests/test_mktestdocs.py +0 -0
@@ -3,7 +3,6 @@ import pathlib
|
|
3
3
|
import subprocess
|
4
4
|
import textwrap
|
5
5
|
|
6
|
-
|
7
6
|
_executors = {}
|
8
7
|
|
9
8
|
|
@@ -90,20 +89,26 @@ def grab_code_blocks(docstring, lang="python"):
|
|
90
89
|
docstring: the docstring to analyse
|
91
90
|
lang: if not None, the language that is assigned to the codeblock
|
92
91
|
"""
|
92
|
+
docstring = format_docstring(docstring)
|
93
93
|
docstring = textwrap.dedent(docstring)
|
94
94
|
in_block = False
|
95
95
|
block = ""
|
96
96
|
codeblocks = []
|
97
97
|
for idx, line in enumerate(docstring.split("\n")):
|
98
|
-
if
|
98
|
+
if "```" in line:
|
99
99
|
if in_block:
|
100
100
|
codeblocks.append(check_codeblock(block, lang=lang))
|
101
101
|
block = ""
|
102
102
|
in_block = not in_block
|
103
103
|
if in_block:
|
104
104
|
block += line + "\n"
|
105
|
-
return [c for c in codeblocks if c != ""]
|
105
|
+
return [textwrap.dedent(c) for c in codeblocks if c != ""]
|
106
106
|
|
107
|
+
def format_docstring(docstring):
|
108
|
+
"""Formats docstring to be able to successfully go through dedent."""
|
109
|
+
if docstring[:1] != "\n":
|
110
|
+
return f"\n {docstring}"
|
111
|
+
return docstring
|
107
112
|
|
108
113
|
def check_docstring(obj, lang=""):
|
109
114
|
"""
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import pytest
|
2
|
+
from mktestdocs import check_docstring
|
3
|
+
|
4
|
+
|
5
|
+
def foobar_good(a, b):
|
6
|
+
"""
|
7
|
+
Returns a + b.
|
8
|
+
|
9
|
+
Examples:
|
10
|
+
|
11
|
+
```python
|
12
|
+
import random
|
13
|
+
|
14
|
+
random.random()
|
15
|
+
assert 'a' + 'b' == 'ab'
|
16
|
+
assert 1 + 2 == 3
|
17
|
+
```
|
18
|
+
"""
|
19
|
+
pass
|
20
|
+
|
21
|
+
|
22
|
+
def foobar_also_good(a, b):
|
23
|
+
"""
|
24
|
+
```python
|
25
|
+
import random
|
26
|
+
|
27
|
+
assert random.random() < 10
|
28
|
+
```
|
29
|
+
"""
|
30
|
+
pass
|
31
|
+
|
32
|
+
|
33
|
+
def foobar_bad(a, b):
|
34
|
+
"""
|
35
|
+
```python
|
36
|
+
assert foobar(1, 2) == 4
|
37
|
+
```
|
38
|
+
"""
|
39
|
+
pass
|
40
|
+
|
41
|
+
|
42
|
+
def admonition_edge_cases():
|
43
|
+
"""
|
44
|
+
!!! note
|
45
|
+
|
46
|
+
All cells of a table are initialized with an empty string. Therefore, to delete the content of a cell,
|
47
|
+
you need to assign an empty string, i.e. `''`. For instance, to delete the first row after the header:
|
48
|
+
|
49
|
+
```python
|
50
|
+
assert 1 + 2 == 3
|
51
|
+
```"""
|
52
|
+
pass
|
53
|
+
|
54
|
+
def adminition_edge_case_bad():
|
55
|
+
"""Test that we can handle the edge cases of admonitions."""
|
56
|
+
example = """!!! note
|
57
|
+
|
58
|
+
Another one.
|
59
|
+
```python
|
60
|
+
assert 1 + 2 == 4
|
61
|
+
```"""
|
62
|
+
pass
|
63
|
+
|
64
|
+
@pytest.mark.parametrize("func", [foobar_good, foobar_also_good, admonition_edge_cases])
|
65
|
+
def test_base_docstrings(func):
|
66
|
+
check_docstring(func)
|
67
|
+
|
68
|
+
|
69
|
+
@pytest.mark.parametrize("func", [foobar_bad, adminition_edge_case_bad])
|
70
|
+
def test_base_docstrings_bad(func, capsys):
|
71
|
+
with pytest.raises(Exception):
|
72
|
+
check_docstring(func)
|
73
|
+
capsys.readouterr()
|
74
|
+
assert func.__name__ in capsys.readouterr().out
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import pytest
|
2
|
+
|
3
|
+
from mktestdocs import get_codeblock_members
|
4
|
+
from mktestdocs.__main__ import format_docstring
|
5
|
+
|
6
|
+
|
7
|
+
def test_docstring_formatted():
|
8
|
+
# given (a docstring not prepared for dedent)
|
9
|
+
docstring = "Some class with a header and a code block"
|
10
|
+
# when (we go through the format_docstring function)
|
11
|
+
formatted = format_docstring(docstring)
|
12
|
+
# then (a new line and tab are added to the docstring)
|
13
|
+
assert formatted == "\n Some class with a header and a code block"
|
14
|
+
|
15
|
+
def test_docstring_not_formatted():
|
16
|
+
# given (a docstring prepared for dedent)
|
17
|
+
docstring = "\n Some class with a header and a code block"
|
18
|
+
# when (we go through the format_docstring function)
|
19
|
+
formatted = format_docstring(docstring)
|
20
|
+
# then (the docstring doesn't change)
|
21
|
+
assert formatted == docstring
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# The docstring of the first class starts like
|
26
|
+
# """Some class ...
|
27
|
+
# The docstring of the second class starts like
|
28
|
+
# """
|
29
|
+
# Some class ...
|
30
|
+
# The tests are checking that regardless of how the class docstring starts we should always be able to read the tests
|
31
|
+
class BadClass:
|
32
|
+
"""Some class with a header and a code block.
|
33
|
+
|
34
|
+
```python
|
35
|
+
assert False, "this should fail."
|
36
|
+
```
|
37
|
+
|
38
|
+
"""
|
39
|
+
def __init__(self):
|
40
|
+
pass
|
41
|
+
|
42
|
+
class BadClassNewLine:
|
43
|
+
"""
|
44
|
+
Some class with a header and a code block.
|
45
|
+
|
46
|
+
```python
|
47
|
+
assert False, "this should fail."
|
48
|
+
```
|
49
|
+
|
50
|
+
"""
|
51
|
+
def __init__(self):
|
52
|
+
pass
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
@pytest.mark.parametrize("cls", [BadClass, BadClassNewLine], ids=lambda d: d.__qualname__)
|
57
|
+
def test_grab_bad_methods(cls):
|
58
|
+
bad_members = get_codeblock_members(cls)
|
59
|
+
assert len(bad_members) == 1
|
60
|
+
|
61
|
+
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import pytest
|
2
|
-
from mktestdocs import check_docstring
|
3
|
-
|
4
|
-
|
5
|
-
def foobar_good(a, b):
|
6
|
-
"""
|
7
|
-
Returns a + b.
|
8
|
-
|
9
|
-
Examples:
|
10
|
-
|
11
|
-
```python
|
12
|
-
import random
|
13
|
-
|
14
|
-
random.random()
|
15
|
-
assert 'a' + 'b' == 'ab'
|
16
|
-
assert 1 + 2 == 3
|
17
|
-
```
|
18
|
-
"""
|
19
|
-
return a + b
|
20
|
-
|
21
|
-
|
22
|
-
def foobar_also_good(a, b):
|
23
|
-
"""
|
24
|
-
Returns a + b.
|
25
|
-
|
26
|
-
Examples:
|
27
|
-
|
28
|
-
```python
|
29
|
-
import random
|
30
|
-
|
31
|
-
assert random.random() < 10
|
32
|
-
```
|
33
|
-
"""
|
34
|
-
return a + b
|
35
|
-
|
36
|
-
|
37
|
-
def foobar_bad(a, b):
|
38
|
-
"""
|
39
|
-
Returns a + b.
|
40
|
-
|
41
|
-
Examples:
|
42
|
-
|
43
|
-
```python
|
44
|
-
assert foobar(1, 2) == 4
|
45
|
-
```
|
46
|
-
"""
|
47
|
-
return a + b
|
48
|
-
|
49
|
-
|
50
|
-
@pytest.mark.parametrize("func", [foobar_good, foobar_also_good])
|
51
|
-
def test_base_docstrings(func):
|
52
|
-
check_docstring(func)
|
53
|
-
|
54
|
-
|
55
|
-
@pytest.mark.parametrize("func", [foobar_bad])
|
56
|
-
def test_base_docstrings_bad(func, capsys):
|
57
|
-
with pytest.raises(Exception):
|
58
|
-
check_docstring(func)
|
59
|
-
capsys.readouterr()
|
60
|
-
assert func.__name__ in capsys.readouterr().out
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|