Add tests for CLI arguments

This commit is contained in:
Sebastián Ramírez 2019-12-29 17:09:56 +01:00
parent ce1316ce8f
commit 3332ab3cae
4 changed files with 111 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import subprocess
import typer
from typer.testing import CliRunner
from arguments import tutorial001 as mod
runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
def test_call_no_arg():
result = runner.invoke(app)
assert result.exit_code != 0
assert 'Error: Missing argument "NAME".' in result.output
def test_call_arg():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "Hello Camila" in result.output
def test_script():
result = subprocess.run(
["coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout

View file

@ -0,0 +1,39 @@
import subprocess
import typer
from typer.testing import CliRunner
from arguments import tutorial002 as mod
runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
def test_call_no_arg():
result = runner.invoke(app)
assert result.exit_code == 0
assert "Hello World!" in result.output
def test_call_arg():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "Hello Camila" in result.output
def test_script():
result = subprocess.run(
["coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout

View file

@ -0,0 +1,39 @@
import subprocess
import typer
from typer.testing import CliRunner
from arguments import tutorial003 as mod
runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
def test_call_no_arg():
result = runner.invoke(app)
assert result.exit_code == 0
assert "Hello Wade Wilson" in result.output
def test_call_arg():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "Hello Camila" in result.output
def test_script():
result = subprocess.run(
["coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout