Option C Tools
Loading...
Searching...
No Matches
test_docs_clean.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_docs/test_docs_clean.py
4
5"""
6Purpose
7-------
8Validate the ``oct docs --clean`` pipeline (run_docs_clean).
9
10Responsibilities
11----------------
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.
17
18Diagnostics
19-----------
20Domain: DOCS-TESTS
21L2: test lifecycle
22L3: assertion details
23L4: deep tracing
24
25Contracts
26---------
27Inputs: tmp_path pytest fixture
28Outputs: pass/fail assertions
29"""
30
31from pathlib import Path
32import pytest
33from oct.docs.oct_docs import run_docs_clean
34
35
36@pytest.fixture
37def docs_tree(tmp_path: Path) -> Path:
38 """Create a realistic docs/ directory with generated and user-authored files."""
39 root = tmp_path / "project"
40 docs = root / "docs"
41
42 # Generated directories
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")
51
52 # Generated files
53 (docs / "index.rst").write_text(".. toctree::\n", encoding="utf-8")
54 (docs / "dependencies.rst").write_text("deps\n", encoding="utf-8")
55
56 # Preserved: user-authored content
57 (docs / "ARCHITECTURE.md").write_text("# Arch\n", encoding="utf-8")
58 (docs / "ROADMAP.md").write_text("# Roadmap\n", encoding="utf-8")
59
60 # Preserved: Sphinx config
61 (docs / "_sphinx").mkdir()
62 (docs / "_sphinx" / "conf.py").write_text("# conf\n", encoding="utf-8")
63
64 # Preserved: static assets
65 (docs / "_static").mkdir()
66 (docs / "_static" / "custom.css").write_text("body {}\n", encoding="utf-8")
67
68 # Preserved: Doxyfile
69 (docs / "doxygen_work_dir").mkdir()
70 (docs / "doxygen_work_dir" / "Doxyfile").write_text("INPUT =\n", encoding="utf-8")
71
72 return root
73
74
76 """Generated directories (html, doctrees, _api, doxygen_output) are removed."""
77 rc = run_docs_clean(docs_tree)
78 assert rc == 0
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()
84
85
87 """Generated files (index.rst, dependencies.rst) are removed."""
88 rc = run_docs_clean(docs_tree)
89 assert rc == 0
90 docs = docs_tree / "docs"
91 assert not (docs / "index.rst").exists()
92 assert not (docs / "dependencies.rst").exists()
93
94
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()
101
102
104 """Sphinx config directory (_sphinx/) survives clean."""
105 run_docs_clean(docs_tree)
106 assert (docs_tree / "docs" / "_sphinx" / "conf.py").exists()
107
108
109def test_clean_preserves_static(docs_tree: Path):
110 """Static assets directory (_static/) survives clean."""
111 run_docs_clean(docs_tree)
112 assert (docs_tree / "docs" / "_static" / "custom.css").exists()
113
114
115def test_clean_preserves_doxyfile(docs_tree: Path):
116 """Doxyfile in doxygen_work_dir/ survives clean."""
117 run_docs_clean(docs_tree)
118 assert (docs_tree / "docs" / "doxygen_work_dir" / "Doxyfile").exists()
119
120
122 """Dry-run mode reports but does not delete anything."""
123 rc = run_docs_clean(docs_tree, dry_run=True)
124 assert rc == 0
125 docs = docs_tree / "docs"
126 # Everything should still exist
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()
133
134
135def test_no_docs_dir(tmp_path: Path):
136 """No docs/ directory — clean is a no-op."""
137 root = tmp_path / "empty-project"
138 root.mkdir()
139 rc = run_docs_clean(root)
140 assert rc == 0
141
142
143def test_already_clean(docs_tree: Path):
144 """Running clean twice is idempotent."""
145 run_docs_clean(docs_tree)
146 rc = run_docs_clean(docs_tree)
147 assert rc == 0
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)