Coverage for unit_tests/test_006_pydantic_types.py: 100%

1 import subprocess

2 import sys

3

4 from typer.testing import CliRunner

5

6 import pydantic_typer

7 from examples import example_006_pydantic_types as mod

8

9 runner = CliRunner()

10

11 app = pydantic_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_valid_input():

21 result = runner.invoke(app, ["2", "https://google.com"])

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

23 assert "https://google.com/ <class 'pydantic_core._pydantic_core.Url'>" in result.output

24

25

26 def test_invalid_url():

27 result = runner.invoke(app, ["2", "ftp://ftp.google.com"])

28 assert "Invalid value for url: URL scheme should be 'http' or 'https'" in result.output

29

30

31 def test_script():

32 result = subprocess.run(

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

34 capture_output=True,

35 encoding="utf-8",

36 check=False,

37 )

38 assert "Usage" in result.stdout