Coverage for tests/test_cli/test_doc.py: 100%
43 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-10 00:15 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-10 00:15 +0000
1import os 1iabcdefgh
2import subprocess 1iabcdefgh
3import sys 1iabcdefgh
4from pathlib import Path 1iabcdefgh
7def test_doc(): 1iabcdefgh
8 result = subprocess.run( 1iabcdefgh
9 [
10 sys.executable,
11 "-m",
12 "coverage",
13 "run",
14 "-m",
15 "typer",
16 "tests.assets.cli.multi_app",
17 "utils",
18 "docs",
19 "--name",
20 "multiapp",
21 ],
22 capture_output=True,
23 encoding="utf-8",
24 )
25 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs.md" 1iabcdefgh
26 docs = docs_path.read_text() 1iabcdefgh
27 assert docs in result.stdout 1iabcdefgh
28 assert "**Arguments**" in result.stdout 1iabcdefgh
31def test_doc_output(tmp_path: Path): 1iabcdefgh
32 out_file: Path = tmp_path / "out.md" 1iabcdefgh
33 result = subprocess.run( 1iabcdefgh
34 [
35 sys.executable,
36 "-m",
37 "coverage",
38 "run",
39 "-m",
40 "typer",
41 "tests.assets.cli.multi_app",
42 "utils",
43 "docs",
44 "--name",
45 "multiapp",
46 "--output",
47 str(out_file),
48 ],
49 capture_output=True,
50 encoding="utf-8",
51 )
52 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs.md" 1iabcdefgh
53 docs = docs_path.read_text() 1iabcdefgh
54 written_docs = out_file.read_text() 1iabcdefgh
55 assert docs in written_docs 1iabcdefgh
56 assert "Docs saved to:" in result.stdout 1iabcdefgh
59def test_doc_title_output(tmp_path: Path): 1iabcdefgh
60 out_file: Path = tmp_path / "out.md" 1iabcdefgh
61 result = subprocess.run( 1iabcdefgh
62 [
63 sys.executable,
64 "-m",
65 "coverage",
66 "run",
67 "-m",
68 "typer",
69 "tests.assets.cli.multi_app",
70 "utils",
71 "docs",
72 "--name",
73 "multiapp",
74 "--title",
75 "Awesome CLI",
76 "--output",
77 str(out_file),
78 ],
79 capture_output=True,
80 encoding="utf-8",
81 )
82 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs-title.md" 1iabcdefgh
83 docs = docs_path.read_text() 1iabcdefgh
84 written_docs = out_file.read_text() 1iabcdefgh
85 assert docs in written_docs 1iabcdefgh
86 assert "Docs saved to:" in result.stdout 1iabcdefgh
89def test_doc_not_existing(): 1iabcdefgh
90 result = subprocess.run( 1iabcdefgh
91 [
92 sys.executable,
93 "-m",
94 "coverage",
95 "run",
96 "-m",
97 "typer",
98 "no_typer",
99 "utils",
100 "docs",
101 ],
102 capture_output=True,
103 encoding="utf-8",
104 )
105 assert "Could not import as Python module:" in result.stderr 1iabcdefgh
108def test_doc_no_typer(): 1iabcdefgh
109 result = subprocess.run( 1iabcdefgh
110 [
111 sys.executable,
112 "-m",
113 "coverage",
114 "run",
115 "-m",
116 "typer",
117 "tests/assets/cli/empty_script.py",
118 "utils",
119 "docs",
120 ],
121 capture_output=True,
122 encoding="utf-8",
123 )
124 assert "No Typer app found" in result.stderr 1iabcdefgh
127def test_doc_file_not_existing(): 1iabcdefgh
128 result = subprocess.run( 1iabcdefgh
129 [
130 sys.executable,
131 "-m",
132 "coverage",
133 "run",
134 "-m",
135 "typer",
136 "assets/cli/not_existing.py",
137 "utils",
138 "docs",
139 ],
140 capture_output=True,
141 encoding="utf-8",
142 )
143 assert "Not a valid file or Python module:" in result.stderr 1iabcdefgh
146def test_doc_html_output(tmp_path: Path): 1iabcdefgh
147 out_file: Path = tmp_path / "out.md" 1iabcdefgh
148 result = subprocess.run( 1iabcdefgh
149 [
150 sys.executable,
151 "-m",
152 "coverage",
153 "run",
154 "-m",
155 "typer",
156 "tests.assets.cli.rich_formatted_app",
157 "utils",
158 "docs",
159 "--title",
160 "Awesome CLI",
161 "--output",
162 str(out_file),
163 ],
164 capture_output=True,
165 encoding="utf-8",
166 env={**os.environ, "PYTHONIOENCODING": "utf-8"},
167 )
168 docs_path: Path = ( 1abcdefgh
169 Path(__file__).parent.parent / "assets" / "cli" / "richformattedapp-docs.md"
170 )
171 docs = docs_path.read_text(encoding="utf-8") 1iabcdefgh
172 written_docs = out_file.read_text(encoding="utf-8") 1iabcdefgh
173 assert docs in written_docs 1iabcdefgh
174 assert "Docs saved to:" in result.stdout 1iabcdefgh