Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions mktestdocs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def grab_code_blocks(docstring, lang="python"):
block = ""
codeblocks = []
for idx, line in enumerate(docstring.split("\n")):
if line.startswith("```"):
if "```" in line:
if in_block:
codeblocks.append(check_codeblock(block, lang=lang))
block = ""
in_block = not in_block
if in_block:
block += line + "\n"
return [c for c in codeblocks if c != ""]
return [textwrap.dedent(c) for c in codeblocks if c != ""]

def format_docstring(docstring):
"""Formats docstring to be able to successfully go through dedent."""
Expand Down
40 changes: 27 additions & 13 deletions tests/test_actual_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,57 @@ def foobar_good(a, b):
assert 1 + 2 == 3
```
"""
return a + b
pass


def foobar_also_good(a, b):
"""
Returns a + b.

Examples:

```python
import random

assert random.random() < 10
```
"""
return a + b
pass


def foobar_bad(a, b):
"""
Returns a + b.

Examples:

```python
assert foobar(1, 2) == 4
```
"""
return a + b
pass


@pytest.mark.parametrize("func", [foobar_good, foobar_also_good])
def admonition_edge_cases():
"""
!!! note

All cells of a table are initialized with an empty string. Therefore, to delete the content of a cell,
you need to assign an empty string, i.e. `''`. For instance, to delete the first row after the header:

```python
assert 1 + 2 == 3
```"""
pass

def adminition_edge_case_bad():
"""Test that we can handle the edge cases of admonitions."""
example = """!!! note

Another one.
```python
assert 1 + 2 == 4
```"""
pass

@pytest.mark.parametrize("func", [foobar_good, foobar_also_good, admonition_edge_cases])
def test_base_docstrings(func):
check_docstring(func)


@pytest.mark.parametrize("func", [foobar_bad])
@pytest.mark.parametrize("func", [foobar_bad, adminition_edge_case_bad])
def test_base_docstrings_bad(func, capsys):
with pytest.raises(Exception):
check_docstring(func)
Expand Down