Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Apr 17, 2024
1 parent 82ab659 commit 2ddb91a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions holoviews/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def ibis_sqlite_backend():

@pytest.fixture
def bokeh_backend():
if not hv.extension._loaded:
hv.extension("bokeh")
hv.renderer("bokeh")
prev_backend = hv.Store.current_backend
hv.Store.current_backend = "bokeh"
Expand All @@ -74,6 +76,8 @@ def bokeh_backend():

@pytest.fixture
def mpl_backend():
if not hv.extension._loaded:
hv.extension("matplotlib")
hv.renderer("matplotlib")
prev_backend = hv.Store.current_backend
hv.Store.current_backend = "matplotlib"
Expand All @@ -83,6 +87,8 @@ def mpl_backend():

@pytest.fixture
def plotly_backend():
if not hv.extension._loaded:
hv.extension("plotly")
hv.renderer("plotly")
prev_backend = hv.Store.current_backend
hv.Store.current_backend = "plotly"
Expand Down
53 changes: 53 additions & 0 deletions holoviews/tests/ui/bokeh/test_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from datetime import timedelta

import numpy as np
import pandas as pd
import pytest
from bokeh.sampledata.stocks import AAPL

import holoviews as hv
from holoviews.plotting.links import RangeToolLink

from .. import expect

pytestmark = pytest.mark.ui


@pytest.mark.usefixtures("bokeh_backend")
@pytest.mark.parametrize(
["index", "intervalsx", "x_range_src", "x_range_tgt"],
[
(range(len(AAPL["date"])), (100, 365), (0, 365), (0, 3269)),
(
pd.to_datetime(AAPL["date"]),
(timedelta(days=100), timedelta(days=365)),
(
np.array(["2000-03-01"], dtype="datetime64[ns]")[0],
pd.Timestamp("2001-03-01"),
),
np.array(["2000-03-01", "2013-03-01"], dtype="datetime64[ns]"),
),
],
ids=["int", "datetime"],
)
def test_rangetool_link_interval(serve_hv, index, intervalsx, x_range_src, x_range_tgt):
df = pd.DataFrame(AAPL["close"], columns=["close"], index=index)
df.index.name = "Date"

aapl_curve = hv.Curve(df, "Date", ("close", "Price ($)"))
tgt = aapl_curve.relabel("AAPL close price").opts(width=800, labelled=["y"])
src = aapl_curve.opts(width=800, height=100, yaxis=None)

RangeToolLink(src, tgt, axes=["x", "y"], intervalsx=intervalsx)
layout = (tgt + src).cols(1)
layout.opts(hv.opts.Layout(shared_axes=False))

page = serve_hv(layout)
hv_plot = page.locator(".bk-events")
expect(hv_plot).to_have_count(2)

bk_model = hv.render(layout)
bk_src = bk_model.children[0][0]
np.testing.assert_equal((bk_src.x_range.start, bk_src.x_range.end), x_range_src)
bk_tgt = bk_model.children[1][0]
np.testing.assert_equal((bk_tgt.x_range.start, bk_tgt.x_range.end), x_range_tgt)

0 comments on commit 2ddb91a

Please sign in to comment.