This repository has been archived by the owner on Apr 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
test_doc.py
98 lines (88 loc) · 2.36 KB
/
test_doc.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import subprocess
from pathlib import Path
def test_doc():
result = subprocess.run(
[
"coverage",
"run",
"-m",
"typer_cli",
"tests.assets.multi_app",
"utils",
"docs",
"--name",
"multiapp",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
docs_path: Path = Path(__file__).parent / "assets/multiapp-docs.md"
docs = docs_path.read_text()
assert docs in result.stdout
assert "**Arguments**" in result.stdout
def test_doc_output(tmp_path: Path):
out_file: Path = tmp_path / "out.md"
result = subprocess.run(
[
"coverage",
"run",
"-m",
"typer_cli",
"tests.assets.multi_app",
"utils",
"docs",
"--name",
"multiapp",
"--output",
str(out_file),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
docs_path: Path = Path(__file__).parent / "assets/multiapp-docs.md"
docs = docs_path.read_text()
written_docs = out_file.read_text()
assert docs in written_docs
assert "Docs saved to:" in result.stdout
def test_doc_not_existing():
result = subprocess.run(
["coverage", "run", "-m", "typer_cli", "no_typer", "utils", "docs"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Could not import as Python module:" in result.stderr
def test_doc_no_typer():
result = subprocess.run(
[
"coverage",
"run",
"-m",
"typer_cli",
"tests/assets/empty_script.py",
"utils",
"docs",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "No Typer app found" in result.stderr
def test_doc_file_not_existing():
result = subprocess.run(
[
"coverage",
"run",
"-m",
"typer_cli",
"assets/not_existing.py",
"utils",
"docs",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Not a valid file or Python module:" in result.stderr