-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
357f19b
commit 7096ed6
Showing
1 changed file
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from __future__ import annotations | ||
|
||
import click | ||
import pytest | ||
|
||
import click_repl | ||
from tests import mock_stdin | ||
|
||
|
||
@click.group(invoke_without_command=True) | ||
@click.pass_context | ||
def cli(ctx): | ||
if ctx.invoked_subcommand is None: | ||
click_repl.repl(ctx) | ||
|
||
|
||
@cli.command() | ||
def hello(): | ||
print("Hello!") | ||
|
||
|
||
@cli.command() | ||
@click_repl.pass_context | ||
def history_test(repl_ctx): | ||
print(list(repl_ctx.history())) | ||
|
||
|
||
def test_repl_ctx_history(capsys): | ||
with mock_stdin("hello\nhistory-test\n"): | ||
with pytest.raises(SystemExit): | ||
cli(args=[], prog_name="test_repl_ctx_history") | ||
|
||
assert ( | ||
capsys.readouterr().out.replace("\r\n", "\n") | ||
== "Hello!\n['history-test', 'hello']\n" | ||
) | ||
|
||
|
||
@cli.command() | ||
@click_repl.pass_context | ||
def prompt_test(repl_ctx): | ||
print(repl_ctx.prompt) | ||
|
||
|
||
def test_repl_ctx_prompt(capsys): | ||
with mock_stdin("prompt-test\n"): | ||
with pytest.raises(SystemExit): | ||
cli(args=[], prog_name="test_repl_ctx_history") | ||
|
||
assert capsys.readouterr().out.replace("\r\n", "\n") == "None\n" |