Skip to content
Myr

:white_check_mark: Add tests for tutorial006 in First Steps, to test help from docstring

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent cf75cad · Browse files · 1 file+52 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+52 added−0 removed

  • tests:+52 added−0 removed

1 file+52 added−0 removed

added:tests/test_tutorial/test_first_steps/test_tutorial006.py+52 added
1import subprocess23import typer4from typer.testing import CliRunner56from first_steps import tutorial006 as mod78runner = CliRunner()910app = typer.Typer()11app.command()(mod.main)121314def test_help():15 result = runner.invoke(app, ["--help"])16 assert result.exit_code == 017 assert "Say hi to NAME, optionally with a --lastname." in result.output18 assert "If --formal is used, say hi very formally." in result.output192021def test_1():22 result = runner.invoke(app, ["Camila"])23 assert result.exit_code == 024 assert "Hello Camila" in result.output252627def test_option_lastname():28 result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"])29 assert result.exit_code == 030 assert "Hello Camila Gutiérrez" in result.output313233def test_option_lastname_2():34 result = runner.invoke(app, ["--lastname", "Gutiérrez", "Camila"])35 assert result.exit_code == 036 assert "Hello Camila Gutiérrez" in result.output373839def test_formal_1():40 result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez", "--formal"])41 assert result.exit_code == 042 assert "Good day Ms. Camila Gutiérrez." in result.output434445def test_script():46 result = subprocess.run(47 ["coverage", "run", "--parallel-mode", mod.__file__, "--help"],48 stdout=subprocess.PIPE,49 stderr=subprocess.PIPE,50 encoding="utf-8",51 )52 assert "Usage" in result.stdout