Skip to content

Commit 2267243

Browse files
committed
refactor: improve HTML formatter tests by updating import statements and enhancing regex patterns for body data
1 parent 768f977 commit 2267243

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

python/tests/test_dataframe.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
)
3434
from datafusion.expr import Window
3535
from datafusion.html_formatter import (
36+
DataFrameHtmlFormatter,
3637
configure_formatter,
3738
get_formatter,
3839
reset_formatter,
40+
reset_styles_loaded_state,
3941
)
4042
from pyarrow.csv import write_csv
4143

@@ -1514,19 +1516,15 @@ def test_dataframe_repr_html_structure(df) -> None:
15141516
# between the <th></th> and <td></td>. We also don't want the closing > on the
15151517
# td and th segments because that is where the formatting data is written.
15161518

1517-
# Test for headers - this part works fine
15181519
headers = ["a", "b", "c"]
15191520
headers = [f"<th(.*?)>{v}</th>" for v in headers]
15201521
header_pattern = "(.*?)".join(headers)
15211522
header_matches = re.findall(header_pattern, output, re.DOTALL)
15221523
assert len(header_matches) == 1
15231524

1524-
# The problem is with the body pattern - values are now wrapped in spans
15251525
# Update the pattern to handle values that may be wrapped in spans
15261526
body_data = [[1, 4, 8], [2, 5, 5], [3, 6, 8]]
15271527

1528-
# Create a more flexible pattern that can match both direct values and values
1529-
# in spans
15301528
body_lines = [
15311529
f"<td(.*?)>(?:<span[^>]*?>)?{v}(?:</span>)?</td>"
15321530
for inner in body_data
@@ -1570,10 +1568,6 @@ def test_dataframe_repr_html_values(df):
15701568

15711569
def test_html_formatter_shared_styles(df, clean_formatter_state):
15721570
"""Test that shared styles work correctly across multiple tables."""
1573-
from datafusion.html_formatter import (
1574-
configure_formatter,
1575-
reset_styles_loaded_state,
1576-
)
15771571

15781572
# First, ensure we're using shared styles
15791573
configure_formatter(use_shared_styles=True)
@@ -1603,7 +1597,6 @@ def test_html_formatter_shared_styles(df, clean_formatter_state):
16031597

16041598
def test_html_formatter_no_shared_styles(df, clean_formatter_state):
16051599
"""Test that styles are always included when shared styles are disabled."""
1606-
from datafusion.html_formatter import configure_formatter
16071600

16081601
# Configure formatter to NOT use shared styles
16091602
configure_formatter(use_shared_styles=False)
@@ -1621,12 +1614,6 @@ def test_html_formatter_no_shared_styles(df, clean_formatter_state):
16211614

16221615
def test_html_formatter_manual_format_html(clean_formatter_state):
16231616
"""Test direct usage of format_html method with shared styles."""
1624-
import pyarrow as pa
1625-
from datafusion.html_formatter import (
1626-
DataFrameHtmlFormatter,
1627-
get_formatter,
1628-
reset_styles_loaded_state,
1629-
)
16301617

16311618
# Create sample data
16321619
batch = pa.RecordBatch.from_arrays(

0 commit comments

Comments
 (0)