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
8 changes: 5 additions & 3 deletions mktestdocs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def exec_python(source):
register_executor("python", exec_python)


def get_codeblock_members(*classes):
def get_codeblock_members(*classes, lang="python"):
"""
Grabs the docstrings of any methods of any classes that are passed in.
"""
Expand All @@ -61,7 +61,7 @@ def get_codeblock_members(*classes):
for name, member in inspect.getmembers(cl):
if member.__doc__:
results.append(member)
return [m for m in results if len(grab_code_blocks(m.__doc__)) > 0]
return [m for m in results if len(grab_code_blocks(m.__doc__, lang=lang)) > 0]


def check_codeblock(block, lang="python"):
Expand All @@ -76,7 +76,7 @@ def check_codeblock(block, lang="python"):
"""
first_line = block.split("\n")[0]
if lang:
if first_line[3:] != lang:
if first_line.lstrip()[3:] != lang:
return ""
return "\n".join(block.split("\n")[1:])

Expand Down Expand Up @@ -104,12 +104,14 @@ def grab_code_blocks(docstring, lang="python"):
block += line + "\n"
return [textwrap.dedent(c) for c in codeblocks if c != ""]


def format_docstring(docstring):
"""Formats docstring to be able to successfully go through dedent."""
if docstring[:1] != "\n":
return f"\n {docstring}"
return docstring


def check_docstring(obj, lang=""):
"""
Given a function, test the contents of the docstring.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,27 @@ def hello(self):
"""
return self.name

def hfdocs_style(self, value):
"""
Returns value

Example:

```python
from dinosaur import Dinosaur

dino = Dinosaur()
assert dino.a(1) == 1
```
"""
return value


members = get_codeblock_members(Dinosaur)


def test_grab_methods():
assert len(get_codeblock_members(Dinosaur)) == 4
assert len(get_codeblock_members(Dinosaur)) == 5


@pytest.mark.parametrize("obj", members, ids=lambda d: d.__qualname__)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_mktestdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from mktestdocs import check_md_file


def test_readme(monkeypatch):
test_dir = pathlib.Path(__file__).parent
fpath = test_dir.parent / "README.md"
monkeypatch.chdir(test_dir)

check_md_file(fpath=fpath)
check_md_file(fpath=fpath, memory=True)