Skip to content

Commit 1b15ef0

Browse files
committed
add testcase
1 parent 94c05d7 commit 1b15ef0

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

@@ -684,6 +686,23 @@ def test_widget_with_unknown_row_count_empty_dataframe(
684686
assert widget.page == 0
685687

686688

687-
# TODO(shuowei): Add tests for custom index and multiindex
689+
def test_repr_html_anywidget_fallback(paginated_bf_df: bf.dataframe.DataFrame):
690+
"""
691+
Test that _repr_html_ falls back to deferred mode when anywidget is not available.
692+
"""
693+
with bf.option_context("display.repr_mode", "anywidget"):
694+
# Use a mock to simulate the absence of the 'anywidget' module.
695+
with mock.patch.dict(
696+
"sys.modules", {"anywidget": None, "IPython": mock.MagicMock()}
697+
):
698+
# The warning is now expected inside the _ipython_display_ call, not _repr_html_
699+
# The test setup doesn't easily allow capturing warnings from ipython display hooks.
700+
# Instead we focus on the fallback behavior of _repr_html_
701+
html = paginated_bf_df._repr_html_()
702+
assert "Computation deferred." in html
703+
assert "Computation will process" in html
704+
705+
706+
# TODO(b/332316283): Add tests for custom index and multiindex
688707
# This may not be necessary for the SQL Cell use case but should be
689708
# considered for completeness.

0 commit comments

Comments
 (0)