1616import pytest
1717
1818import bigframes as bf
19+ from bigframes .display import TableWidget
1920
2021pytest .importorskip ("anywidget" )
2122
2223
2324@pytest .fixture (scope = "module" )
2425def paginated_pandas_df () -> pd .DataFrame :
25- """Create a test DataFrame with exactly 3 pages of manually defined data."""
2626 """Create a minimal test DataFrame with exactly 3 pages of 2 rows each."""
2727 test_data = pd .DataFrame (
2828 {
@@ -52,13 +52,11 @@ def paginated_bf_df(
5252
5353
5454@pytest .fixture (scope = "module" )
55- def table_widget (paginated_bf_df : bf .dataframe .DataFrame ):
55+ def table_widget (paginated_bf_df : bf .dataframe .DataFrame ) -> TableWidget :
5656 """
5757 Helper fixture to create a TableWidget instance with a fixed page size.
5858 This reduces duplication across tests that use the same widget configuration.
5959 """
60- from bigframes .display import TableWidget
61-
6260 with bf .option_context ("display.repr_mode" , "anywidget" , "display.max_rows" , 2 ):
6361 widget = TableWidget (paginated_bf_df )
6462 return widget
@@ -86,24 +84,46 @@ def _assert_html_matches_pandas_slice(
8684 assert row ["page_indicator" ] not in table_html
8785
8886
89- def test_repr_anywidget_initialization_set_correct_defaults (
87+ def test_repr_anywidget_initialization_sets_page_to_zero (
9088 paginated_bf_df : bf .dataframe .DataFrame ,
91- paginated_pandas_df : pd .DataFrame ,
9289):
93- """
94- A TableWidget should initialize with correct default values.
95- """
90+ """A TableWidget should initialize with the page number set to 0."""
9691 with bf .option_context ("display.repr_mode" , "anywidget" ):
9792 from bigframes .display import TableWidget
9893
9994 widget = TableWidget (paginated_bf_df )
10095
10196 assert widget .page == 0
97+
98+
99+ def test_repr_anywidget_initialization_sets_page_size_from_options (
100+ paginated_bf_df : bf .dataframe .DataFrame ,
101+ ):
102+ """A TableWidget should initialize its page size from bf.options."""
103+ with bf .option_context ("display.repr_mode" , "anywidget" ):
104+ from bigframes .display import TableWidget
105+
106+ widget = TableWidget (paginated_bf_df )
107+
102108 assert widget .page_size == bf .options .display .max_rows
109+
110+
111+ def test_repr_anywidget_initialization_sets_row_count (
112+ paginated_bf_df : bf .dataframe .DataFrame ,
113+ paginated_pandas_df : pd .DataFrame ,
114+ ):
115+ """A TableWidget should initialize with the correct total row count."""
116+ with bf .option_context ("display.repr_mode" , "anywidget" ):
117+ from bigframes .display import TableWidget
118+
119+ widget = TableWidget (paginated_bf_df )
120+
103121 assert widget .row_count == len (paginated_pandas_df )
104122
105123
106- def test_repr_anywidget_display_first_page_on_load (table_widget , paginated_pandas_df ):
124+ def test_repr_anywidget_display_first_page_on_load (
125+ table_widget : TableWidget , paginated_pandas_df : pd .DataFrame
126+ ):
107127 """
108128 Given a widget, when it is first loaded, then it should display
109129 the first page of data.
@@ -115,7 +135,9 @@ def test_repr_anywidget_display_first_page_on_load(table_widget, paginated_panda
115135 _assert_html_matches_pandas_slice (html , expected_slice , paginated_pandas_df )
116136
117137
118- def test_repr_anywidget_navigate_to_second_page (table_widget , paginated_pandas_df ):
138+ def test_repr_anywidget_navigate_to_second_page (
139+ table_widget : TableWidget , paginated_pandas_df : pd .DataFrame
140+ ):
119141 """
120142 Given a widget, when the page is set to 1, then it should display
121143 the second page of data.
@@ -129,7 +151,9 @@ def test_repr_anywidget_navigate_to_second_page(table_widget, paginated_pandas_d
129151 _assert_html_matches_pandas_slice (html , expected_slice , paginated_pandas_df )
130152
131153
132- def test_repr_anywidget_navigate_to_last_page (table_widget , paginated_pandas_df ):
154+ def test_repr_anywidget_navigate_to_last_page (
155+ table_widget : TableWidget , paginated_pandas_df : pd .DataFrame
156+ ):
133157 """
134158 Given a widget, when the page is set to the last page (2),
135159 then it should display the final page of data.
@@ -144,7 +168,7 @@ def test_repr_anywidget_navigate_to_last_page(table_widget, paginated_pandas_df)
144168
145169
146170def test_repr_anywidget_page_clamp_to_zero_for_negative_input (
147- table_widget , paginated_pandas_df
171+ table_widget : TableWidget , paginated_pandas_df : pd . DataFrame
148172):
149173 """
150174 Given a widget, when a negative page number is set,
@@ -160,7 +184,7 @@ def test_repr_anywidget_page_clamp_to_zero_for_negative_input(
160184
161185
162186def test_repr_anywidget_page_clamp_to_last_page_for_out_of_bounds_input (
163- table_widget , paginated_pandas_df
187+ table_widget : TableWidget , paginated_pandas_df : pd . DataFrame
164188):
165189 """
166190 Given a widget, when a page number greater than the max is set,
@@ -187,7 +211,11 @@ def test_repr_anywidget_page_clamp_to_last_page_for_out_of_bounds_input(
187211 ],
188212)
189213def test_repr_anywidget_paginate_correctly_with_custom_page_size (
190- paginated_bf_df , paginated_pandas_df , page , start_row , end_row
214+ paginated_bf_df : bf .dataframe .DataFrame ,
215+ paginated_pandas_df : pd .DataFrame ,
216+ page : int ,
217+ start_row : int ,
218+ end_row : int ,
191219):
192220 """
193221 A widget should paginate correctly with a custom page size of 3.
0 commit comments