forked from tiangolo/typer
/
test_tutorial001.py
65 lines (49 loc) · 1.76 KB
/
test_tutorial001.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
import subprocess
import sys
import typer
from typer.testing import CliRunner
from docs_src.parameter_types.enum import tutorial001 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 "--network" in result.output
assert "[simple|conv|lstm]" in result.output
def test_main():
result = runner.invoke(app, ["--network", "conv"])
assert result.exit_code == 0
assert "Training neural network of type: conv" in result.output
def test_invalid_case():
result = runner.invoke(app, ["--network", "CONV"])
assert result.exit_code != 0
# TODO: when deprecating Click 7, remove second option
assert (
"Invalid value for '--network': 'CONV' is not one of" in result.output
or "Invalid value for '--network': invalid choice: CONV. (choose from"
in result.output
)
assert "simple" in result.output
assert "conv" in result.output
assert "lstm" in result.output
def test_invalid_other():
result = runner.invoke(app, ["--network", "capsule"])
assert result.exit_code != 0
# TODO: when deprecating Click 7, remove second option
assert (
"Invalid value for '--network': 'capsule' is not one of" in result.output
or "Invalid value for '--network': invalid choice: capsule. (choose from"
in result.output
)
assert "simple" in result.output
assert "conv" in result.output
assert "lstm" in result.output
def test_script():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout