-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Show help items in order of definition (#944)
- Loading branch information
Showing
6 changed files
with
133 additions
and
32 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() | ||
|
||
|
||
@app.command() | ||
def delete(): | ||
print("Deleting user: Hiro Hamada") | ||
|
||
|
||
@app.command() | ||
def create(): | ||
print("Creating user: Hiro Hamada") | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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
45 changes: 45 additions & 0 deletions
45
tests/test_tutorial/test_commands/test_index/test_tutorial004.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,45 @@ | ||
import subprocess | ||
import sys | ||
|
||
from typer.testing import CliRunner | ||
|
||
from docs_src.commands.index import tutorial004 as mod | ||
|
||
app = mod.app | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_help(): | ||
result = runner.invoke(app, ["--help"]) | ||
assert result.exit_code == 0 | ||
assert "[OPTIONS] COMMAND [ARGS]..." in result.output | ||
print(result.output) | ||
assert "Commands" in result.output | ||
assert "create" in result.output | ||
assert "delete" in result.output | ||
# Test that the 'delete' command precedes the 'create' command in the help output | ||
create_char = result.output.index("create") | ||
delete_char = result.output.index("delete") | ||
assert delete_char < create_char | ||
|
||
|
||
def test_create(): | ||
result = runner.invoke(app, ["create"]) | ||
assert result.exit_code == 0 | ||
assert "Creating user: Hiro Hamada" in result.output | ||
|
||
|
||
def test_delete(): | ||
result = runner.invoke(app, ["delete"]) | ||
assert result.exit_code == 0 | ||
assert "Deleting user: Hiro Hamada" in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], | ||
capture_output=True, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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