forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lesson_lint.py
More file actions
57 lines (46 loc) 路 2.09 KB
/
Copy pathtest_lesson_lint.py
File metadata and controls
57 lines (46 loc) 路 2.09 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
"""Regression tests for the repository-wide lesson lint contract."""
import tempfile
import unittest
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from scripts.lesson_lint import (
check_frontmatter_fields,
check_links,
check_title,
is_lesson_file,
)
class TestLessonLint(unittest.TestCase):
def test_metadata_title_is_a_valid_lesson_title(self):
content = (
'---\n{"title": "Metadata title", "domain": "devops", '
'"status": "published"}\n---\n\n## Body\n'
)
self.assertEqual(check_title(content, Path("lesson.md")), [])
def test_required_frontmatter_fields_are_reported(self):
content = '---\n{"status": "published"}\n---\n\nBody\n'
rules = [item["rule"] for item in check_frontmatter_fields(content, Path("lesson.md"))]
self.assertEqual(rules, ["missing_frontmatter_field", "missing_frontmatter_field"])
def test_readme_is_not_classified_as_a_lesson(self):
lessons_dir = Path("lessons")
self.assertFalse(is_lesson_file(lessons_dir / "core" / "README.md", lessons_dir))
def test_code_examples_do_not_create_broken_links(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
lesson = root / "lesson.md"
lesson.write_text(
"Before: `[](link-url)`\n"
"```markdown\n[example](placeholder.md)\n```\n",
encoding="utf-8",
)
self.assertEqual(check_links(lesson.read_text(encoding="utf-8"), lesson, root), [])
def test_rendered_relative_link_must_exist(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
lesson = root / "lesson.md"
lesson.write_text("[missing](missing.md)\n", encoding="utf-8")
issues = check_links(lesson.read_text(encoding="utf-8"), lesson, root)
self.assertEqual(len(issues), 1)
self.assertEqual(issues[0]["rule"], "broken_link")
if __name__ == "__main__":
unittest.main()