Coverage for tests / test_tutorial / test_commands / test_help / test_tutorial006.py: 100%

37 statements  

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

1import os 1abcdefghij

2import subprocess 1abcdefghij

3import sys 1abcdefghij

4 

5from typer.testing import CliRunner 1abcdefghij

6 

7from docs_src.commands.help import tutorial006 as mod 1abcdefghij

8 

9app = mod.app 1abcdefghij

10 

11runner = CliRunner() 1abcdefghij

12 

13 

14def test_main_help(): 1abcdefghij

15 result = runner.invoke(app, ["--help"]) 1abcdefghij

16 assert result.exit_code == 0 1abcdefghij

17 assert "create" in result.output 1abcdefghij

18 assert "Create a new user. ✨" in result.output 1abcdefghij

19 assert "delete" in result.output 1abcdefghij

20 assert "Delete a user. ❌" in result.output 1abcdefghij

21 assert "Utils and Configs" in result.output 1abcdefghij

22 assert "config" in result.output 1abcdefghij

23 assert "Configure the system. ⚙" in result.output 1abcdefghij

24 assert "Synchronize the system or something fancy like that. ♻" in result.output 1abcdefghij

25 assert "Help and Others" in result.output 1abcdefghij

26 assert "Get help with the system. ❓" in result.output 1abcdefghij

27 assert "Report an issue. ❗" in result.output 1abcdefghij

28 

29 

30def test_call(): 1abcdefghij

31 # Mainly for coverage 

32 result = runner.invoke(app, ["create", "Morty"]) 1abcdefghij

33 assert result.exit_code == 0 1abcdefghij

34 result = runner.invoke(app, ["delete", "Morty"]) 1abcdefghij

35 assert result.exit_code == 0 1abcdefghij

36 result = runner.invoke(app, ["config", "Morty"]) 1abcdefghij

37 assert result.exit_code == 0 1abcdefghij

38 result = runner.invoke(app, ["sync"]) 1abcdefghij

39 assert result.exit_code == 0 1abcdefghij

40 result = runner.invoke(app, ["help"]) 1abcdefghij

41 assert result.exit_code == 0 1abcdefghij

42 result = runner.invoke(app, ["report"]) 1abcdefghij

43 assert result.exit_code == 0 1abcdefghij

44 

45 

46def test_script(): 1abcdefghij

47 result = subprocess.run( 1abcdefghij

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

49 capture_output=True, 

50 encoding="utf-8", 

51 env={**os.environ, "PYTHONIOENCODING": "utf-8"}, 

52 ) 

53 assert "Usage" in result.stdout 1abcdefghij