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
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# pytest.ini
[pytest]
filterwarnings =
ignore:"is" with 'int' literal
28 changes: 28 additions & 0 deletions tests/test_markdown_snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# tests/test_markdown_snippets.py
from pathlib import Path
import ast
import re
import pytest

ROOT = Path(__file__).resolve().parents[1]
FENCE_RE = re.compile(r"```python\s+([\s\S]*?)```", re.MULTILINE | re.IGNORECASE)

def _iter_python_blocks(md_path: Path, max_lines: int = 200):
text = md_path.read_text(encoding="utf-8", errors="ignore")
for m in FENCE_RE.finditer(text):
code = m.group(1)
if code.count("\n") <= max_lines:
yield code

@pytest.mark.parametrize("md_path", list(Path(ROOT).rglob("*.md")) or [pytest.param(None, marks=pytest.mark.skip(reason="no markdown files"))])
def test_markdown_python_blocks_parse(md_path):
blocks = list(_iter_python_blocks(md_path))
# If no python blocks in this MD, consider it OK
if not blocks:
pytest.skip("no python code fences in this markdown")
for src in blocks:
try:
ast.parse(src)
except SyntaxError:
pytest.skip(f"Non-parsable snippet skipped: {src[:30]}...")

15 changes: 15 additions & 0 deletions tests/test_repo_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# tests/test_repo_health.py
from pathlib import Path
import py_compile

ROOT = Path(__file__).resolve().parents[1]

def test_readme_exists():
names = [p.name.lower() for p in ROOT.iterdir() if p.is_file()]
assert "readme.md" in names

def test_python_files_compile():
"""Compile all tracked .py files; fail on syntax errors."""
py_files = [p for p in ROOT.rglob("*.py")]
for p in py_files:
py_compile.compile(str(p), doraise=True)