Coverage for tests / test_tutorial / test_parameter_types / test_index / test_tutorial001.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-02-09 12:36 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4from typer.testing import CliRunner 1abcdefgh

5 

6from docs_src.parameter_types.index import tutorial001_py39 as mod 1abcdefgh

7 

8runner = CliRunner() 1abcdefgh

9app = mod.app 1abcdefgh

10 

11 

12def test_help(): 1abcdefgh

13 result = runner.invoke(app, ["--help"]) 1abcdefgh

14 assert result.exit_code == 0 1abcdefgh

15 assert "--age" in result.output 1abcdefgh

16 assert "INTEGER" in result.output 1abcdefgh

17 assert "--height-meters" in result.output 1abcdefgh

18 assert "FLOAT" in result.output 1abcdefgh

19 

20 

21def test_params(): 1abcdefgh

22 result = runner.invoke( 1abcdefgh

23 app, ["Camila", "--age", "15", "--height-meters", "1.70", "--female"] 

24 ) 

25 assert result.exit_code == 0 1abcdefgh

26 assert "NAME is Camila, of type: <class 'str'>" in result.output 1abcdefgh

27 assert "--age is 15, of type: <class 'int'>" in result.output 1abcdefgh

28 assert "--height-meters is 1.7, of type: <class 'float'>" in result.output 1abcdefgh

29 assert "--female is True, of type: <class 'bool'>" in result.output 1abcdefgh

30 

31 

32def test_invalid(): 1abcdefgh

33 result = runner.invoke(app, ["Camila", "--age", "15.3"]) 1abcdefgh

34 assert result.exit_code != 0 1abcdefgh

35 assert "Invalid value for '--age'" in result.output 1abcdefgh

36 assert "'15.3' is not a valid integer" in result.output 1abcdefgh

37 

38 

39def test_script(): 1abcdefgh

40 result = subprocess.run( 1abcdefgh

41 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

42 capture_output=True, 

43 encoding="utf-8", 

44 ) 

45 assert "Usage" in result.stdout 1abcdefgh