Skip to content

Commit 1c0130b

Browse files
committed
working UI test
1 parent 8d88024 commit 1c0130b

1 file changed

Lines changed: 21 additions & 84 deletions

File tree

holoviews/tests/ui/bokeh/test_hover.py

Lines changed: 21 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -519,94 +519,31 @@ def test_hover_heatmap_image(serve_hv, x_axis_type, y_axis_type):
519519

520520
# UI regression tests for https://github.com/holoviz/holoviews/pull/6438
521521
@pytest.mark.usefixtures("bokeh_backend")
522-
def test_hover_heatmap_categorical_outside_plot_area(serve_hv):
523-
heatmap = hv.HeatMap([('A', 'X', 1), ('B', 'Y', 2), ('C', 'Z', 3)]).opts(tools=["hover"], colorbar=True)
522+
def test_hover_heatmap_categorical_outside_plot_area(serve_hv, caplog):
523+
df = pd.DataFrame([
524+
[0, "A", 10],
525+
[0, "B", 20],
526+
[1, "A", 20],
527+
[1, "B", 30]
528+
], columns=["key1", "key2", "value"])
529+
530+
ds = hv.Dataset(df)
531+
heatmap = ds.to(hv.HeatMap, kdims=["key1", "key2"], vdims="value").opts(tools=["hover"])
532+
533+
hv.streams.PointerXY(source=heatmap)
524534

525535
page = serve_hv(heatmap)
526536
hv_plot = page.locator(".bk-events")
527537
expect(hv_plot).to_have_count(1)
528538
bbox = hv_plot.bounding_box()
539+
page.mouse.wheel(0, 1000)
529540

530-
# Hover over valid points - should show tooltips
531-
page.mouse.move(bbox["x"] + bbox["width"] * 0.25, bbox["y"] + bbox["height"] * 0.25)
532-
page.mouse.up()
533-
expect(page.locator(".bk-Tooltip")).to_have_count(1)
534-
expect(page.locator(".bk-Tooltip")).to_contain_text("x: A")
535-
expect(page.locator(".bk-Tooltip")).to_contain_text("y: Z")
536-
537-
# Hover far outside the plot area - should not crash
538-
page.mouse.move(bbox["x"] + bbox["width"] * 1.5, bbox["y"] + bbox["height"] / 2)
539-
page.mouse.up()
540-
expect(page.locator(".bk-Tooltip")).to_have_count(0)
541-
page.wait_for_timeout(100)
542-
543-
# Hover far below the plot - should not crash
544-
page.mouse.move(bbox["x"] + bbox["width"] / 2, bbox["y"] + bbox["height"] * 1.5)
545-
page.mouse.up()
546-
expect(page.locator(".bk-Tooltip")).to_have_count(0)
547-
page.wait_for_timeout(100)
548-
549-
# Hover far to the left - should not crash
550-
page.mouse.move(bbox["x"] - 50, bbox["y"] + bbox["height"] / 2)
551-
page.mouse.up()
552-
expect(page.locator(".bk-Tooltip")).to_have_count(0)
553-
page.wait_for_timeout(100)
541+
import logging
542+
with caplog.at_level(logging.ERROR):
543+
# Scroll and hover above the plot
544+
page.mouse.move(bbox["x"] + bbox["width"] * 0.5, 10)
545+
page.mouse.up()
546+
page.wait_for_timeout(100)
554547

555-
# Hover far above - should not crash
556-
page.mouse.move(bbox["x"] + bbox["width"] / 2, bbox["y"] - 50)
557-
page.mouse.up()
558-
expect(page.locator(".bk-Tooltip")).to_have_count(0)
559-
page.wait_for_timeout(100)
560-
561-
# Verify we can still hover over valid points after hovering outside
562-
page.mouse.move(bbox["x"] + bbox["width"] * 0.25, bbox["y"] + bbox["height"] * 0.25)
563-
page.mouse.up()
564-
expect(page.locator(".bk-Tooltip")).to_have_count(1)
565-
566-
567-
@pytest.mark.usefixtures("bokeh_backend")
568-
def test_tap_heatmap_categorical_outside_plot_area(serve_hv):
569-
from holoviews import streams
570-
571-
heatmap = hv.HeatMap([('A', 'X', 1), ('B', 'Y', 2), ('C', 'Z', 3)]).opts(colorbar=True)
572-
573-
# Create a stream to track tap events
574-
tap_stream = streams.SingleTap(source=heatmap)
575-
576-
# Create a DynamicMap that displays tap coordinates
577-
def show_tap(x, y):
578-
if x is not None and y is not None:
579-
return hv.Text(0.5, 0.5, f'Tapped: ({x}, {y})', halign='center', valign='center')
580-
return hv.Text(0.5, 0.5, 'No tap yet', halign='center', valign='center')
581-
582-
tap_display = hv.DynamicMap(show_tap, streams=[tap_stream])
583-
layout = heatmap + tap_display
584-
585-
page = serve_hv(layout)
586-
hv_plot = page.locator(".bk-events").first
587-
expect(hv_plot).to_be_visible()
588-
bbox = hv_plot.bounding_box()
589-
590-
# Click inside the plot - should work normally
591-
page.mouse.click(bbox["x"] + bbox["width"] * 0.25, bbox["y"] + bbox["height"] * 0.25)
592-
page.wait_for_timeout(100)
593-
594-
# Click far outside the plot area - should not crash
595-
page.mouse.click(bbox["x"] + bbox["width"] * 1.5, bbox["y"] + bbox["height"] / 2)
596-
page.wait_for_timeout(100)
597-
598-
# Click far below the plot - should not crash
599-
page.mouse.click(bbox["x"] + bbox["width"] / 2, bbox["y"] + bbox["height"] * 1.5)
600-
page.wait_for_timeout(100)
601-
602-
# Click far to the left - should not crash
603-
page.mouse.click(bbox["x"] - 50, bbox["y"] + bbox["height"] / 2)
604-
page.wait_for_timeout(100)
605-
606-
# Click far above - should not crash
607-
page.mouse.click(bbox["x"] + bbox["width"] / 2, bbox["y"] - 50)
608-
page.wait_for_timeout(100)
609-
610-
# Verify we can still click inside the plot after clicking outside
611-
page.mouse.click(bbox["x"] + bbox["width"] * 0.75, bbox["y"] + bbox["height"] * 0.75)
612-
page.wait_for_timeout(100)
548+
error_message = caplog.record_tuples[-1][-1]
549+
assert "IndexError" not in error_message

0 commit comments

Comments
 (0)