Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colors module and docs for printing and terminating. #20

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✅ Add tests for printing and terminating
  • Loading branch information
tiangolo committed Jan 2, 2020
commit 9abba68f0b1e8203c19b5592555b9999bb20f959
Empty file.
35 changes: 35 additions & 0 deletions tests/test_tutorial/test_terminating/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess

import typer
from typer.testing import CliRunner

from terminating import tutorial001 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


def test_cli():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "User created: Camila" in result.output
assert "Notification sent for new user: Camila" in result.output


def test_existing():
result = runner.invoke(app, ["rick"])
assert result.exit_code == 0
assert "The user already exists" in result.output
assert "Notification sent for new user" not 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
33 changes: 33 additions & 0 deletions tests/test_tutorial/test_terminating/test_tutorial002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess

import typer
from typer.testing import CliRunner

from terminating import tutorial002 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


def test_cli():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "New user created: Camila" in result.output


def test_root():
result = runner.invoke(app, ["root"])
assert result.exit_code == 1
assert "The root user is reserved" 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
34 changes: 34 additions & 0 deletions tests/test_tutorial/test_terminating/test_tutorial003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import subprocess

import typer
from typer.testing import CliRunner

from terminating import tutorial003 as mod

runner = CliRunner()

app = typer.Typer()
app.command()(mod.main)


def test_cli():
result = runner.invoke(app, ["Camila"])
assert result.exit_code == 0
assert "New user created: Camila" in result.output


def test_root():
result = runner.invoke(app, ["root"])
assert result.exit_code == 1
assert "The root user is reserved" in result.output
assert "Aborted!" 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