8Validate the ``oct docs --clean`` pipeline (run_docs_clean).
12- Confirm generated directories (html, doctrees, _api, doxygen_output) are removed.
13- Confirm generated files (index.rst, dependencies.rst) are removed.
14- Confirm preserved files (_sphinx/conf.py, _static/, user-authored .md) survive.
15- Confirm dry-run mode does not delete anything.
16- Confirm running on a project with no docs/ is a no-op.
27Inputs: tmp_path pytest fixture
28Outputs: pass/fail assertions
31from pathlib
import Path
38 """Create a realistic docs/ directory with generated and user-authored files."""
39 root = tmp_path /
"project"
43 (docs /
"html").mkdir(parents=
True)
44 (docs /
"html" /
"index.html").write_text(
"<html/>", encoding=
"utf-8")
45 (docs /
"doctrees").mkdir()
46 (docs /
"doctrees" /
"index.doctree").write_bytes(b
"\x00")
47 (docs /
"_api").mkdir()
48 (docs /
"_api" /
"modules.rst").write_text(
"API\n", encoding=
"utf-8")
49 (docs /
"doxygen_output" /
"html").mkdir(parents=
True)
50 (docs /
"doxygen_output" /
"html" /
"index.html").write_text(
"<html/>", encoding=
"utf-8")
53 (docs /
"index.rst").write_text(
".. toctree::\n", encoding=
"utf-8")
54 (docs /
"dependencies.rst").write_text(
"deps\n", encoding=
"utf-8")
57 (docs /
"ARCHITECTURE.md").write_text(
"# Arch\n", encoding=
"utf-8")
58 (docs /
"ROADMAP.md").write_text(
"# Roadmap\n", encoding=
"utf-8")
61 (docs /
"_sphinx").mkdir()
62 (docs /
"_sphinx" /
"conf.py").write_text(
"# conf\n", encoding=
"utf-8")
65 (docs /
"_static").mkdir()
66 (docs /
"_static" /
"custom.css").write_text(
"body {}\n", encoding=
"utf-8")
69 (docs /
"doxygen_work_dir").mkdir()
70 (docs /
"doxygen_work_dir" /
"Doxyfile").write_text(
"INPUT =\n", encoding=
"utf-8")
76 """Generated directories (html, doctrees, _api, doxygen_output) are removed."""
77 rc = run_docs_clean(docs_tree)
79 docs = docs_tree /
"docs"
80 assert not (docs /
"html").exists()
81 assert not (docs /
"doctrees").exists()
82 assert not (docs /
"_api").exists()
83 assert not (docs /
"doxygen_output").exists()
87 """Generated files (index.rst, dependencies.rst) are removed."""
88 rc = run_docs_clean(docs_tree)
90 docs = docs_tree /
"docs"
91 assert not (docs /
"index.rst").exists()
92 assert not (docs /
"dependencies.rst").exists()
96 """User-authored markdown files survive clean."""
97 run_docs_clean(docs_tree)
98 docs = docs_tree /
"docs"
99 assert (docs /
"ARCHITECTURE.md").exists()
100 assert (docs /
"ROADMAP.md").exists()
104 """Sphinx config directory (_sphinx/) survives clean."""
105 run_docs_clean(docs_tree)
106 assert (docs_tree /
"docs" /
"_sphinx" /
"conf.py").exists()
110 """Static assets directory (_static/) survives clean."""
111 run_docs_clean(docs_tree)
112 assert (docs_tree /
"docs" /
"_static" /
"custom.css").exists()
116 """Doxyfile in doxygen_work_dir/ survives clean."""
117 run_docs_clean(docs_tree)
118 assert (docs_tree /
"docs" /
"doxygen_work_dir" /
"Doxyfile").exists()
122 """Dry-run mode reports but does not delete anything."""
123 rc = run_docs_clean(docs_tree, dry_run=
True)
125 docs = docs_tree /
"docs"
127 assert (docs /
"html").exists()
128 assert (docs /
"doctrees").exists()
129 assert (docs /
"_api").exists()
130 assert (docs /
"doxygen_output").exists()
131 assert (docs /
"index.rst").exists()
132 assert (docs /
"dependencies.rst").exists()
136 """No docs/ directory — clean is a no-op."""
137 root = tmp_path /
"empty-project"
139 rc = run_docs_clean(root)
144 """Running clean twice is idempotent."""
145 run_docs_clean(docs_tree)
146 rc = run_docs_clean(docs_tree)
test_clean_preserves_user_content(Path docs_tree)
test_dry_run_preserves_everything(Path docs_tree)
test_clean_preserves_sphinx_config(Path docs_tree)
test_already_clean(Path docs_tree)
test_clean_preserves_static(Path docs_tree)
Path docs_tree(Path tmp_path)
test_clean_preserves_doxyfile(Path docs_tree)
test_clean_removes_generated_files(Path docs_tree)
test_clean_removes_generated_dirs(Path docs_tree)
test_no_docs_dir(Path tmp_path)