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
35 changes: 35 additions & 0 deletions .github/workflows/test_docs_sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Documentation sanity check

on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

jobs:
run-docs-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install build dependencies (pyproject.toml)
run: |
python -m pip install --upgrade pip
pip install setuptools

- name: Install project and runtime dependencies
run: |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install pytest

- name: Run pytest
run: pytest tests/test_docs.py --maxfail=1 --disable-warnings
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ EXPOSE 8080

CMD ["mkdocs", "serve", "--dev-addr=0.0.0.0:8080"]

# docker build -t cwapi3d-py .
# docker build -t cwapi3d-py .
# docker run --rm -p 8080:8080 cwapi3d-py
Binary file modified requirements.in
Binary file not shown.
1 change: 1 addition & 0 deletions tests/__internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cw_python_analyser import CwPythonAnalyser
576 changes: 576 additions & 0 deletions tests/__internal/cw_python_analyser.py

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
import pathlib
from __internal.cw_python_analyser import CwPythonAnalyser

EXAMPLES_DIR = pathlib.Path(__file__).parent.parent / "docs" / "examples"
STUBS_ROOT = pathlib.Path(__file__).parent.parent / "src"

def get_all_md_files():
return list(EXAMPLES_DIR.glob("*.md"))

@pytest.mark.parametrize("md_file", get_all_md_files(), ids=lambda f: f.name)
def test_pyAPI_signatures_blocks(md_file):
content = md_file.read_text(encoding="utf-8")
raw_blocks = CwPythonAnalyser.extract_markdown_py_code_blocks(content)
py_code_blocks = [block["code"] for block in raw_blocks if block["language"] == "python"]

for py_block in py_code_blocks:
extracted_symbols = CwPythonAnalyser.extract_py_dotted_symbols_from_code(py_block)
matched_signatures, uncertain_signatures = CwPythonAnalyser.match_symbols_to_api_signatures(
api_calls=extracted_symbols,
stubs_root=STUBS_ROOT
)
# Only fail if possible signatures are present for any uncertain signature
filtered = [
(symbol, possible)
for symbol, possible in uncertain_signatures
if possible # Only include if possible signatures are found
]
if filtered:
formatted = "\n".join(
f"Symbol: {symbol}\nPossible signatures: {', '.join(possible)}"
for symbol, possible in filtered
)
pytest.fail(f"In file {md_file.name}:\nUncertain signatures found:\n{formatted}")
8 changes: 8 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.