Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
run: |
python -m pytest -k test_basic
python -m pytest -k test_zarr
python -m pytest -k test_docs

dcam:
name: Python ${{ matrix.python }} (DCAM)
Expand Down
42 changes: 42 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import atexit
from pathlib import Path
import shutil
import subprocess
import re
import logging
import tempfile
import pytest


logging.getLogger("acquire").setLevel(logging.CRITICAL)

DOCS_REPO = "https://github.com/acquire-project/acquire-docs"
CODE_BLOCK = re.compile(r"```python\n(.*?)```", re.DOTALL)
SKIP = {
"setup.md", # has invalid syntax
"trigger.md", # has some non-existant paths
}


def tutorials():
tmp_path = Path(tempfile.mkdtemp())
subprocess.check_call(["git", "clone", DOCS_REPO], cwd=str(tmp_path))
docs_path = tmp_path / "acquire-docs" / "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()

@atexit.register
def cleanup():
shutil.rmtree(tmp_path, ignore_errors=True)

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))