Coverage for unit_tests/test_005_multi_commands.py: 100%

1 import subprocess

2 import sys

3

4 from typer.testing import CliRunner

5

6 from examples import example_005_multi_commands as mod

7

8 runner = CliRunner()

9

10 app = mod.app

11

12

13 def test_help():

14 result = runner.invoke(app, ["--help"])

15 assert result.exit_code == 0

16

17

18 def test_all_commands():

19 result = runner.invoke(app, ["hi", "--user.id", "1"])

20 assert "Hi id=1 name='John'" in result.output

21 result = runner.invoke(app, ["bye", "--user.id", "1"])

22 assert "Bye id=1 name='John'" in result.output

23

24

25 def test_script():

26 result = subprocess.run(

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

28 capture_output=True,

29 encoding="utf-8",

30 check=False,

31 )

32 assert "Usage" in result.stdout