Align stage and step banner formatting in test log
Stage banners now use a fixed-width top and bottom border, with a left-aligned content line indented by two spaces. This replaces the previous centered format and ensures the content line always begins at a consistent column. Step banners now use a fixed-length prefix and either: - Pad to a target width when the line is short, or - Append a fixed-length suffix if the line exceeds that width. This ensures consistent prefix alignment for all steps and stages. Right-side borders may overflow when content exceeds the width limit, but formatting remains visually stable and predictable. Change-Id: I2b2de3ba74bdd7675c5526484600018218447359 Signed-off-by: Andrew Vaillancourt <andrew.vaillancourt@windriver.com>
This commit is contained in:
@@ -182,7 +182,11 @@ class AutomationLogger(logging.getLoggerClass()):
|
|||||||
|
|
||||||
def _format_step_tag(self, tag: str, step_number: int | None, description: str = "") -> str:
|
def _format_step_tag(self, tag: str, step_number: int | None, description: str = "") -> str:
|
||||||
"""
|
"""
|
||||||
Format a standardized left-aligned single-line banner.
|
Format a left-aligned, single-line banner for a test step.
|
||||||
|
|
||||||
|
This ensures a consistent prefix and trailing marker. If the total line
|
||||||
|
is shorter than the target width, it will be padded to align visually.
|
||||||
|
Otherwise, a fixed suffix is appended to preserve formatting.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tag (str): The stage label (e.g., "SETUP", "TEST", "TEARDOWN").
|
tag (str): The stage label (e.g., "SETUP", "TEST", "TEARDOWN").
|
||||||
@@ -191,19 +195,25 @@ class AutomationLogger(logging.getLoggerClass()):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: A left-aligned banner like:
|
str: A left-aligned banner like:
|
||||||
----- [ Test Step 2: Validate throughput ] -----------
|
------- [ Test Step 3: Validate throughput ] ---------------
|
||||||
"""
|
"""
|
||||||
banner_char = "-"
|
banner_char = "-"
|
||||||
total_width = 60
|
total_width = 60
|
||||||
|
suffix_pad_len = 7
|
||||||
|
prefix = banner_char * 7
|
||||||
|
|
||||||
label = tag.title()
|
label = tag.title()
|
||||||
|
|
||||||
if step_number is not None:
|
if step_number is not None:
|
||||||
content = f"[ {label} Step {step_number}: {description} ]"
|
content = f"[ {label} Step {step_number}: {description} ]"
|
||||||
else:
|
else:
|
||||||
content = f"[ {label}: {description} ]"
|
content = f"[ {label}: {description} ]"
|
||||||
|
|
||||||
padding = total_width - len(content) - 1 # -1 for the leading space
|
line = f"{prefix} {content} "
|
||||||
return banner_char * 5 + " " + content + " " + banner_char * max(padding - 5, 0)
|
|
||||||
|
# Pad short lines to target width, otherwise append a fixed-length suffix
|
||||||
|
trailing = banner_char * max(total_width - len(line), suffix_pad_len)
|
||||||
|
return line + trailing
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@@ -64,29 +64,20 @@ def get_banner(banner_lines: List[str]) -> List[str]:
|
|||||||
return banner
|
return banner
|
||||||
|
|
||||||
|
|
||||||
def log_testcase_stage_banner(stage: str, test_name: str) -> None:
|
def log_testcase_stage_banner(stage: str, test_name: str, total_width: int = 60) -> None:
|
||||||
"""
|
"""
|
||||||
Logs a standardized banner indicating the start of a test case stage, with a three-line format.
|
Logs a fixed-width, left-aligned banner for a test case stage.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
stage (str): One of 'Setup', 'Execution', or 'Teardown'.
|
stage (str): One of 'Setup', 'Execution', or 'Teardown'.
|
||||||
test_name (str): The name of the test case.
|
test_name (str): The name of the test case.
|
||||||
|
total_width (int): Total banner width.
|
||||||
"""
|
"""
|
||||||
total_width = 60
|
banner_char = "="
|
||||||
banner_char = "=" # Change this to customize the banner character (e.g., '-', '#', '*')
|
|
||||||
|
|
||||||
banner_text = f"Starting {stage}: {test_name}"
|
|
||||||
inner_line = f" {banner_text} "
|
|
||||||
|
|
||||||
padding = max((total_width - len(inner_line)) // 2, 0)
|
|
||||||
middle_line = banner_char * padding + inner_line + banner_char * padding
|
|
||||||
|
|
||||||
if len(middle_line) < total_width:
|
|
||||||
middle_line += banner_char
|
|
||||||
|
|
||||||
border_line = banner_char * total_width
|
border_line = banner_char * total_width
|
||||||
|
content_line = f" Starting {stage}: {test_name}"
|
||||||
|
|
||||||
get_logger().log_info("") # clean line break
|
get_logger().log_info("") # clean line break
|
||||||
get_logger().log_info(border_line)
|
get_logger().log_info(border_line)
|
||||||
get_logger().log_info(middle_line)
|
get_logger().log_info(content_line)
|
||||||
get_logger().log_info(border_line)
|
get_logger().log_info(border_line)
|
||||||
|
Reference in New Issue
Block a user