Coverage for tests/test_tutorial/test_parameter_types/test_number/test_tutorial002.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4import typer 1abcdefgh

5from typer.testing import CliRunner 1abcdefgh

6 

7from docs_src.parameter_types.number import tutorial002 as mod 1abcdefgh

8 

9runner = CliRunner() 1abcdefgh

10 

11app = typer.Typer() 1abcdefgh

12app.command()(mod.main) 1abcdefgh

13 

14 

15def test_invalid_id(): 1abcdefgh

16 result = runner.invoke(app, ["1002"]) 1abcdefgh

17 assert result.exit_code != 0 1abcdefgh

18 assert ( 1abcdefgh

19 "Invalid value for 'ID': 1002 is not in the range 0<=x<=1000" in result.output 

20 ) 

21 

22 

23def test_clamped(): 1abcdefgh

24 result = runner.invoke(app, ["5", "--rank", "11", "--score", "-5"]) 1abcdefgh

25 assert result.exit_code == 0 1abcdefgh

26 assert "ID is 5" in result.output 1abcdefgh

27 assert "--rank is 10" in result.output 1abcdefgh

28 assert "--score is 0" in result.output 1abcdefgh

29 

30 

31def test_script(): 1abcdefgh

32 result = subprocess.run( 1abcdefgh

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

34 capture_output=True, 

35 encoding="utf-8", 

36 ) 

37 assert "Usage" in result.stdout 1abcdefgh