Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support prompt-toolkit 3.0.47 #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 157 additions & 156 deletions tests/prompts/test_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,153 +12,153 @@


class TestConfirmPrompt(unittest.TestCase):
def setUp(self):
self.inp = create_pipe_input()

def tearDown(self):
self.inp.close()

def test_default_false(self):
self.inp.send_text("\n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=InquirerPyStyle({"qmark": "bold"}),
default=False,
qmark="x",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)
with create_pipe_input() as inp:
inp.send_text("\n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=InquirerPyStyle({"qmark": "bold"}),
default=False,
qmark="x",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)

def test_default_true(self):
self.inp.send_text("\n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=InquirerPyStyle({"qmark": "bold", "answer": "#000000"}),
default=True,
qmark="x",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)
with create_pipe_input() as inp:
inp.send_text("\n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=InquirerPyStyle({"qmark": "bold", "answer": "#000000"}),
default=True,
qmark="x",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)

def test_input_y(self):
self.inp.send_text("y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt._session.prompt()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)
with create_pipe_input() as inp:
inp.send_text("y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt._session.prompt()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)

self.inp.send_text("Y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, True)
inp.send_text("Y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, True)

def test_input_n(self):
self.inp.send_text("n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)
with create_pipe_input() as inp:
inp.send_text("n")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)

self.inp.send_text("N")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
inp.send_text("N")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = confirm_prompt.execute()
self.assertEqual(result, False)

def test_custom_confirm(self):
self.inp.send_text("s")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
confirm_letter="s",
)
result = confirm_prompt._session.prompt()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)
with create_pipe_input() as inp:
inp.send_text("s")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
confirm_letter="s",
)
result = confirm_prompt._session.prompt()
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)

self.inp.send_text("S")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
confirm_letter="s",
)
result = confirm_prompt.execute()
self.assertEqual(result, True)
inp.send_text("S")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
confirm_letter="s",
)
result = confirm_prompt.execute()
self.assertEqual(result, True)

def test_custom_reject(self):
self.inp.send_text("w")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=False,
qmark="?",
output=DummyOutput(),
input=self.inp,
reject_letter="w",
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)
with create_pipe_input() as inp:
inp.send_text("w")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=False,
qmark="?",
output=DummyOutput(),
input=inp,
reject_letter="w",
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], False)

self.inp.send_text("W")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
reject_letter="w",
)
result = confirm_prompt.execute()
self.assertEqual(result, False)
inp.send_text("W")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
reject_letter="w",
)
result = confirm_prompt.execute()
self.assertEqual(result, False)

def test_get_prompt_message(self):
confirm_prompt = ConfirmPrompt(
Expand Down Expand Up @@ -268,28 +268,29 @@ def test_confirm_kbi(self, mocked_session):
prompt.execute()

def test_input_y_async(self):
self.inp.send_text("y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = asyncio.run(confirm_prompt._run_async())
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)
with create_pipe_input() as inp:
inp.send_text("y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = asyncio.run(confirm_prompt._run_async())
self.assertEqual(result, True)
self.assertEqual(confirm_prompt.status["answered"], True)
self.assertEqual(confirm_prompt.status["result"], True)

self.inp.send_text("Y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=self.inp,
)
result = asyncio.run(confirm_prompt.execute_async())
self.assertEqual(result, True)
inp.send_text("Y")
confirm_prompt = ConfirmPrompt(
message="hello",
style=None,
default=True,
qmark="?",
output=DummyOutput(),
input=inp,
)
result = asyncio.run(confirm_prompt.execute_async())
self.assertEqual(result, True)
Loading