diff --git a/tests/test_tutorial/test_arguments/__init__.py b/tests/test_tutorial/test_arguments/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_tutorial/test_arguments/test_tutorial001.py b/tests/test_tutorial/test_arguments/test_tutorial001.py new file mode 100644 index 0000000..668e657 --- /dev/null +++ b/tests/test_tutorial/test_arguments/test_tutorial001.py @@ -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 diff --git a/tests/test_tutorial/test_arguments/test_tutorial002.py b/tests/test_tutorial/test_arguments/test_tutorial002.py new file mode 100644 index 0000000..82c6198 --- /dev/null +++ b/tests/test_tutorial/test_arguments/test_tutorial002.py @@ -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 diff --git a/tests/test_tutorial/test_arguments/test_tutorial003.py b/tests/test_tutorial/test_arguments/test_tutorial003.py new file mode 100644 index 0000000..255b793 --- /dev/null +++ b/tests/test_tutorial/test_arguments/test_tutorial003.py @@ -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