-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_ai_coding_content.py
More file actions
60 lines (42 loc) · 1.96 KB
/
Copy pathtest_ai_coding_content.py
File metadata and controls
60 lines (42 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import annotations
import re
from pathlib import Path
import yaml
from tools.catalog import load_catalog
ROOT = Path(__file__).resolve().parents[1]
GUIDES = {
"en-US": ROOT / "guides" / "ai-coding" / "workflow.md",
"zh-CN": ROOT / "guides" / "ai-coding" / "workflow_cn.md",
}
def load_guide(path: Path) -> tuple[dict, str]:
content = path.read_text(encoding="utf-8")
assert content.startswith("---\n")
_, front_matter, body = content.split("---\n", maxsplit=2)
return yaml.safe_load(front_matter), body
def test_ai_coding_guides_have_matching_identity_and_version() -> None:
loaded = {lang: load_guide(path) for lang, path in GUIDES.items()}
english, _ = loaded["en-US"]
chinese, _ = loaded["zh-CN"]
assert english["id"] == chinese["id"] == "python-ai-coding-workflow"
assert english["content_version"] == chinese["content_version"] == 1
assert english["reviewed_on"] == chinese["reviewed_on"]
assert english["lang"] == "en-US"
assert chinese["lang"] == "zh-CN"
def test_ai_coding_guides_cover_the_same_eight_step_workflow() -> None:
for path in GUIDES.values():
_, body = load_guide(path)
headings = re.findall(r"^## ([1-8])\.", body, flags=re.MULTILINE)
assert headings == [str(number) for number in range(1, 9)]
def test_guide_reference_urls_come_from_reviewed_catalog() -> None:
catalog = load_catalog(ROOT / "catalog")
catalog_urls = {resource["url"] for resource in catalog["resources"]}
for path in GUIDES.values():
_, body = load_guide(path)
urls = set(re.findall(r"\]\((https://[^)]+)\)", body))
assert urls
assert urls <= catalog_urls
def test_readmes_link_to_the_matching_ai_coding_guide() -> None:
english = (ROOT / "README.md").read_text(encoding="utf-8")
chinese = (ROOT / "README_cn.md").read_text(encoding="utf-8")
assert "guides/ai-coding/workflow.md" in english
assert "guides/ai-coding/workflow_cn.md" in chinese