4141)
4242from pyarrow .csv import write_csv
4343
44- MB = 1024 * 1024
44+ MB = 1024 * 1024
45+
46+
4547@pytest .fixture
4648def ctx ():
4749 return SessionContext ()
@@ -116,6 +118,7 @@ def clean_formatter_state():
116118 """Reset the HTML formatter after each test."""
117119 reset_formatter ()
118120
121+
119122# custom style for testing with html formatter
120123class CustomStyleProvider :
121124 def get_cell_style (self ) -> str :
@@ -130,17 +133,17 @@ def get_header_style(self) -> str:
130133 "padding: 10px; border: 1px solid #3367d6;"
131134 )
132135
136+
133137def count_table_rows (html_content : str ) -> int :
134138 """Count the number of table rows in HTML content.
135-
136139 Args:
137140 html_content: HTML string to analyze
138-
139141 Returns:
140142 Number of table rows found (number of <tr> tags)
141143 """
142144 return len (re .findall (r"<tr" , html_content ))
143145
146+
144147def test_select (df ):
145148 df_1 = df .select (
146149 column ("a" ) + column ("b" ),
@@ -929,23 +932,17 @@ def get_header_style(self) -> str:
929932
930933def test_html_formatter_memory (df , clean_formatter_state ):
931934 """Test the memory and row control parameters in DataFrameHtmlFormatter."""
932- configure_formatter (
933- max_memory_bytes = 10 ,
934- min_rows_display = 1
935- )
935+ configure_formatter (max_memory_bytes = 10 , min_rows_display = 1 )
936936 html_output = df ._repr_html_ ()
937-
937+
938938 # Count the number of table rows in the output
939939 tr_count = count_table_rows (html_output )
940940 # With a tiny memory limit of 10 bytes, the formatter should display
941941 # the minimum number of rows (1) plus a message about truncation
942942 assert tr_count == 2 # 1 for header row, 1 for data row
943- assert "data truncated" in html_output .lower ()
944-
945- configure_formatter (
946- max_memory_bytes = 10 * MB ,
947- min_rows_display = 1
948- )
943+ assert "data truncated" in html_output .lower ()
944+
945+ configure_formatter (max_memory_bytes = 10 * MB , min_rows_display = 1 )
949946 html_output = df ._repr_html_ ()
950947 # With larger memory limit and min_rows=2, should display all rows
951948 tr_count = count_table_rows (html_output )
@@ -954,40 +951,35 @@ def test_html_formatter_memory(df, clean_formatter_state):
954951 # No truncation message should appear
955952 assert "data truncated" not in html_output .lower ()
956953
954+
957955def test_html_formatter_repr_rows (df , clean_formatter_state ):
958- configure_formatter (
959- min_rows_display = 2 ,
960- repr_rows = 2
961- )
956+ configure_formatter (min_rows_display = 2 , repr_rows = 2 )
962957 html_output = df ._repr_html_ ()
963-
958+
964959 tr_count = count_table_rows (html_output )
965960 # Tabe should have header row (1) + 2 data rows = 3 rows
966961 assert tr_count == 3
967-
968- configure_formatter (
969- min_rows_display = 2 ,
970- repr_rows = 3
971- )
962+
963+ configure_formatter (min_rows_display = 2 , repr_rows = 3 )
972964 html_output = df ._repr_html_ ()
973-
965+
974966 tr_count = count_table_rows (html_output )
975967 # Tabe should have header row (1) + 3 data rows = 4 rows
976968 assert tr_count == 4
977-
978-
969+
970+
979971def test_html_formatter_validation ():
980972 # Test validation for invalid parameters
981-
973+
982974 with pytest .raises (ValueError , match = "max_cell_length must be a positive integer" ):
983975 DataFrameHtmlFormatter (max_cell_length = 0 )
984-
976+
985977 with pytest .raises (ValueError , match = "max_width must be a positive integer" ):
986978 DataFrameHtmlFormatter (max_width = 0 )
987-
979+
988980 with pytest .raises (ValueError , match = "max_height must be a positive integer" ):
989981 DataFrameHtmlFormatter (max_height = 0 )
990-
982+
991983 with pytest .raises (ValueError , match = "max_memory_bytes must be a positive integer" ):
992984 DataFrameHtmlFormatter (max_memory_bytes = 0 )
993985
@@ -1012,51 +1004,51 @@ def test_configure_formatter(df, clean_formatter_state):
10121004 parameters."""
10131005
10141006 # these are non-default values
1015- MAX_CELL_LENGTH = 10
1016- MAX_WIDTH = 500
1017- MAX_HEIGHT = 30
1018- MAX_MEMORY_BYTES = 3 * MB
1019- MIN_ROWS_DISPLAY = 2
1020- REPR_ROWS = 2
1021- ENABLE_CELL_EXPANSION = False
1022- SHOW_TRUNCATION_MESSAGE = False
1023- USE_SHARED_STYLES = False
1024-
1007+ max_cell_length = 10
1008+ max_width = 500
1009+ max_height = 30
1010+ max_memory_bytes = 3 * MB
1011+ min_rows_display = 2
1012+ repr_rows = 2
1013+ enable_cell_expansion = False
1014+ show_truncation_message = False
1015+ use_shared_styles = False
1016+
10251017 reset_formatter ()
10261018 formatter_default = get_formatter ()
1027-
1028- assert formatter_default .max_cell_length != MAX_CELL_LENGTH
1029- assert formatter_default .max_width != MAX_WIDTH
1030- assert formatter_default .max_height != MAX_HEIGHT
1031- assert formatter_default .max_memory_bytes != MAX_MEMORY_BYTES
1032- assert formatter_default .min_rows_display != MIN_ROWS_DISPLAY
1033- assert formatter_default .repr_rows != REPR_ROWS
1034- assert formatter_default .enable_cell_expansion != ENABLE_CELL_EXPANSION
1035- assert formatter_default .show_truncation_message != SHOW_TRUNCATION_MESSAGE
1036- assert formatter_default .use_shared_styles != USE_SHARED_STYLES
1037-
1019+
1020+ assert formatter_default .max_cell_length != max_cell_length
1021+ assert formatter_default .max_width != max_width
1022+ assert formatter_default .max_height != max_height
1023+ assert formatter_default .max_memory_bytes != max_memory_bytes
1024+ assert formatter_default .min_rows_display != min_rows_display
1025+ assert formatter_default .repr_rows != repr_rows
1026+ assert formatter_default .enable_cell_expansion != enable_cell_expansion
1027+ assert formatter_default .show_truncation_message != show_truncation_message
1028+ assert formatter_default .use_shared_styles != use_shared_styles
1029+
10381030 # Configure with custom style provider and additional parameters
10391031 configure_formatter (
1040- max_cell_length = MAX_CELL_LENGTH ,
1041- max_width = MAX_WIDTH ,
1042- max_height = MAX_HEIGHT ,
1043- max_memory_bytes = MAX_MEMORY_BYTES ,
1044- min_rows_display = MIN_ROWS_DISPLAY ,
1045- repr_rows = REPR_ROWS ,
1046- enable_cell_expansion = ENABLE_CELL_EXPANSION ,
1047- show_truncation_message = SHOW_TRUNCATION_MESSAGE ,
1048- use_shared_styles = USE_SHARED_STYLES
1032+ max_cell_length = max_cell_length ,
1033+ max_width = max_width ,
1034+ max_height = max_height ,
1035+ max_memory_bytes = max_memory_bytes ,
1036+ min_rows_display = min_rows_display ,
1037+ repr_rows = repr_rows ,
1038+ enable_cell_expansion = enable_cell_expansion ,
1039+ show_truncation_message = show_truncation_message ,
1040+ use_shared_styles = use_shared_styles ,
10491041 )
10501042 formatter_custom = get_formatter ()
1051- assert formatter_custom .max_cell_length == MAX_CELL_LENGTH
1052- assert formatter_custom .max_width == MAX_WIDTH
1053- assert formatter_custom .max_height == MAX_HEIGHT
1054- assert formatter_custom .max_memory_bytes == MAX_MEMORY_BYTES
1055- assert formatter_custom .min_rows_display == MIN_ROWS_DISPLAY
1056- assert formatter_custom .repr_rows == REPR_ROWS
1057- assert formatter_custom .enable_cell_expansion == ENABLE_CELL_EXPANSION
1058- assert formatter_custom .show_truncation_message == SHOW_TRUNCATION_MESSAGE
1059- assert formatter_custom .use_shared_styles == USE_SHARED_STYLES
1043+ assert formatter_custom .max_cell_length == max_cell_length
1044+ assert formatter_custom .max_width == max_width
1045+ assert formatter_custom .max_height == max_height
1046+ assert formatter_custom .max_memory_bytes == max_memory_bytes
1047+ assert formatter_custom .min_rows_display == min_rows_display
1048+ assert formatter_custom .repr_rows == repr_rows
1049+ assert formatter_custom .enable_cell_expansion == enable_cell_expansion
1050+ assert formatter_custom .show_truncation_message == show_truncation_message
1051+ assert formatter_custom .use_shared_styles == use_shared_styles
10601052
10611053
10621054def test_get_dataframe (tmp_path ):
@@ -1788,4 +1780,3 @@ def test_html_formatter_manual_format_html(clean_formatter_state):
17881780
17891781 assert "<style>" in local_html_1
17901782 assert "<style>" in local_html_2
1791-
0 commit comments