Refactor text extraction in Micron renderer for improved attribute access
- Updated the text extraction logic to use public attributes instead of private ones, enhancing readability and maintainability. - Adjusted corresponding unit tests to reflect the changes in attribute access.
This commit is contained in:
@@ -565,12 +565,10 @@ def render_micron(content: str, ascii_art_scale: float = 0.75) -> ft.Control:
|
||||
)
|
||||
|
||||
text_content = ""
|
||||
if hasattr(control, "_Text__spans") and control._Text__spans:
|
||||
text_content = "".join(span.text for span in control._Text__spans)
|
||||
elif hasattr(control, "_Control__attrs") and "text" in control._Control__attrs:
|
||||
text_content = control._Control__attrs["text"][0]
|
||||
elif hasattr(control, "_Control__attrs") and "value" in control._Control__attrs:
|
||||
text_content = control._Control__attrs["value"][0]
|
||||
if hasattr(control, "spans") and control.spans:
|
||||
text_content = "".join(span.text for span in control.spans)
|
||||
elif hasattr(control, "value") and control.value:
|
||||
text_content = control.value
|
||||
else:
|
||||
text_content = ""
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ class TestMicronRenderer:
|
||||
for control in result.controls:
|
||||
assert isinstance(control, ft.Text)
|
||||
# Extract text from the merged control
|
||||
if hasattr(control, "_Control__attrs") and "value" in control._Control__attrs:
|
||||
all_text += control._Control__attrs["value"][0]
|
||||
if hasattr(control, "value") and control.value:
|
||||
all_text += control.value
|
||||
|
||||
# Should preserve the content
|
||||
assert content in all_text
|
||||
@@ -139,8 +139,8 @@ class TestRendererComparison:
|
||||
for control in micron_result.controls:
|
||||
if isinstance(control, ft.Text):
|
||||
# Extract text from the merged control
|
||||
if hasattr(control, "_Control__attrs") and "value" in control._Control__attrs:
|
||||
micron_text += control._Control__attrs["value"][0] + "\n"
|
||||
if hasattr(control, "value") and control.value:
|
||||
micron_text += control.value + "\n"
|
||||
|
||||
# Remove trailing newline and compare
|
||||
micron_text = micron_text.rstrip("\n")
|
||||
|
||||
Reference in New Issue
Block a user