Coverage for tests/test_004_argument_override.py: 100%

1 import subprocess

2 import sys

3

4 import typer

5 from typer.testing import CliRunner

6

7 from examples import example_004_argument_override as mod

8

9 runner = CliRunner()

10

11 app = typer.Typer()

12 app.command()(mod.main)

13

14

15 def test_help():

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

17 assert result.exit_code == 0

18

19

20 def test_parse_pydantic_model():

21 result = runner.invoke(app, '--num 1 2 --user.name "John Doe"')

22 assert "1 <class 'int'>" in result.output

23 assert "id=2 name='John Doe' <class 'examples.example_004_argument_override.User'>" in result.output

24

25

26 def test_script():

27 result = subprocess.run(

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

29 capture_output=True,

30 encoding="utf-8",

31 check=False,

32 )

33 assert "Usage" in result.stdout