-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the code blocks in Markdown files (courtesy of @tlambert03
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Testing the Documentation | ||
|
||
To test the documentation, you will need to have several packages installed in your Python environment. | ||
You can install them with the following command: | ||
|
||
```bash | ||
python -m pip install -r requirements-test.txt | ||
``` | ||
|
||
(You can find the `requirements-test.txt` file in the folder containing this README file.) | ||
|
||
Then execute the tests with the following command: | ||
|
||
```bash | ||
python -m pytest | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
acquire-imaging | ||
napari[all] | ||
numpy | ||
ome-zarr | ||
pytest | ||
tifffile | ||
zarr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import atexit | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
import re | ||
import logging | ||
import tempfile | ||
import pytest | ||
|
||
|
||
logging.getLogger("acquire").setLevel(logging.CRITICAL) | ||
|
||
CODE_BLOCK = re.compile(r"```python\n(.*?)```", re.DOTALL) | ||
SKIP = { | ||
"setup.md", # has invalid syntax | ||
"trigger.md", # has some non-existant paths | ||
} | ||
|
||
|
||
def tutorials(): | ||
docs_path = Path(__file__).parent.parent / "docs" | ||
|
||
tuts = [] | ||
if (get_started := docs_path / "get_started.md").exists(): | ||
tuts.append(get_started) | ||
tuts.extend([fn for fn in docs_path.glob("tutorials/*.md") if fn.name not in SKIP]) | ||
tuts.sort() | ||
|
||
return tuts | ||
|
||
|
||
@pytest.mark.parametrize("tutorial", tutorials(), ids=lambda x: x.name) | ||
def test_tutorials(tutorial: Path): | ||
for code_block in CODE_BLOCK.finditer(tutorial.read_text()): | ||
exec(code_block.group(1)) |