Coverage for tests / test_tutorial / test_terminating / test_tutorial001.py: 100%

24 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 typer.testing import CliRunner 1abcdefgh

5 

6from docs_src.terminating import tutorial001_py39 as mod 1abcdefgh

7 

8runner = CliRunner() 1abcdefgh

9app = mod.app 1abcdefgh

10 

11 

12def test_cli(): 1abcdefgh

13 result = runner.invoke(app, ["Camila"]) 1abcdefgh

14 assert result.exit_code == 0 1abcdefgh

15 assert "User created: Camila" in result.output 1abcdefgh

16 assert "Notification sent for new user: Camila" in result.output 1abcdefgh

17 

18 

19def test_existing(): 1abcdefgh

20 result = runner.invoke(app, ["rick"]) 1abcdefgh

21 assert result.exit_code == 0 1abcdefgh

22 assert "The user already exists" in result.output 1abcdefgh

23 assert "Notification sent for new user" not in result.output 1abcdefgh

24 

25 

26def test_existing_no_standalone(): 1abcdefgh

27 # Mainly for coverage 

28 result = runner.invoke(app, ["rick"], standalone_mode=False) 1abcdefgh

29 assert result.exit_code == 0 1abcdefgh

30 assert "The user already exists" in result.output 1abcdefgh

31 assert "Notification sent for new user" not in result.output 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