Skip to content

Commit

Permalink
Merge pull request #13 from cospectrum/dev
Browse files Browse the repository at this point in the history
skip readme tests instead of fail
  • Loading branch information
cospectrum authored Jan 11, 2025
2 parents 00fad36 + b6fbdc2 commit 22c9984
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit 22c9984

Please sign in to comment.