-
-
Notifications
You must be signed in to change notification settings - Fork 624
/
test_tutorial008.py
49 lines (39 loc) · 1.36 KB
/
test_tutorial008.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
import os
import subprocess
import typer
from typer.testing import CliRunner
from docs_src.options.autocompletion import tutorial008 as mod
runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
def test_completion():
result = subprocess.run(
["coverage", "run", mod.__file__, " "],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
env={
**os.environ,
"_TUTORIAL008.PY_COMPLETE": "complete_zsh",
"_TYPER_COMPLETE_ARGS": "tutorial008.py --name ",
"_TYPER_COMPLETE_TESTING": "True",
},
)
assert '"Camila":"The reader of books."' in result.stdout
assert '"Carlos":"The writer of scripts."' in result.stdout
assert '"Sebastian":"The type hints guy."' in result.stdout
# TODO: when deprecating Click 7, remove second option
assert "[]" in result.stderr or "['--name']" in result.stderr
def test_1():
result = runner.invoke(app, ["--name", "Camila", "--name", "Sebastian"])
assert result.exit_code == 0
assert "Hello Camila" in result.output
assert "Hello Sebastian" in result.output
def test_script():
result = subprocess.run(
["coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout