aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/tests
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-04-06 18:18:01 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-04-06 18:18:01 +0300
commit01fbacb386809436dfa331780875aed72cb76118 (patch)
tree04c911ad96ff0523bd4d3e7a45c23cf2f2d7607d /contrib/python/prompt-toolkit/py3/tests
parent48fb997d7f820a474b9094a72d9798a95ec612b7 (diff)
downloadydb-01fbacb386809436dfa331780875aed72cb76118.tar.gz
intermediate changes
ref:b4f892f3c2b06a356c155f73c27efc5661a7fb89
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/tests')
-rw-r--r--contrib/python/prompt-toolkit/py3/tests/test_cli.py30
-rw-r--r--contrib/python/prompt-toolkit/py3/tests/test_key_binding.py15
-rw-r--r--contrib/python/prompt-toolkit/py3/tests/test_shortcuts.py16
3 files changed, 38 insertions, 23 deletions
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_cli.py b/contrib/python/prompt-toolkit/py3/tests/test_cli.py
index 678bc52636..53d1e4f284 100644
--- a/contrib/python/prompt-toolkit/py3/tests/test_cli.py
+++ b/contrib/python/prompt-toolkit/py3/tests/test_cli.py
@@ -45,9 +45,7 @@ def _feed_cli_with_input(
if check_line_ending:
assert text.endswith("\r")
- inp = create_pipe_input()
-
- try:
+ with create_pipe_input() as inp:
inp.send_text(text)
session = PromptSession(
input=inp,
@@ -59,12 +57,9 @@ def _feed_cli_with_input(
key_bindings=key_bindings,
)
- result = session.prompt()
+ _ = session.prompt()
return session.default_buffer.document, session.app
- finally:
- inp.close()
-
def test_simple_text_input():
# Simple text input, followed by enter.
@@ -933,15 +928,12 @@ def test_accept_default():
"""
Test `prompt(accept_default=True)`.
"""
- inp = create_pipe_input()
-
- session = PromptSession(input=inp, output=DummyOutput())
- result = session.prompt(default="hello", accept_default=True)
- assert result == "hello"
-
- # Test calling prompt() for a second time. (We had an issue where the
- # prompt reset between calls happened at the wrong time, breaking this.)
- result = session.prompt(default="world", accept_default=True)
- assert result == "world"
-
- inp.close()
+ with create_pipe_input() as inp:
+ session = PromptSession(input=inp, output=DummyOutput())
+ result = session.prompt(default="hello", accept_default=True)
+ assert result == "hello"
+
+ # Test calling prompt() for a second time. (We had an issue where the
+ # prompt reset between calls happened at the wrong time, breaking this.)
+ result = session.prompt(default="world", accept_default=True)
+ assert result == "world"
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py b/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py
index 617e71c1e1..6f03f2deab 100644
--- a/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py
+++ b/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py
@@ -1,3 +1,5 @@
+from contextlib import contextmanager
+
import pytest
from prompt_toolkit.application import Application
@@ -21,16 +23,21 @@ class Handlers:
return func
+@contextmanager
def set_dummy_app():
"""
Return a context manager that makes sure that this dummy application is
active. This is important, because we need an `Application` with
`is_done=False` flag, otherwise no keys will be processed.
"""
- app = Application(
- layout=Layout(Window()), output=DummyOutput(), input=create_pipe_input()
- )
- return set_app(app)
+ with create_pipe_input() as pipe_input:
+ app = Application(
+ layout=Layout(Window()),
+ output=DummyOutput(),
+ input=pipe_input,
+ )
+ with set_app(app):
+ yield
@pytest.fixture
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_shortcuts.py b/contrib/python/prompt-toolkit/py3/tests/test_shortcuts.py
index dc4d65b272..10ee73a20e 100644
--- a/contrib/python/prompt-toolkit/py3/tests/test_shortcuts.py
+++ b/contrib/python/prompt-toolkit/py3/tests/test_shortcuts.py
@@ -1,4 +1,7 @@
+from prompt_toolkit.shortcuts import print_container
from prompt_toolkit.shortcuts.prompt import _split_multiline_prompt
+from prompt_toolkit.shortcuts.utils import print_container
+from prompt_toolkit.widgets import Frame, TextArea
def test_split_multiline_prompt():
@@ -49,3 +52,16 @@ def test_split_multiline_prompt():
assert has_before_tokens() is True
assert before() == [("class:testclass", "\n")]
assert first_input_line() == [("class:testclass", "a"), ("class:testclass", "b")]
+
+
+def test_print_container(tmpdir):
+ # Call `print_container`, render to a dummy file.
+ f = tmpdir.join("output")
+ with open(f, "w") as fd:
+ print_container(Frame(TextArea(text="Hello world!\n"), title="Title"), file=fd)
+
+ # Verify rendered output.
+ with open(f, "r") as fd:
+ text = fd.read()
+ assert "Hello world" in text
+ assert "Title" in text