Skip to content

Commit 99a1e74

Browse files
committed
test mktestdocs own README
1 parent 5af9433 commit 99a1e74

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Let's suppose that you have the following markdown file:
4141

4242
```python
4343
from operator import add
44-
a = 1
44+
a = 1
4545
b = 2
4646
```
4747

@@ -54,10 +54,20 @@ Let's suppose that you have the following markdown file:
5454
Then in this case the second code-block depends on the first code-block. The standard settings of `check_md_file` assume that each code-block needs to run independently. If you'd like to test markdown files with these sequential code-blocks be sure to set `memory=True`.
5555

5656
```python
57-
# Assume that cell-blocks are independent.
58-
check_md_file(fpath=fpath)
57+
import pathlib
58+
59+
from mktestdocs import check_md_file
60+
61+
fpath = pathlib.Path("docs") / "multiple-code-blocks.md"
5962

60-
# Assumes that cell-blocks depend on eachother.
63+
try:
64+
# Assume that cell-blocks are independent.
65+
check_md_file(fpath=fpath)
66+
except NameError:
67+
# But they weren't
68+
pass
69+
70+
# Assumes that cell-blocks depend on each other.
6171
check_md_file(fpath=fpath, memory=True)
6272
```
6373

@@ -88,7 +98,7 @@ from dinosaur import Dinosaur
8898
import pytest
8999
from mktestdocs import check_docstring, get_codeblock_members
90100

91-
# This retreives all methods/properties with a docstring.
101+
# This retrieves all methods/properties with a docstring.
92102
members = get_codeblock_members(Dinosaur)
93103

94104
# Note the use of `__qualname__`, makes for pretty output
@@ -128,13 +138,13 @@ import pytest
128138

129139
from mktestdocs import check_md_file
130140

131-
@pytest.mark.parametrize('fpath', pathlib.Path("docs").glob("**/*.md"), ids=str)
132-
def test_python_examples(fpath):
141+
fpath = pathlib.Path("docs") / "bash-support.md"
142+
143+
def test_python_examples():
133144
check_md_file(fpath=fpath, lang="python")
134145

135-
@pytest.mark.parametrize('fpath', pathlib.Path("docs").glob("**/*.md"), ids=str)
136-
def test_bash_examples(fpath):
137-
check_md_file(fpath=fpath), lang="bash")
146+
def test_bash_examples():
147+
check_md_file(fpath=fpath, lang="bash")
138148
```
139149

140150
## Additional Language Support
@@ -156,6 +166,8 @@ You could create a json validator that tested the example was always valid json
156166

157167
```python
158168
import json
169+
import pathlib
170+
159171
import pytest
160172

161173
from mktestdocs import check_md_file, register_executor
@@ -165,8 +177,7 @@ def parse_json(json_text):
165177

166178
register_executor("json", parse_json)
167179

168-
# Note the use of `str`, makes for pretty output
169-
@pytest.mark.parametrize('fpath', pathlib.Path("docs").glob("**/*.md"), ids=str)
170180
def test_files_good(fpath):
181+
fpath = pathlib.Path("docs") / "additional-language-support.md"
171182
check_md_file(fpath=fpath)
172183
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is an example REST response
2+
3+
```json
4+
{body: {results: [spam, eggs]}, errors: []}
5+
```

tests/docs/bash-support.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This will print the python version to the terminal
2+
3+
```bash
4+
python --version
5+
```
6+
7+
This will print the exact same version string
8+
9+
```python
10+
import sys
11+
12+
print(f"Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
13+
```

tests/docs/multiple-code-blocks.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This is a code block
2+
3+
```python
4+
from operator import add
5+
a = 1
6+
b = 2
7+
```
8+
9+
This code-block should run fine.
10+
11+
```python
12+
assert add(1, 2) == 3
13+
```

tests/docs/test.md

Whitespace-only changes.

tests/test_mktestdocs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pathlib
2+
3+
from mktestdocs import check_md_file
4+
5+
def test_readme(monkeypatch):
6+
test_dir = pathlib.Path(__file__).parent
7+
fpath = test_dir.parent / "README.md"
8+
monkeypatch.chdir(test_dir)
9+
10+
check_md_file(fpath=fpath)

0 commit comments

Comments
 (0)