Skip to content

Commit

Permalink
Try to support prompt_toolkit >3.0.37
Browse files Browse the repository at this point in the history
Currently one test will fail with latest prompt_toolkit(3.0.43).
test_blank_line_fix will throw RuntimeError: no running event loop.
By bisecting commit, the culprit is
prompt-toolkit/python-prompt-toolkit@a775996.
This commit replaces custom `get_event_loop` with `asyncio.get_event_loop`. The former will creator a new loop if `asyncio.get_running_loop` fails while the latter won't.
I mimic the changes in the examples to use `asyncio.run` and the test
passes.

Fixes: tmbo#344
  • Loading branch information
FantasqueX committed Jan 9, 2024
1 parent 04a90f8 commit ac81bf2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.8"
prompt_toolkit = ">=2.0,<=3.0.36" # once https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1726 is fixed, this can be changed to ">=2.0,<4.0"
prompt_toolkit = ">=2.0,<4.0"

[tool.poetry.group.docs]
optional = true
Expand Down
7 changes: 5 additions & 2 deletions tests/prompts/test_common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from unittest.mock import Mock
from unittest.mock import call

Expand All @@ -6,6 +7,7 @@
from prompt_toolkit.output import DummyOutput
from prompt_toolkit.styles import Attrs
from prompt_toolkit.validation import ValidationError
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.validation import Validator

from questionary import Choice
Expand Down Expand Up @@ -72,7 +74,7 @@ def get_prompt_tokens():

ic = InquirerControl(["a", "b", "c"])

def run(inp):
async def run(inp):
inp.send_text("")
layout = common.create_inquirer_layout(
ic, get_prompt_tokens, input=inp, output=DummyOutput()
Expand All @@ -86,7 +88,8 @@ def run(inp):
== 1000000000000000000000000000001
)

execute_with_input_pipe(run)
with create_pipe_input() as inp:
asyncio.run(run(inp))


def test_prompt_highlight_coexist():
Expand Down

0 comments on commit ac81bf2

Please sign in to comment.