From e0babfa8225f27be7d03a1dfc46bd08ecfad2212 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Mon, 13 Jul 2026 15:30:55 +0900 Subject: [PATCH] Make cheat-sheet test independent of rich table padding Signed-off-by: PoAn Yang --- .../cli/commands/test_cheat_sheet_command.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/airflow-core/tests/unit/cli/commands/test_cheat_sheet_command.py b/airflow-core/tests/unit/cli/commands/test_cheat_sheet_command.py index b00bb56059304..5c4baa8d807e5 100644 --- a/airflow-core/tests/unit/cli/commands/test_cheat_sheet_command.py +++ b/airflow-core/tests/unit/cli/commands/test_cheat_sheet_command.py @@ -16,6 +16,7 @@ # under the License. from __future__ import annotations +import re from unittest import mock from airflow.cli import cli_parser @@ -72,20 +73,25 @@ def noop(): ] ALL_COMMANDS = """\ -airflow cmd_b | Help text D +airflow cmd_b | Help text D """ SECTION_A = """\ -airflow cmd_a cmd_b | Help text B -airflow cmd_a cmd_c | Help text C +airflow cmd_a cmd_b | Help text B +airflow cmd_a cmd_c | Help text C """ SECTION_E = """\ -airflow cmd_e cmd_f | Help text F -airflow cmd_e cmd_g | Help text G +airflow cmd_e cmd_f | Help text F +airflow cmd_e cmd_g | Help text G """ +def normalize_spaces(text: str) -> str: + """Collapse runs of spaces so assertions do not depend on the rich version's exact column padding.""" + return re.sub(r" +", " ", text) + + class TestCheatSheetCommand: @classmethod def setup_class(cls): @@ -96,7 +102,7 @@ def test_should_display_index(self, stdout_capture): with stdout_capture as temp_stdout: args = self.parser.parse_args(["cheat-sheet"]) args.func(args) - output = temp_stdout.getvalue() + output = normalize_spaces(temp_stdout.getvalue()) assert ALL_COMMANDS in output assert SECTION_A in output assert SECTION_E in output