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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
import os
import subprocess
import sys
from pathlib import Path
def test_doc():
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests.assets.cli.multi_app",
"utils",
"docs",
"--name",
"multiapp",
],
capture_output=True,
encoding="utf-8",
)
docs_path: Path = Path(__file__).parent.parent / "assets/cli/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(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests.assets.cli.multi_app",
"utils",
"docs",
"--name",
"multiapp",
"--output",
str(out_file),
],
capture_output=True,
encoding="utf-8",
)
docs_path: Path = Path(__file__).parent.parent / "assets/cli/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_title_output(tmp_path: Path):
out_file: Path = tmp_path / "out.md"
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests.assets.cli.multi_app",
"utils",
"docs",
"--name",
"multiapp",
"--title",
"Awesome CLI",
"--output",
str(out_file),
],
capture_output=True,
encoding="utf-8",
)
docs_path: Path = Path(__file__).parent.parent / "assets/cli/multiapp-docs-title.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(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"no_typer",
"utils",
"docs",
],
capture_output=True,
encoding="utf-8",
)
assert "Could not import as Python module:" in result.stderr
def test_doc_no_typer():
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests/assets/cli/empty_script.py",
"utils",
"docs",
],
capture_output=True,
encoding="utf-8",
)
assert "No Typer app found" in result.stderr
def test_doc_file_not_existing():
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"assets/cli/not_existing.py",
"utils",
"docs",
],
capture_output=True,
encoding="utf-8",
)
assert "Not a valid file or Python module:" in result.stderr
def test_doc_html_output(tmp_path: Path):
out_file: Path = tmp_path / "out.md"
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests.assets.cli.rich_formatted_app",
"utils",
"docs",
"--title",
"Awesome CLI",
"--output",
str(out_file),
],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
docs_path: Path = (
Path(__file__).parent.parent / "assets" / "cli" / "richformattedapp-docs.md"
)
docs = docs_path.read_text(encoding="utf-8")
written_docs = out_file.read_text(encoding="utf-8")
assert docs in written_docs
assert "Docs saved to:" in result.stdout
|