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: #344
  • Loading branch information
FantasqueX committed Jan 26, 2024
1 parent 04a90f8 commit 670653d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 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
8 changes: 5 additions & 3 deletions tests/prompts/test_common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
from unittest.mock import Mock
from unittest.mock import call

import pytest
from prompt_toolkit.document import Document
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.output import DummyOutput
from prompt_toolkit.styles import Attrs
from prompt_toolkit.validation import ValidationError
Expand All @@ -13,7 +15,6 @@
from questionary.prompts.common import InquirerControl
from questionary.prompts.common import build_validator
from questionary.prompts.common import print_formatted_text
from tests.utils import execute_with_input_pipe
from tests.utils import prompt_toolkit_version


Expand Down Expand Up @@ -72,7 +73,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 +87,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 670653d

Please sign in to comment.