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-11-18 11:12 +0000

1import subprocess 1abcdefghij

2import sys 1abcdefghij

3 

4from typer.testing import CliRunner 1abcdefghij

5 

6from docs_src.parameter_types.index import tutorial001 as mod 1abcdefghij

7 

8runner = CliRunner() 1abcdefghij

9app = mod.app 1abcdefghij

10 

11 

12def test_help(): 1abcdefghij

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

14 assert result.exit_code == 0 1abcdefghij

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

16 assert "<int>" in result.output 1abcdefghij

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

18 assert "<float>" in result.output 1abcdefghij

19 

20 

21def test_params(): 1abcdefghij

22 result = runner.invoke( 1abcdefghij

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

24 ) 

25 assert result.exit_code == 0 1abcdefghij

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

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

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

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

30 

31 

32def test_invalid(): 1abcdefghij

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

34 assert result.exit_code != 0 1abcdefghij

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

36 assert "Input should be a valid integer" in result.output 1abcdefghij

37 

38 

39def test_script(): 1abcdefghij

40 result = subprocess.run( 1abcdefghij

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

42 capture_output=True, 

43 encoding="utf-8", 

44 ) 

45 assert "Usage" in result.stdout 1abcdefghij