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

20 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-19 20:29 +0000

1import subprocess 1abcdefghi

2import sys 1abcdefghi

3 

4from typer.testing import CliRunner 1abcdefghi

5 

6from docs_src.parameter_types.custom_types import tutorial002 as mod 1abcdefghi

7 

8runner = CliRunner() 1abcdefghi

9app = mod.app 1abcdefghi

10 

11 

12def test_help(): 1abcdefghi

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

14 assert result.exit_code == 0 1abcdefghi

15 

16 

17def test_parse_custom_type(): 1abcdefghi

18 result = runner.invoke(app, ["0", "--custom-opt", "1"]) 1abcdefghi

19 assert "custom_arg is <CustomClass: value=000>" in result.output 1abcdefghi

20 assert "custom-opt is <CustomClass: value=111>" in result.output 1abcdefghi

21 

22 

23def test_parse_custom_type_with_default(): 1abcdefghi

24 result = runner.invoke(app, ["0"]) 1abcdefghi

25 assert "custom_arg is <CustomClass: value=000>" in result.output 1abcdefghi

26 assert "custom-opt is <CustomClass: value=FooFooFoo>" in result.output 1abcdefghi

27 

28 

29def test_script(): 1abcdefghi

30 result = subprocess.run( 1abcdefghi

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

32 capture_output=True, 

33 encoding="utf-8", 

34 ) 

35 assert "Usage" in result.stdout 1abcdefghi