Skip to content

Commit f8dbb22

Browse files
committed
add testcase
1 parent c35bb35 commit f8dbb22

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/system/small/test_anywidget.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515

16+
import unittest.mock as mock
17+
1618
import pandas as pd
1719
import pytest
1820

@@ -549,6 +551,23 @@ def test_widget_row_count_reflects_actual_data_available(
549551
assert widget.page_size == 2 # Respects the display option
550552

551553

552-
# TODO(shuowei): Add tests for custom index and multiindex
554+
def test_repr_html_anywidget_fallback(paginated_bf_df: bf.dataframe.DataFrame):
555+
"""
556+
Test that _repr_html_ falls back to deferred mode when anywidget is not available.
557+
"""
558+
with bf.option_context("display.repr_mode", "anywidget"):
559+
# Use a mock to simulate the absence of the 'anywidget' module.
560+
with mock.patch.dict(
561+
"sys.modules", {"anywidget": None, "IPython": mock.MagicMock()}
562+
):
563+
# The warning is now expected inside the _ipython_display_ call, not _repr_html_
564+
# The test setup doesn't easily allow capturing warnings from ipython display hooks.
565+
# Instead we focus on the fallback behavior of _repr_html_
566+
html = paginated_bf_df._repr_html_()
567+
assert "Computation deferred." in html
568+
assert "Computation will process" in html
569+
570+
571+
# TODO(b/332316283): Add tests for custom index and multiindex
553572
# This may not be necessary for the SQL Cell use case but should be
554573
# considered for completeness.

0 commit comments

Comments
 (0)