✅ Add tests for extra param types, bool, number
This commit is contained in:
parent
421468c04c
commit
be75c9c3a3
6 changed files with 239 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
import subprocess
|
||||
|
||||
import typer
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from parameter_types.bool import tutorial001 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 "--force" in result.output
|
||||
assert "--no-force" not in result.output
|
||||
|
||||
|
||||
def test_no_force():
|
||||
result = runner.invoke(app)
|
||||
assert result.exit_code == 0
|
||||
assert "Not forcing" in result.output
|
||||
|
||||
|
||||
def test_force():
|
||||
result = runner.invoke(app, ["--force"])
|
||||
assert result.exit_code == 0
|
||||
assert "Forcing operation" in result.output
|
||||
|
||||
|
||||
def test_invalid_no_force():
|
||||
result = runner.invoke(app, ["--no-force"])
|
||||
assert result.exit_code != 0
|
||||
assert "Error: no such option: --no-force" 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
|
|
@ -0,0 +1,52 @@
|
|||
import subprocess
|
||||
|
||||
import typer
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from parameter_types.bool 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 "--accept / --reject" in result.output
|
||||
assert "--no-accept" not in result.output
|
||||
|
||||
|
||||
def test_main():
|
||||
result = runner.invoke(app)
|
||||
assert result.exit_code == 0
|
||||
assert "I don't know what you want yet" in result.output
|
||||
|
||||
|
||||
def test_accept():
|
||||
result = runner.invoke(app, ["--accept"])
|
||||
assert result.exit_code == 0
|
||||
assert "Accepting!" in result.output
|
||||
|
||||
|
||||
def test_reject():
|
||||
result = runner.invoke(app, ["--reject"])
|
||||
assert result.exit_code == 0
|
||||
assert "Rejecting!" in result.output
|
||||
|
||||
|
||||
def test_invalid_no_accept():
|
||||
result = runner.invoke(app, ["--no-accept"])
|
||||
assert result.exit_code != 0
|
||||
assert "Error: no such option: --no-accept" 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
|
|
@ -0,0 +1,39 @@
|
|||
import subprocess
|
||||
|
||||
import typer
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from parameter_types.bool 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 "-f, --force / -F, --no-force" in result.output
|
||||
|
||||
|
||||
def test_force():
|
||||
result = runner.invoke(app, ["-f"])
|
||||
assert result.exit_code == 0
|
||||
assert "Forcing operation" in result.output
|
||||
|
||||
|
||||
def test_no_force():
|
||||
result = runner.invoke(app, ["-F"])
|
||||
assert result.exit_code == 0
|
||||
assert "Not forcing" 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
|
|
@ -0,0 +1,45 @@
|
|||
import subprocess
|
||||
|
||||
import typer
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from parameter_types.bool import tutorial004 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 "/ -d, --demo" in result.output
|
||||
|
||||
|
||||
def test_main():
|
||||
result = runner.invoke(app)
|
||||
assert result.exit_code == 0
|
||||
assert "Running in production" in result.output
|
||||
|
||||
|
||||
def test_demo():
|
||||
result = runner.invoke(app, ["--demo"])
|
||||
assert result.exit_code == 0
|
||||
assert "Running demo" in result.output
|
||||
|
||||
|
||||
def test_short_demo():
|
||||
result = runner.invoke(app, ["-d"])
|
||||
assert result.exit_code == 0
|
||||
assert "Running demo" 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
|
|
@ -0,0 +1,57 @@
|
|||
import subprocess
|
||||
|
||||
import typer
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from parameter_types.number import tutorial003 as mod
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
app = typer.Typer()
|
||||
app.command()(mod.main)
|
||||
|
||||
|
||||
def test_main():
|
||||
result = runner.invoke(app)
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 0" in result.output
|
||||
|
||||
|
||||
def test_verbose_1():
|
||||
result = runner.invoke(app, ["--verbose"])
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 1" in result.output
|
||||
|
||||
|
||||
def test_verbose_3():
|
||||
result = runner.invoke(app, ["--verbose", "--verbose", "--verbose"])
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 3" in result.output
|
||||
|
||||
|
||||
def test_verbose_short_1():
|
||||
result = runner.invoke(app, ["-v"])
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 1" in result.output
|
||||
|
||||
|
||||
def test_verbose_short_3():
|
||||
result = runner.invoke(app, ["-v", "-v", "-v"])
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 3" in result.output
|
||||
|
||||
|
||||
def test_verbose_short_3_condensed():
|
||||
result = runner.invoke(app, ["-vvv"])
|
||||
assert result.exit_code == 0
|
||||
assert "Verbose level is 3" 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