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

30 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-02-09 12:36 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4import pytest 1abcdefgh

5import typer 1abcdefgh

6import typer.core 1abcdefgh

7from typer.testing import CliRunner 1abcdefgh

8 

9from docs_src.terminating import tutorial003_py39 as mod 1abcdefgh

10 

11runner = CliRunner() 1abcdefgh

12app = mod.app 1abcdefgh

13 

14 

15def test_cli(): 1abcdefgh

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

17 assert result.exit_code == 0 1abcdefgh

18 assert "New user created: Camila" in result.output 1abcdefgh

19 

20 

21def test_root(): 1abcdefgh

22 result = runner.invoke(app, ["root"]) 1abcdefgh

23 assert result.exit_code == 1 1abcdefgh

24 assert "The root user is reserved" in result.output 1abcdefgh

25 assert "Aborted" in result.output 1abcdefgh

26 

27 

28def test_root_no_standalone(): 1abcdefgh

29 # Mainly for coverage 

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

31 assert result.exit_code == 1 1abcdefgh

32 

33 

34def test_root_no_rich(monkeypatch: pytest.MonkeyPatch): 1abcdefgh

35 # Mainly for coverage 

36 monkeypatch.setattr(typer.core, "HAS_RICH", False) 1abcdefgh

37 result = runner.invoke(app, ["root"]) 1abcdefgh

38 assert result.exit_code == 1 1abcdefgh

39 assert "The root user is reserved" in result.output 1abcdefgh

40 assert "Aborted!" in result.output 1abcdefgh

41 

42 

43def test_script(): 1abcdefgh

44 result = subprocess.run( 1abcdefgh

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

46 capture_output=True, 

47 encoding="utf-8", 

48 ) 

49 assert "Usage" in result.stdout 1abcdefgh