Coverage for tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002_an.py: 100%
33 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1import subprocess 1abcdefgh
2import sys 1abcdefgh
4import typer 1abcdefgh
5from typer.testing import CliRunner 1abcdefgh
7from docs_src.multiple_values.arguments_with_multiple_values import ( 1abcdefgh
8 tutorial002_an as mod,
9)
11runner = CliRunner() 1abcdefgh
12app = typer.Typer() 1abcdefgh
13app.command()(mod.main) 1abcdefgh
16def test_help(): 1abcdefgh
17 result = runner.invoke(app, ["--help"]) 1abcdefgh
18 assert result.exit_code == 0 1abcdefgh
19 assert "[OPTIONS] [NAMES]..." in result.output 1abcdefgh
20 assert "Arguments" in result.output 1abcdefgh
21 assert "[default: Harry, Hermione, Ron]" in result.output 1abcdefgh
24def test_defaults(): 1abcdefgh
25 result = runner.invoke(app) 1abcdefgh
26 assert result.exit_code == 0 1abcdefgh
27 assert "Hello Harry" in result.output 1abcdefgh
28 assert "Hello Hermione" in result.output 1abcdefgh
29 assert "Hello Ron" in result.output 1abcdefgh
32def test_invalid_args(): 1abcdefgh
33 result = runner.invoke(app, ["Draco", "Hagrid"]) 1abcdefgh
34 assert result.exit_code != 0 1abcdefgh
35 assert "Argument 'names' takes 3 values" in result.stdout 1abcdefgh
38def test_valid_args(): 1abcdefgh
39 result = runner.invoke(app, ["Draco", "Hagrid", "Dobby"]) 1abcdefgh
40 assert result.exit_code == 0 1abcdefgh
41 assert "Hello Draco" in result.stdout 1abcdefgh
42 assert "Hello Hagrid" in result.stdout 1abcdefgh
43 assert "Hello Dobby" in result.stdout 1abcdefgh
46def test_script(): 1abcdefgh
47 result = subprocess.run( 1abcdefgh
48 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
49 capture_output=True,
50 encoding="utf-8",
51 )
52 assert "Usage" in result.stdout 1abcdefgh