From a445a6d5c62e509afacdcd1855ae911d1e2d59f5 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 3 Mar 2026 03:25:42 -0500 Subject: [PATCH] Removed unnecessary arguments in rich_text_to_string(). --- cmd2/argparse_custom.py | 4 ++-- cmd2/rich_utils.py | 3 --- tests/test_cmd2.py | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 2830a45a1..39417bd80 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -1250,10 +1250,10 @@ def error(self, message: str) -> NoReturn: self.print_usage(sys.stderr) - # Add error style to message + # Use console to add style since it will respect ALLOW_STYLE's value console = self._get_formatter().console with console.capture() as capture: - console.print(formatted_message, style=Cmd2Style.ERROR, crop=False) + console.print(formatted_message, style=Cmd2Style.ERROR) formatted_message = f"{capture.get()}" self.exit(2, f'{formatted_message}\n') diff --git a/cmd2/rich_utils.py b/cmd2/rich_utils.py index 4178158d6..418783281 100644 --- a/cmd2/rich_utils.py +++ b/cmd2/rich_utils.py @@ -273,9 +273,6 @@ def rich_text_to_string(text: Text) -> str: force_terminal=True, soft_wrap=True, no_color=False, - markup=False, - emoji=False, - highlight=False, theme=APP_THEME, ) with console.capture() as capture: diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 2a5fa8320..0ca5dc2b5 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -2540,10 +2540,20 @@ def test_get_settable_choices(base_app: cmd2.Cmd) -> None: cur_settable = base_app.settables.get(cur_choice.text) assert cur_settable is not None + # Convert fields so we can compare them str_value = str(cur_settable.value) + + choice_value = cur_choice.table_row[0] + if isinstance(choice_value, Text): + choice_value = ru.rich_text_to_string(choice_value) + + choice_description = cur_choice.table_row[1] + if isinstance(choice_description, Text): + choice_description = ru.rich_text_to_string(choice_description) + assert str_value in cur_choice.display_meta - assert ru.rich_text_to_string(cur_choice.table_row[0]) == str_value - assert ru.rich_text_to_string(cur_choice.table_row[1]) == cur_settable.description + assert choice_value == str_value + assert choice_description == cur_settable.description def test_alias_no_subcommand(base_app) -> None: