diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-12 14:35:15 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-12 14:35:15 +0300 |
commit | 46a8b83899dd321edf511c0483f9c479ce2c1bc4 (patch) | |
tree | e5debc03beecbd10e7d1bf78c889c8d54e8c4523 /contrib/python/prompt-toolkit/py3/tests | |
parent | b56bbcc9f63bf31991a8aa118555ce0c12875a74 (diff) | |
download | ydb-46a8b83899dd321edf511c0483f9c479ce2c1bc4.tar.gz |
intermediate changes
ref:7c971b97c72bbbcbf889118d39017bd14f99365a
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/tests')
5 files changed, 82 insertions, 15 deletions
diff --git a/contrib/python/prompt-toolkit/py3/tests/test_cli.py b/contrib/python/prompt-toolkit/py3/tests/test_cli.py index 9c623f1c0c5..678bc526365 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_cli.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_cli.py @@ -1,4 +1,3 @@ -# encoding: utf-8 """ These are almost end-to-end tests. They create a Prompt, feed it with some input and check the result. diff --git a/contrib/python/prompt-toolkit/py3/tests/test_completion.py b/contrib/python/prompt-toolkit/py3/tests/test_completion.py index f5c2a582a17..6c71620d113 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_completion.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_completion.py @@ -33,7 +33,7 @@ def write_test_files(test_dir, names=None): names = names or range(10) for i in names: with open(os.path.join(test_dir, str(i)), "wb") as out: - out.write("".encode("UTF-8")) + out.write(b"") def test_pathcompleter_completes_in_current_directory(): @@ -50,7 +50,7 @@ def test_pathcompleter_completes_files_in_current_directory(): test_dir = tempfile.mkdtemp() write_test_files(test_dir) - expected = sorted([str(i) for i in range(10)]) + expected = sorted(str(i) for i in range(10)) if not test_dir.endswith(os.path.sep): test_dir += os.path.sep @@ -74,7 +74,7 @@ def test_pathcompleter_completes_files_in_absolute_directory(): test_dir = tempfile.mkdtemp() write_test_files(test_dir) - expected = sorted([str(i) for i in range(10)]) + expected = sorted(str(i) for i in range(10)) test_dir = os.path.abspath(test_dir) if not test_dir.endswith(os.path.sep): @@ -86,7 +86,7 @@ def test_pathcompleter_completes_files_in_absolute_directory(): doc = Document(doc_text, len(doc_text)) event = CompleteEvent() completions = list(completer.get_completions(doc, event)) - result = sorted([c.text for c in completions]) + result = sorted(c.text for c in completions) assert expected == result # cleanup diff --git a/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py b/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py index 23f5ccfd57f..8b4924f968a 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_formatted_text.py @@ -103,6 +103,71 @@ def test_ansi_true_color(): ] +def test_ansi_interpolation(): + # %-style interpolation. + value = ANSI("\x1b[1m%s\x1b[0m") % "hello\x1b" + assert to_formatted_text(value) == [ + ("bold", "h"), + ("bold", "e"), + ("bold", "l"), + ("bold", "l"), + ("bold", "o"), + ("bold", "?"), + ] + + value = ANSI("\x1b[1m%s\x1b[0m") % ("\x1bhello",) + assert to_formatted_text(value) == [ + ("bold", "?"), + ("bold", "h"), + ("bold", "e"), + ("bold", "l"), + ("bold", "l"), + ("bold", "o"), + ] + + value = ANSI("\x1b[32m%s\x1b[45m%s") % ("He", "\x1bllo") + assert to_formatted_text(value) == [ + ("ansigreen", "H"), + ("ansigreen", "e"), + ("ansigreen bg:ansimagenta", "?"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "o"), + ] + + # Format function. + value = ANSI("\x1b[32m{0}\x1b[45m{1}").format("He\x1b", "llo") + assert to_formatted_text(value) == [ + ("ansigreen", "H"), + ("ansigreen", "e"), + ("ansigreen", "?"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "o"), + ] + + value = ANSI("\x1b[32m{a}\x1b[45m{b}").format(a="\x1bHe", b="llo") + assert to_formatted_text(value) == [ + ("ansigreen", "?"), + ("ansigreen", "H"), + ("ansigreen", "e"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "l"), + ("ansigreen bg:ansimagenta", "o"), + ] + + value = ANSI("\x1b[32m{:02d}\x1b[45m{:.3f}").format(3, 3.14159) + assert to_formatted_text(value) == [ + ("ansigreen", "0"), + ("ansigreen", "3"), + ("ansigreen bg:ansimagenta", "3"), + ("ansigreen bg:ansimagenta", "."), + ("ansigreen bg:ansimagenta", "1"), + ("ansigreen bg:ansimagenta", "4"), + ("ansigreen bg:ansimagenta", "2"), + ] + + def test_interpolation(): value = Template(" {} ").format(HTML("<b>hello</b>")) @@ -125,22 +190,25 @@ def test_interpolation(): def test_html_interpolation(): # %-style interpolation. - value = HTML("<b>%s</b>") % "hello" - assert to_formatted_text(value) == [("class:b", "hello")] + value = HTML("<b>%s</b>") % "&hello" + assert to_formatted_text(value) == [("class:b", "&hello")] - value = HTML("<b>%s</b>") % ("hello",) - assert to_formatted_text(value) == [("class:b", "hello")] + value = HTML("<b>%s</b>") % ("<hello>",) + assert to_formatted_text(value) == [("class:b", "<hello>")] - value = HTML("<b>%s</b><u>%s</u>") % ("hello", "world") - assert to_formatted_text(value) == [("class:b", "hello"), ("class:u", "world")] + value = HTML("<b>%s</b><u>%s</u>") % ("<hello>", "</world>") + assert to_formatted_text(value) == [("class:b", "<hello>"), ("class:u", "</world>")] # Format function. - value = HTML("<b>{0}</b><u>{1}</u>").format("hello", "world") - assert to_formatted_text(value) == [("class:b", "hello"), ("class:u", "world")] + value = HTML("<b>{0}</b><u>{1}</u>").format("'hello'", '"world"') + assert to_formatted_text(value) == [("class:b", "'hello'"), ("class:u", '"world"')] value = HTML("<b>{a}</b><u>{b}</u>").format(a="hello", b="world") assert to_formatted_text(value) == [("class:b", "hello"), ("class:u", "world")] + value = HTML("<b>{:02d}</b><u>{:.3f}</u>").format(3, 3.14159) + assert to_formatted_text(value) == [("class:b", "03"), ("class:u", "3.142")] + def test_merge_formatted_text(): html1 = HTML("<u>hello</u>") diff --git a/contrib/python/prompt-toolkit/py3/tests/test_inputstream.py b/contrib/python/prompt-toolkit/py3/tests/test_inputstream.py index f5ae1e39656..8c3d8fd7c45 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_inputstream.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_inputstream.py @@ -4,7 +4,7 @@ from prompt_toolkit.input.vt100_parser import Vt100Parser from prompt_toolkit.keys import Keys -class _ProcessorMock(object): +class _ProcessorMock: def __init__(self): self.keys = [] 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 f1ec5af36dd..617e71c1e1d 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_key_binding.py @@ -10,7 +10,7 @@ from prompt_toolkit.layout import Layout, Window from prompt_toolkit.output import DummyOutput -class Handlers(object): +class Handlers: def __init__(self): self.called = [] |