-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks_test.py
More file actions
70 lines (59 loc) · 2.76 KB
/
Copy pathhooks_test.py
File metadata and controls
70 lines (59 loc) · 2.76 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
61
62
63
64
65
66
67
68
69
70
"""Tests for docs/hooks.py"""
from __future__ import annotations
import json
import tempfile
import unittest
from pathlib import Path
from hooks import on_post_build
class HooksTest(unittest.TestCase):
def test_noop_when_root_llms_exists(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
site = Path(tmp)
docs = site / "docs_src"
docs.mkdir()
(site / "llms.txt").write_text("# already\n", encoding="utf-8")
on_post_build({"site_dir": str(site), "docs_dir": str(docs)})
self.assertEqual((site / "llms.txt").read_text(encoding="utf-8"), "# already\n")
def test_copies_from_en_subdir(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
site = Path(tmp)
docs = site / "docs_src"
docs.mkdir()
(site / "en").mkdir()
(site / "en" / "llms.txt").write_text("# from en\n", encoding="utf-8")
on_post_build({"site_dir": str(site), "docs_dir": str(docs)})
self.assertEqual((site / "llms.txt").read_text(encoding="utf-8"), "# from en\n")
def test_copies_from_docs_dir(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
site = Path(tmp)
docs = Path(tmp) / "docs_src"
(docs / "en").mkdir(parents=True)
(docs / "en" / "llms.txt").write_text("# from docs\n", encoding="utf-8")
on_post_build({"site_dir": str(site), "docs_dir": str(docs)})
self.assertEqual((site / "llms.txt").read_text(encoding="utf-8"), "# from docs\n")
def test_noop_when_missing(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
site = Path(tmp)
docs = Path(tmp) / "docs_src"
docs.mkdir()
on_post_build({"site_dir": str(site), "docs_dir": str(docs)})
self.assertFalse((site / "llms.txt").exists())
def test_copies_schemas_from_monorepo_layout(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
# Mimic docs/docs as docs_dir → parent.parent/schemas
docs = root / "docs" / "docs"
docs.mkdir(parents=True)
site = root / "site"
site.mkdir()
schemas = root / "schemas"
schemas.mkdir()
(schemas / "catalog.json").write_text(
json.dumps({"operatorVersion": "1.9.0"}), encoding="utf-8"
)
(schemas / "dataflow.json").write_text("{}", encoding="utf-8")
on_post_build({"site_dir": str(site), "docs_dir": str(docs)})
self.assertTrue((site / "schemas" / "catalog.json").is_file())
self.assertTrue((site / "schemas" / "dataflow.json").is_file())
if __name__ == "__main__":
unittest.main()