Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs and test for 'no_args_is_help'
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import typer | ||
|
||
app = typer.Typer(no_args_is_help=True) | ||
|
||
|
||
@app.command() | ||
def create(): | ||
print("Creating user: Hiro Hamada") | ||
|
||
|
||
@app.command() | ||
def delete(): | ||
print("Deleting user: Hiro Hamada") | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
29 changes: 29 additions & 0 deletions
29
tests/test_tutorial/test_commands/test_index/test_tutorial003.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import subprocess | ||
import sys | ||
|
||
from typer.testing import CliRunner | ||
|
||
from docs_src.commands.index import tutorial003 as mod | ||
|
||
app = mod.app | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_no_arg(): | ||
result = runner.invoke(app) | ||
assert result.exit_code == 0 | ||
assert "[OPTIONS] COMMAND [ARGS]..." in result.output | ||
assert "Commands" in result.output | ||
assert "create" in result.output | ||
assert "delete" in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |