fix tests

This commit is contained in:
2026-01-28 14:52:41 +03:00
parent 2a9281a421
commit 9aa99352fe
3 changed files with 26 additions and 36 deletions
-22
View File
@@ -1,22 +0,0 @@
from prompt_toolkit.shortcuts import checkboxlist_dialog
from prompt_toolkit.styles import Style
results = checkboxlist_dialog(
title="CheckboxList dialog",
text="What would you like in your breakfast ?",
values=[
("eggs", "Eggs"),
("bacon", "Bacon"),
("croissants", "20 Croissants"),
("daily", "The breakfast of the day")
],
style=Style.from_dict({
'dialog': 'bg:#cdbbb3',
'button': 'bg:#bf99a4',
'checkbox': '#e8612c',
'dialog.body': 'bg:#a9cfd0',
'dialog shadow': 'bg:#c98982',
'frame.label': '#fcaca3',
'dialog.body label': '#fd8bb6',
})
).run()
+16 -4
View File
@@ -157,14 +157,26 @@ class BaseApp:
)
)
def _print_framed_text(self, text: str) -> None:
def _print_static_framed_text(self, text: str) -> None:
"""
Private. Outputs text by framing it in a static or dynamic split strip
:param text: framed text
:return: None
"""
match self._dividing_line:
case (StaticDividingLine() as dividing_line) | (DynamicDividingLine() as dividing_line):
case StaticDividingLine() as dividing_line:
self._print_func(
dividing_line.get_full_static_line(
is_override=self._override_system_messages
)
)
print(text.strip("\n"))
self._print_func(
dividing_line.get_full_static_line(
is_override=self._override_system_messages
)
)
case DynamicDividingLine() as dividing_line:
self._print_func(
StaticDividingLine(dividing_line.get_unit_part()).get_full_static_line(
is_override=self._override_system_messages
@@ -460,7 +472,7 @@ class App(BaseApp):
stderr_result = self._capture_stdout(
lambda: self._error_handler(error, raw_command) # noqa F821
)
self._print_framed_text(stderr_result)
self._print_static_framed_text(stderr_result)
continue
if self._is_exit_command(input_command):
@@ -471,7 +483,7 @@ class App(BaseApp):
stdout_res = self._capture_stdout(
lambda: self._unknown_command_handler(input_command)
)
self._print_framed_text(stdout_res)
self._print_static_framed_text(stdout_res)
continue
self._process_exist_and_valid_command(input_command)
+10 -10
View File
@@ -297,30 +297,30 @@ def test_pre_cycle_setup_prints_startup_messages(capsys: CaptureFixture[str]) ->
def test_print_framed_text_with_static_dividing_line(capsys: CaptureFixture[str]) -> None:
app = App(override_system_messages=True, dividing_line=StaticDividingLine(length=5))
app._print_framed_text('test')
app = App(override_system_messages=True, dividing_line=StaticDividingLine(unit_part='!', length=5))
app._print_static_framed_text('test')
captured = capsys.readouterr()
assert '\n-----\n\ntest\n\n-----\n' in captured.out
assert '\n' + '!'*5 + '\n\ntest\n\n' + '!'*5 + '\n' in captured.out
def test_print_framed_text_with_dynamic_dividing_line_short_text(capsys: CaptureFixture[str]) -> None:
app = App(override_system_messages=True, dividing_line=DynamicDividingLine())
app._print_framed_text('some long test')
app = App(override_system_messages=True, dividing_line=DynamicDividingLine('+'))
app._print_static_framed_text('some long test')
captured = capsys.readouterr()
assert '\n--------------\n\nsome long test\n\n--------------\n' in captured.out
assert '\n' + '+'*25 + '\n\nsome long test\n\n' + '+'*25 + '\n' in captured.out
def test_print_framed_text_with_dynamic_dividing_line_long_text(capsys: CaptureFixture[str]) -> None:
app = App(override_system_messages=True, dividing_line=DynamicDividingLine())
app._print_framed_text('test as test as test')
app = App(override_system_messages=True, dividing_line=DynamicDividingLine('`'))
app._print_static_framed_text('test as test as test')
captured = capsys.readouterr()
assert '\n' + '-'*20 + '\n\ntest as test as test\n\n' + '-'*20 + '\n' in captured.out
assert '\n' + '`'*25 + '\n\ntest as test as test\n\n' + '`'*25 + '\n' in captured.out
def test_print_framed_text_with_unsupported_dividing_line_raises_error() -> None:
@@ -330,7 +330,7 @@ def test_print_framed_text_with_unsupported_dividing_line_raises_error() -> None
app = App(override_system_messages=True, dividing_line=OtherDividingLine()) # pyright: ignore[reportArgumentType]
with pytest.raises(NotImplementedError):
app._print_framed_text('some long test')
app._print_static_framed_text('some long test')
# ============================================================================