Coverage for tests/test_tutorial/test_options/test_callback/test_tutorial003_an.py: 100%
24 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 os 1abcdefgh
2import subprocess 1abcdefgh
3import sys 1abcdefgh
5import typer 1abcdefgh
6from typer.testing import CliRunner 1abcdefgh
8from docs_src.options.callback import tutorial003_an as mod 1abcdefgh
10runner = CliRunner() 1abcdefgh
12app = typer.Typer() 1abcdefgh
13app.command()(mod.main) 1abcdefgh
16def test_1(): 1abcdefgh
17 result = runner.invoke(app, ["--name", "Camila"]) 1abcdefgh
18 assert result.exit_code == 0 1abcdefgh
19 assert "Validating name" in result.output 1abcdefgh
20 assert "Hello Camila" in result.output 1abcdefgh
23def test_2(): 1abcdefgh
24 result = runner.invoke(app, ["--name", "rick"]) 1abcdefgh
25 assert result.exit_code != 0 1abcdefgh
26 assert "Invalid value for '--name': Only Camila is allowed" in result.output 1abcdefgh
29def test_script(): 1abcdefgh
30 result = subprocess.run( 1abcdefgh
31 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
32 capture_output=True,
33 encoding="utf-8",
34 )
35 assert "Usage" in result.stdout 1abcdefgh
38def test_completion(): 1abcdefgh
39 result = subprocess.run( 1abcdefgh
40 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],
41 capture_output=True,
42 encoding="utf-8",
43 env={
44 **os.environ,
45 "_TUTORIAL003_AN.PY_COMPLETE": "complete_bash",
46 "COMP_WORDS": "tutorial003_an.py --",
47 "COMP_CWORD": "1",
48 },
49 )
50 assert "--name" in result.stdout 1abcdefgh