16
16
import pytest
17
17
18
18
import bigframes as bf
19
+ from bigframes .display import TableWidget
19
20
20
21
pytest .importorskip ("anywidget" )
21
22
22
23
23
24
@pytest .fixture (scope = "module" )
24
25
def paginated_pandas_df () -> pd .DataFrame :
25
- """Create a test DataFrame with exactly 3 pages of manually defined data."""
26
26
"""Create a minimal test DataFrame with exactly 3 pages of 2 rows each."""
27
27
test_data = pd .DataFrame (
28
28
{
@@ -52,13 +52,11 @@ def paginated_bf_df(
52
52
53
53
54
54
@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 :
56
56
"""
57
57
Helper fixture to create a TableWidget instance with a fixed page size.
58
58
This reduces duplication across tests that use the same widget configuration.
59
59
"""
60
- from bigframes .display import TableWidget
61
-
62
60
with bf .option_context ("display.repr_mode" , "anywidget" , "display.max_rows" , 2 ):
63
61
widget = TableWidget (paginated_bf_df )
64
62
return widget
@@ -86,24 +84,46 @@ def _assert_html_matches_pandas_slice(
86
84
assert row ["page_indicator" ] not in table_html
87
85
88
86
89
- def test_repr_anywidget_initialization_set_correct_defaults (
87
+ def test_repr_anywidget_initialization_sets_page_to_zero (
90
88
paginated_bf_df : bf .dataframe .DataFrame ,
91
- paginated_pandas_df : pd .DataFrame ,
92
89
):
93
- """
94
- A TableWidget should initialize with correct default values.
95
- """
90
+ """A TableWidget should initialize with the page number set to 0."""
96
91
with bf .option_context ("display.repr_mode" , "anywidget" ):
97
92
from bigframes .display import TableWidget
98
93
99
94
widget = TableWidget (paginated_bf_df )
100
95
101
96
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
+
102
108
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
+
103
121
assert widget .row_count == len (paginated_pandas_df )
104
122
105
123
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
+ ):
107
127
"""
108
128
Given a widget, when it is first loaded, then it should display
109
129
the first page of data.
@@ -115,7 +135,9 @@ def test_repr_anywidget_display_first_page_on_load(table_widget, paginated_panda
115
135
_assert_html_matches_pandas_slice (html , expected_slice , paginated_pandas_df )
116
136
117
137
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
+ ):
119
141
"""
120
142
Given a widget, when the page is set to 1, then it should display
121
143
the second page of data.
@@ -129,7 +151,9 @@ def test_repr_anywidget_navigate_to_second_page(table_widget, paginated_pandas_d
129
151
_assert_html_matches_pandas_slice (html , expected_slice , paginated_pandas_df )
130
152
131
153
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
+ ):
133
157
"""
134
158
Given a widget, when the page is set to the last page (2),
135
159
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)
144
168
145
169
146
170
def 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
148
172
):
149
173
"""
150
174
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(
160
184
161
185
162
186
def 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
164
188
):
165
189
"""
166
190
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(
187
211
],
188
212
)
189
213
def 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 ,
191
219
):
192
220
"""
193
221
A widget should paginate correctly with a custom page size of 3.
0 commit comments