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

30 statements  

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

1import subprocess 1abcdefghij

2import sys 1abcdefghij

3 

4import pytest 1abcdefghij

5import typer 1abcdefghij

6import typer.core 1abcdefghij

7from typer.testing import CliRunner 1abcdefghij

8 

9from docs_src.terminating import tutorial003 as mod 1abcdefghij

10 

11runner = CliRunner() 1abcdefghij

12app = mod.app 1abcdefghij

13 

14 

15def test_cli(): 1abcdefghij

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

17 assert result.exit_code == 0 1abcdefghij

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

19 

20 

21def test_root(): 1abcdefghij

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

23 assert result.exit_code == 1 1abcdefghij

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

25 assert "Aborted" in result.output 1abcdefghij

26 

27 

28def test_root_no_standalone(): 1abcdefghij

29 # Mainly for coverage 

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

31 assert result.exit_code == 1 1abcdefghij

32 

33 

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

35 # Mainly for coverage 

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

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

38 assert result.exit_code == 1 1abcdefghij

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

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

41 

42 

43def test_script(): 1abcdefghij

44 result = subprocess.run( 1abcdefghij

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

46 capture_output=True, 

47 encoding="utf-8", 

48 ) 

49 assert "Usage" in result.stdout 1abcdefghij