Coverage for tests / test_tutorial / test_options / test_password / test_tutorial001.py: 100%
31 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import importlib 1abcdefghij
2import subprocess 1abcdefghij
3import sys 1abcdefghij
4from types import ModuleType 1abcdefghij
6import pytest 1abcdefghij
7from typer.testing import CliRunner 1abcdefghij
9from tests.utils import strip_double_spaces 1abcdefghij
11runner = CliRunner() 1abcdefghij
14@pytest.fixture( 1abcdefghij
15 name="mod",
16 params=[
17 pytest.param("tutorial001_non_an"),
18 pytest.param("tutorial001"),
19 ],
20)
21def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghij
22 module_name = f"docs_src.options.password.{request.param}" 1abcdefghij
23 mod = importlib.import_module(module_name) 1abcdefghij
24 return mod 1abcdefghij
27def test_option_email(mod: ModuleType): 1abcdefghij
28 result = runner.invoke(mod.app, ["Camila", "--email", "camila@example.com"]) 1abcdefghij
29 assert result.exit_code == 0 1abcdefghij
30 assert "Hello Camila, your email is camila@example.com" in result.output 1abcdefghij
33def test_option_email_prompt(mod: ModuleType): 1abcdefghij
34 result = runner.invoke( 1abcdefghij
35 mod.app, ["Camila"], input="camila@example.com\ncamila@example.com\n"
36 )
37 assert result.exit_code == 0 1abcdefghij
38 assert "Email: camila@example.com" in result.output 1abcdefghij
39 assert "Repeat for confirmation: camila@example.com" in result.output 1abcdefghij
40 assert "Hello Camila, your email is camila@example.com" in result.output 1abcdefghij
43def test_help(mod: ModuleType): 1abcdefghij
44 result = runner.invoke(mod.app, ["--help"]) 1abcdefghij
45 assert result.exit_code == 0 1abcdefghij
46 output_without_double_spaces = strip_double_spaces(result.output) 1abcdefghij
47 assert "--email <str> [required]" in output_without_double_spaces 1abcdefghij
50def test_script(mod: ModuleType): 1abcdefghij
51 result = subprocess.run( 1abcdefghij
52 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
53 capture_output=True,
54 encoding="utf-8",
55 )
56 assert "Usage" in result.stdout 1abcdefghij