✅ Add tests for printing and terminating
This commit is contained in:
parent
aadca21c0b
commit
9abba68f0b
4 changed files with 102 additions and 0 deletions
0
tests/test_tutorial/test_terminating/__init__.py
Normal file
0
tests/test_tutorial/test_terminating/__init__.py
Normal file
35
tests/test_tutorial/test_terminating/test_tutorial001.py
Normal file
35
tests/test_tutorial/test_terminating/test_tutorial001.py
Normal file
|
@ -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
tests/test_tutorial/test_terminating/test_tutorial002.py
Normal file
33
tests/test_tutorial/test_terminating/test_tutorial002.py
Normal file
|
@ -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
tests/test_tutorial/test_terminating/test_tutorial003.py
Normal file
34
tests/test_tutorial/test_terminating/test_tutorial003.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue