-
-
Notifications
You must be signed in to change notification settings - Fork 624
/
test_tutorial002.py
55 lines (41 loc) · 1.46 KB
/
test_tutorial002.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
import subprocess
import typer
from typer.testing import CliRunner
from docs_src.multiple_values.arguments_with_multiple_values import tutorial002 as mod
runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAMES]..." in result.output
assert "Arguments:" in result.output
assert "[default: Harry, Hermione, Ron]" in result.output
def test_defaults():
result = runner.invoke(app)
assert result.exit_code == 0
assert "Hello Harry" in result.output
assert "Hello Hermione" in result.output
assert "Hello Ron" in result.output
def test_invalid_args():
result = runner.invoke(app, ["Draco", "Hagrid"])
assert result.exit_code != 0
# TODO: when deprecating Click 7, remove second option
assert (
"Error: Argument 'names' takes 3 values" in result.stdout
or "Error: argument names takes 3 values" in result.stdout
)
def test_valid_args():
result = runner.invoke(app, ["Draco", "Hagrid", "Dobby"])
assert result.exit_code == 0
assert "Hello Draco" in result.stdout
assert "Hello Hagrid" in result.stdout
assert "Hello Dobby" in result.stdout
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