Coverage for tests/test_tutorial/test_using_click/test_tutorial003.py: 100%

23 statements  

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

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4from click.testing import CliRunner 1abcdefgh

5 

6from docs_src.using_click import tutorial003 as mod 1abcdefgh

7 

8runner = CliRunner() 1abcdefgh

9 

10 

11def test_cli(): 1abcdefgh

12 result = runner.invoke(mod.typer_click_object, []) 1abcdefgh

13 assert "Missing command" in result.stdout 1abcdefgh

14 

15 

16def test_help(): 1abcdefgh

17 result = runner.invoke(mod.typer_click_object, ["--help"]) 1abcdefgh

18 assert result.exit_code == 0 1abcdefgh

19 assert "Commands" in result.output 1abcdefgh

20 assert "top" in result.output 1abcdefgh

21 assert "hello" in result.output 1abcdefgh

22 

23 

24def test_typer(): 1abcdefgh

25 result = runner.invoke(mod.typer_click_object, ["top"]) 1abcdefgh

26 assert "The Typer app is at the top level" in result.stdout 1abcdefgh

27 

28 

29def test_click(): 1abcdefgh

30 result = runner.invoke(mod.typer_click_object, ["hello", "--name", "Camila"]) 1abcdefgh

31 assert "Hello Camila!" in result.stdout 1abcdefgh

32 

33 

34def test_script(): 1abcdefgh

35 result = subprocess.run( 1abcdefgh

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

37 capture_output=True, 

38 encoding="utf-8", 

39 ) 

40 assert "Usage" in result.stdout 1abcdefgh