Coverage for tests/test_cli/test_doc.py: 100%
34 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1import subprocess 1abcdefgh
2import sys 1abcdefgh
3from pathlib import Path 1abcdefgh
6def test_doc(): 1abcdefgh
7 result = subprocess.run( 1abcdefgh
8 [
9 sys.executable,
10 "-m",
11 "coverage",
12 "run",
13 "-m",
14 "typer",
15 "tests.assets.cli.multi_app",
16 "utils",
17 "docs",
18 "--name",
19 "multiapp",
20 ],
21 capture_output=True,
22 encoding="utf-8",
23 )
24 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs.md" 1abcdefgh
25 docs = docs_path.read_text() 1abcdefgh
26 assert docs in result.stdout 1abcdefgh
27 assert "**Arguments**" in result.stdout 1abcdefgh
30def test_doc_output(tmp_path: Path): 1abcdefgh
31 out_file: Path = tmp_path / "out.md" 1abcdefgh
32 result = subprocess.run( 1abcdefgh
33 [
34 sys.executable,
35 "-m",
36 "coverage",
37 "run",
38 "-m",
39 "typer",
40 "tests.assets.cli.multi_app",
41 "utils",
42 "docs",
43 "--name",
44 "multiapp",
45 "--output",
46 str(out_file),
47 ],
48 capture_output=True,
49 encoding="utf-8",
50 )
51 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs.md" 1abcdefgh
52 docs = docs_path.read_text() 1abcdefgh
53 written_docs = out_file.read_text() 1abcdefgh
54 assert docs in written_docs 1abcdefgh
55 assert "Docs saved to:" in result.stdout 1abcdefgh
58def test_doc_title_output(tmp_path: Path): 1abcdefgh
59 out_file: Path = tmp_path / "out.md" 1abcdefgh
60 result = subprocess.run( 1abcdefgh
61 [
62 sys.executable,
63 "-m",
64 "coverage",
65 "run",
66 "-m",
67 "typer",
68 "tests.assets.cli.multi_app",
69 "utils",
70 "docs",
71 "--name",
72 "multiapp",
73 "--title",
74 "Awesome CLI",
75 "--output",
76 str(out_file),
77 ],
78 capture_output=True,
79 encoding="utf-8",
80 )
81 docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs-title.md" 1abcdefgh
82 docs = docs_path.read_text() 1abcdefgh
83 written_docs = out_file.read_text() 1abcdefgh
84 assert docs in written_docs 1abcdefgh
85 assert "Docs saved to:" in result.stdout 1abcdefgh
88def test_doc_not_existing(): 1abcdefgh
89 result = subprocess.run( 1abcdefgh
90 [
91 sys.executable,
92 "-m",
93 "coverage",
94 "run",
95 "-m",
96 "typer",
97 "no_typer",
98 "utils",
99 "docs",
100 ],
101 capture_output=True,
102 encoding="utf-8",
103 )
104 assert "Could not import as Python module:" in result.stderr 1abcdefgh
107def test_doc_no_typer(): 1abcdefgh
108 result = subprocess.run( 1abcdefgh
109 [
110 sys.executable,
111 "-m",
112 "coverage",
113 "run",
114 "-m",
115 "typer",
116 "tests/assets/cli/empty_script.py",
117 "utils",
118 "docs",
119 ],
120 capture_output=True,
121 encoding="utf-8",
122 )
123 assert "No Typer app found" in result.stderr 1abcdefgh
126def test_doc_file_not_existing(): 1abcdefgh
127 result = subprocess.run( 1abcdefgh
128 [
129 sys.executable,
130 "-m",
131 "coverage",
132 "run",
133 "-m",
134 "typer",
135 "assets/cli/not_existing.py",
136 "utils",
137 "docs",
138 ],
139 capture_output=True,
140 encoding="utf-8",
141 )
142 assert "Not a valid file or Python module:" in result.stderr 1abcdefgh