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

20 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 tutorial002_py39 as mod 1abcdefgh

7 

8runner = CliRunner() 1abcdefgh

9 

10 

11def test_help(): 1abcdefgh

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

13 assert result.exit_code == 0 1abcdefgh

14 assert "Commands" in result.output 1abcdefgh

15 assert "initdb" in result.output 1abcdefgh

16 assert "dropdb" in result.output 1abcdefgh

17 

18 

19def test_initdb(): 1abcdefgh

20 result = runner.invoke(mod.cli, ["initdb"]) 1abcdefgh

21 assert "Initialized the database" in result.stdout 1abcdefgh

22 

23 

24def test_dropdb(): 1abcdefgh

25 result = runner.invoke(mod.cli, ["dropdb"]) 1abcdefgh

26 assert "Dropped the database" in result.stdout 1abcdefgh

27 

28 

29def test_script(): 1abcdefgh

30 result = subprocess.run( 1abcdefgh

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

32 capture_output=True, 

33 encoding="utf-8", 

34 ) 

35 assert "Usage" in result.stdout 1abcdefgh