Coverage for tests / test_tutorial / test_using_click / 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 click.testing import CliRunner 1abcdefgh

5 

6from docs_src.using_click import tutorial001_py39 as mod 1abcdefgh

7 

8runner = CliRunner() 1abcdefgh

9 

10 

11def test_help(): 1abcdefgh

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

13 assert result.exit_code == 0 1abcdefgh

14 assert ( 1abcdefgh

15 "Simple program that greets NAME for a total of COUNT times." in result.output 

16 ) 

17 assert "--name" in result.output 1abcdefgh

18 assert "--count" in result.output 1abcdefgh

19 

20 

21def test_cli_prompt(): 1abcdefgh

22 result = runner.invoke(mod.hello, input="Camila\n") 1abcdefgh

23 assert result.exit_code == 0 1abcdefgh

24 assert "Your name: Camila" in result.stdout 1abcdefgh

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

26 

27 

28def test_cli_with_name(): 1abcdefgh

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

30 assert result.exit_code == 0 1abcdefgh

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

32 

33 

34def test_cli_with_name_and_count(): 1abcdefgh

35 result = runner.invoke(mod.hello, ["--name", "Camila", "--count", "3"]) 1abcdefgh

36 assert result.exit_code == 0 1abcdefgh

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

38 assert result.stdout.count("Hello Camila!") == 3 1abcdefgh

39 

40 

41def test_script(): 1abcdefgh

42 result = subprocess.run( 1abcdefgh

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

44 capture_output=True, 

45 encoding="utf-8", 

46 ) 

47 assert "Usage" in result.stdout 1abcdefgh