@@ -1495,23 +1495,49 @@ def add_with_parameter(df_internal, value: Any) -> DataFrame:
14951495
14961496def test_dataframe_repr_html_structure (df ) -> None :
14971497 """Test that DataFrame._repr_html_ produces expected HTML output structure."""
1498+ import re
14981499
14991500 output = df ._repr_html_ ()
15001501
1502+ # Debug prints to understand the actual HTML structure
1503+ print ("\n \n ----- HTML Output Sample -----" )
1504+ print (output [:500 ]) # Print first 500 chars to see the structure
1505+
15011506 # Since we've added a fair bit of processing to the html output, lets just verify
15021507 # the values we are expecting in the table exist. Use regex and ignore everything
15031508 # between the <th></th> and <td></td>. We also don't want the closing > on the
15041509 # td and th segments because that is where the formatting data is written.
15051510
1511+ # Test for headers - this part works fine
15061512 headers = ["a" , "b" , "c" ]
15071513 headers = [f"<th(.*?)>{ v } </th>" for v in headers ]
15081514 header_pattern = "(.*?)" .join (headers )
1509- assert len (re .findall (header_pattern , output , re .DOTALL )) == 1
1515+ header_matches = re .findall (header_pattern , output , re .DOTALL )
1516+ assert len (header_matches ) == 1
15101517
1518+ # The problem is with the body pattern - values are now wrapped in spans
1519+ # Update the pattern to handle values that may be wrapped in spans
15111520 body_data = [[1 , 4 , 8 ], [2 , 5 , 5 ], [3 , 6 , 8 ]]
1512- body_lines = [f"<td(.*?)>{ v } </td>" for inner in body_data for v in inner ]
1521+
1522+ # Create a more flexible pattern that can match both direct values and values in spans
1523+ body_lines = [
1524+ f"<td(.*?)>(?:<span[^>]*?>)?{ v } (?:</span>)?</td>"
1525+ for inner in body_data
1526+ for v in inner
1527+ ]
15131528 body_pattern = "(.*?)" .join (body_lines )
1514- assert len (re .findall (body_pattern , output , re .DOTALL )) == 1
1529+
1530+ # For debugging
1531+ print ("\n ----- Regex Pattern -----" )
1532+ print (body_pattern [:100 ] + "..." ) # Print part of the pattern
1533+
1534+ body_matches = re .findall (body_pattern , output , re .DOTALL )
1535+
1536+ # Print match info for debugging
1537+ print (f"\n ----- Match Results -----" )
1538+ print (f"Found { len (body_matches )} matches" )
1539+
1540+ assert len (body_matches ) == 1 , "Expected pattern of values not found in HTML output"
15151541
15161542
15171543def test_dataframe_repr_html_values (df ):
0 commit comments