Skip to content
Merged
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
23 changes: 15 additions & 8 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import pytest
import os
from pathlib import Path


Script = str


def test_readme() -> None:
readme_path = Path("./README.md")
scripts = parse_readme_code(readme_path, "```python\n", "```\n")
scripts += parse_readme_code(readme_path, "```py\n", "```\n")
assert len(scripts) > 0
@pytest.mark.parametrize(["path"], [("./README.md",)])
def test_readme(path: os.PathLike) -> None:
path = Path(path)
if not path.exists():
pytest.skip(reason=f"{path} doesn't exist")

text = path.read_text()
scripts = parse_md_scripts(text, "```python\n", "```\n")
scripts += parse_md_scripts(text, "```py\n", "```\n")
if len(scripts) == 0:
pytest.skip(reason=f"no scripts in {path}")

for script in scripts:
print("\n# executing the following script")
print(script)
print("\n# stdout...")
exec(script)


def parse_readme_code(path: Path, start_tag: str, end_tag) -> list[Script]:
assert path.exists()
text = path.read_text()
def parse_md_scripts(text: str, start_tag: str, end_tag) -> list[Script]:
_, *sections = text.split(start_tag)
scripts = []
for section in sections:
Expand Down
Loading