|
| 1 | +import subprocess |
| 2 | + |
| 3 | +import typer |
| 4 | +from typer.testing import CliRunner |
| 5 | + |
| 6 | +from first_steps import tutorial005 as mod |
| 7 | + |
| 8 | +runner = CliRunner() |
| 9 | + |
| 10 | +app = typer.Typer() |
| 11 | +app.command()(mod.main) |
| 12 | + |
| 13 | + |
| 14 | +def test_help(): |
| 15 | + result = runner.invoke(app, ["--help"]) |
| 16 | + assert result.exit_code == 0 |
| 17 | + assert "--lastname TEXT" in result.output |
| 18 | + assert "--formal / --no-formal" in result.output |
| 19 | + |
| 20 | + |
| 21 | +def test_1(): |
| 22 | + result = runner.invoke(app, ["Camila"]) |
| 23 | + assert result.exit_code == 0 |
| 24 | + assert "Hello Camila" in result.output |
| 25 | + |
| 26 | + |
| 27 | +def test_option_lastname(): |
| 28 | + result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"]) |
| 29 | + assert result.exit_code == 0 |
| 30 | + assert "Hello Camila Gutiérrez" in result.output |
| 31 | + |
| 32 | + |
| 33 | +def test_option_lastname_2(): |
| 34 | + result = runner.invoke(app, ["--lastname", "Gutiérrez", "Camila"]) |
| 35 | + assert result.exit_code == 0 |
| 36 | + assert "Hello Camila Gutiérrez" in result.output |
| 37 | + |
| 38 | + |
| 39 | +def test_formal_1(): |
| 40 | + result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez", "--formal"]) |
| 41 | + assert result.exit_code == 0 |
| 42 | + assert "Good day Ms. Camila Gutiérrez." in result.output |
| 43 | + |
| 44 | + |
| 45 | +def 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 |
0 commit comments