From 670653df2db3b71b2345db556bfb8040e0f20728 Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Fri, 26 Jan 2024 15:53:26 +0800 Subject: [PATCH] Try to support prompt_toolkit >3.0.37 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 --- poetry.lock | 10 +++++----- pyproject.toml | 2 +- tests/prompts/test_common.py | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/poetry.lock b/poetry.lock index f82de67..ff1ec6f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -577,13 +577,13 @@ virtualenv = ">=20.10.0" [[package]] name = "prompt-toolkit" -version = "3.0.36" +version = "3.0.43" description = "Library for building powerful interactive command lines in Python" optional = false -python-versions = ">=3.6.2" +python-versions = ">=3.7.0" files = [ - {file = "prompt_toolkit-3.0.36-py3-none-any.whl", hash = "sha256:aa64ad242a462c5ff0363a7b9cfe696c20d55d9fc60c11fd8e632d064804d305"}, - {file = "prompt_toolkit-3.0.36.tar.gz", hash = "sha256:3e163f254bef5a03b146397d7c1963bd3e2812f0964bb9a24e6ec761fd28db63"}, + {file = "prompt_toolkit-3.0.43-py3-none-any.whl", hash = "sha256:a11a29cb3bf0a28a387fe5122cdb649816a957cd9261dcedf8c9f1fef33eacf6"}, + {file = "prompt_toolkit-3.0.43.tar.gz", hash = "sha256:3527b7af26106cbc65a040bcc84839a3566ec1b051bb0bfe953631e704b0ff7d"}, ] [package.dependencies] @@ -1094,4 +1094,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.8" -content-hash = "69da0b625156d12413563199c39faece347a06ef44da899307205c0798ad6d0f" +content-hash = "eb9c4e36a3591050ff87532d3cf31a6a4c013872a47e16fcc345165676d9ad6b" diff --git a/pyproject.toml b/pyproject.toml index 681f626..b72d093 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/prompts/test_common.py b/tests/prompts/test_common.py index d6ce51e..bb98253 100644 --- a/tests/prompts/test_common.py +++ b/tests/prompts/test_common.py @@ -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 @@ -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 @@ -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() @@ -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():