Coverage for tests/test_tutorial/test_terminating/test_tutorial003.py: 100%
32 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
5import typer.core 1abcdefgh
6from typer.testing import CliRunner 1abcdefgh
8from docs_src.terminating import tutorial003 as mod 1abcdefgh
10runner = CliRunner() 1abcdefgh
12app = typer.Typer() 1abcdefgh
13app.command()(mod.main) 1abcdefgh
16def test_cli(): 1abcdefgh
17 result = runner.invoke(app, ["Camila"]) 1abcdefgh
18 assert result.exit_code == 0 1abcdefgh
19 assert "New user created: Camila" in result.output 1abcdefgh
22def test_root(): 1abcdefgh
23 result = runner.invoke(app, ["root"]) 1abcdefgh
24 assert result.exit_code == 1 1abcdefgh
25 assert "The root user is reserved" in result.output 1abcdefgh
26 assert "Aborted" in result.output 1abcdefgh
29def test_root_no_standalone(): 1abcdefgh
30 # Mainly for coverage
31 result = runner.invoke(app, ["root"], standalone_mode=False) 1abcdefgh
32 assert result.exit_code == 1 1abcdefgh
35def test_root_no_rich(): 1abcdefgh
36 # Mainly for coverage
37 rich = typer.core.rich 1abcdefgh
38 typer.core.rich = None 1abcdefgh
39 result = runner.invoke(app, ["root"]) 1abcdefgh
40 assert result.exit_code == 1 1abcdefgh
41 assert "The root user is reserved" in result.stdout 1abcdefgh
42 assert "Aborted!" in result.stdout 1abcdefgh
43 typer.core.rich = rich 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