Skip to content

Commit bf9e7b7

Browse files
committed
adds tests
1 parent 4e19811 commit bf9e7b7

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

clients/python/test/tests_docs.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
import sys
3+
import re
4+
from pathlib import Path
5+
6+
_CURRENT_DIR = (
7+
Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
8+
)
9+
_REPO_DIR = _CURRENT_DIR.parent.parent.parent
10+
_DOCS_DIR = _REPO_DIR / "docs"
11+
12+
assert _DOCS_DIR.exists
13+
14+
_MD_LINK_PATTERN = re.compile(r"\[(.*?)\]\((.*?)\)")
15+
16+
17+
def _collect_links():
18+
def _extract_file_links(markdown_file: Path) -> tuple[Path, str, str]:
19+
content = markdown_file.read_text()
20+
# Find all markdown links (e.g., [text](path/to/file))
21+
links = _MD_LINK_PATTERN.findall(content)
22+
return [(markdown_file, text, file_link) for text, file_link in links]
23+
24+
links = []
25+
for md_file in _DOCS_DIR.rglob("*.md"):
26+
links.extend(_extract_file_links(md_file))
27+
return links
28+
29+
30+
@pytest.mark.parametrize("md_file, link_text, file_link", _collect_links())
31+
def test_markdown_links(md_file: Path, link_text: str, file_link: str):
32+
if file_link.startswith("http"):
33+
pytest.skip(f"External link skipped: {file_link}")
34+
35+
relative_to_md = (md_file.parent / file_link).resolve()
36+
relative_to_repo = (_REPO_DIR / file_link).resolve()
37+
38+
assert (
39+
relative_to_md.exists() or relative_to_repo.exists()
40+
), f"Broken link found: [{link_text}]({file_link}) in {md_file}"

docs/doc_entrypoint.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ For more in-depth usage, refer to the following tutorial guides:
7979
- [Version 0.6 Documentation](clients/python/docs/v0.6.0/README.md)
8080

8181

82-
## Contributing
83-
84-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to get involved.
85-
8682
## License
8783

8884
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.

0 commit comments

Comments
 (0)