Skip to content

Commit

Permalink
Bokeh 3 - Fix tests (#4140)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored and philippjfr committed Jan 17, 2023
1 parent 848251f commit 24f163f
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 58 deletions.
6 changes: 4 additions & 2 deletions panel/io/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def show_embed(
states)
publish_display_data(*render_model(model))

def ipywidget(obj: Any, **kwargs: Any):
def ipywidget(obj: Any, doc=None, **kwargs: Any):
"""
Returns an ipywidget model which renders the Panel object.
Expand All @@ -380,6 +380,8 @@ def ipywidget(obj: Any, **kwargs: Any):
---------
obj: object
Any Panel object or object which can be rendered with Panel
doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
**kwargs: dict
Keyword arguments passed to the pn.panel utility function
Expand All @@ -390,7 +392,7 @@ def ipywidget(obj: Any, **kwargs: Any):
from jupyter_bokeh.widgets import BokehModel

from ..pane import panel
model = panel(obj, **kwargs).get_root()
model = panel(obj, **kwargs).get_root(doc=doc)
widget = BokehModel(model, combine_events=True)
if hasattr(widget, '_view_count'):
widget._view_count = 0
Expand Down
14 changes: 5 additions & 9 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import param

from packaging.version import Version
from param.parameterized import classlist, discard_events

from .config import config
Expand All @@ -32,8 +31,8 @@
from .pane.base import PaneBase, ReplacementPane
from .reactive import Reactive
from .util import (
abbreviated_repr, bokeh_version, classproperty, full_groupby, fullpath,
get_method_owner, is_parameterized, param_name, recursive_parameterized,
abbreviated_repr, classproperty, full_groupby, fullpath, get_method_owner,
is_parameterized, param_name, recursive_parameterized,
)
from .viewable import Layoutable, Viewable
from .widgets import (
Expand Down Expand Up @@ -178,7 +177,7 @@ class Param(PaneBase):
param.CalendarDate: DatePicker,
param.Color: ColorPicker,
param.Date: DatetimeInput,
param.DateRange: DateRangeSlider,
param.DateRange: DatetimeRangeSlider,
param.CalendarDateRange: DateRangeSlider,
param.DataFrame: DataFrameWidget,
param.Dict: LiteralInputTyped,
Expand All @@ -200,9 +199,6 @@ class Param(PaneBase):
if hasattr(param, 'Event'):
mapping[param.Event] = Button

if bokeh_version >= Version('2.4.3'):
mapping[param.DateRange] = DatetimeRangeSlider

priority: ClassVar[float | bool | None] = 0.1

_unpack: ClassVar[bool] = True
Expand Down Expand Up @@ -267,7 +263,7 @@ def __repr__(self, depth=0):
parameters = [k for k in params if k != 'name']
params = []
for p, v in sorted(self.param.values().items()):
if v is self.param[p].default: continue
if v == self.param[p].default: continue
elif v is None: continue
elif isinstance(v, str) and v == '': continue
elif p == 'object' or (p == 'name' and (v.startswith(obj_cls) or v.startswith(cls))): continue
Expand All @@ -286,7 +282,7 @@ def __repr__(self, depth=0):

@property
def _synced_params(self):
ignored_params = ['default_layout', 'loading']
ignored_params = ['default_layout', 'loading', 'background']
return [p for p in Layoutable.param if p not in ignored_params]

def _update_widgets(self, *events):
Expand Down
7 changes: 4 additions & 3 deletions panel/tests/io/test_notebook.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from panel.io.notebook import ipywidget
from panel.pane import Str

from ..util import jb_available
from ..util import bokeh3_failing_all, jb_available


@bokeh3_failing_all
@jb_available
def test_ipywidget():
def test_ipywidget(document):
pane = Str('A')
widget = ipywidget(pane)
widget = ipywidget(pane, doc=document)

assert widget._view_count == 0
assert len(pane._models) == 1
Expand Down
6 changes: 5 additions & 1 deletion panel/tests/io/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from panel.io.resources import CDN_DIST
from panel.models.vega import VegaPlot
from panel.pane import Alert, Vega
from panel.tests.util import hv_available
from panel.tests.util import bokeh3_failing, hv_available

vega_example = {
'config': {
Expand All @@ -30,6 +30,7 @@
}


@bokeh3_failing
def test_save_external():
sio = StringIO()
pane = Vega(vega_example)
Expand All @@ -41,6 +42,7 @@ def test_save_external():
assert js.replace(config.npm_cdn, f'{CDN_DIST}bundled/vegaplot') in html


@bokeh3_failing
def test_save_inline_resources():
alert = Alert('# Save test')

Expand All @@ -51,6 +53,7 @@ def test_save_inline_resources():
assert '.bk.alert-primary' in html


@bokeh3_failing
def test_save_cdn_resources():
alert = Alert('# Save test')

Expand All @@ -61,6 +64,7 @@ def test_save_cdn_resources():
assert re.findall('https://cdn.holoviz.org/panel/(.*)/dist/css/alerts.css', html)


@bokeh3_failing
@hv_available
def test_static_path_in_holoviews_save(tmpdir):
import holoviews as hv
Expand Down
4 changes: 2 additions & 2 deletions panel/tests/pane/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_pane_layout_properties(pane, document, comm):


@pytest.mark.parametrize('pane', all_panes+[Bokeh])
def test_pane_linkable_params(pane):
def test_pane_linkable_params(pane, document, comm):
try:
p = pane()
except ImportError:
Expand All @@ -46,7 +46,7 @@ def test_pane_linkable_params(pane):

try:
CallbackGenerator.error = True
layout.get_root()
layout.get_root(document, comm)
except Exception as e:
raise e
finally:
Expand Down
2 changes: 1 addition & 1 deletion panel/tests/pane/test_holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,5 +591,5 @@ def test_holoviews_property_override(document, comm):
css_classes=['test_class'])
model = pane.get_root(document, comm=comm)

assert model.background == 'red'
assert model.styles["background"] == 'red'
assert model.css_classes == ['test_class']
4 changes: 2 additions & 2 deletions panel/tests/pane/test_perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
}


def test_perspective_int_cols():
def test_perspective_int_cols(document, comm):
psp = Perspective(
data, columns=[0], aggregates={0: 'mean'}, sort=[[0, 'desc']],
row_pivots=[0], column_pivots=[0], filters=[[0, '==', 'None']]
)

model = psp.get_root()
model = psp.get_root(document, comm)
assert '0' in model.source.data
assert model.columns == ['0']
assert model.group_by == ['0']
Expand Down
8 changes: 4 additions & 4 deletions panel/tests/template/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
from panel.template import VanillaTemplate


def test_notification_instantiate_on_config():
def test_notification_instantiate_on_config(document):
with config.set(notifications=True):
tmpl = VanillaTemplate()

assert isinstance(tmpl.notifications, NotificationArea)

doc = tmpl.server_doc()
doc = tmpl.server_doc(document)

with set_curdoc(doc):
assert state.notifications is tmpl.notifications


def test_notification_explicit():
def test_notification_explicit(document):
tmpl = VanillaTemplate(notifications=NotificationArea())

assert isinstance(tmpl.notifications, NotificationArea)

doc = tmpl.server_doc()
doc = tmpl.server_doc(document)

with set_curdoc(doc):
assert state.notifications is tmpl.notifications
4 changes: 3 additions & 1 deletion panel/tests/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ def test(a):
assert new_pane._models[column.ref['id']][0] is new_div

interact_pane._cleanup(column)
assert len(interact_pane._callbacks) == 3
assert len(interact_pane._callbacks) == 4
# Note one of the callbacks is Viewable._set_background
# the counter should be reduced when this function is removed.


def test_interact_throttled():
Expand Down
7 changes: 6 additions & 1 deletion panel/tests/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ def test_text_input_controls():
assert not not_checked

assert isinstance(wb2, WidgetBox)
assert len(wb2) == len(list(Viewable.param)) + 1

params1 = {w.name.replace(" ", "_").lower() for w in wb2 if len(w.name)}
params2 = set(Viewable.param) - {"background"}
# Background should be moved when Layoutable.background is removed.

assert not len(params1 - params2)
assert not len(params2 - params1)


def test_text_input_controls_explicit():
Expand Down
8 changes: 7 additions & 1 deletion panel/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from panel.pane import Markdown
from panel.reactive import ReactiveHTML
from panel.template import BootstrapTemplate
from panel.tests.util import wait_until
from panel.tests.util import bokeh3_failing, bokeh3_failing_all, wait_until
from panel.widgets import (
Button, Tabulator, Terminal, TextInput,
)
Expand Down Expand Up @@ -154,6 +154,7 @@ def test_server_extensions_on_root(port):
assert r.ok


@bokeh3_failing
def test_autoload_js(port):
html = Markdown('# Title')
app_name = 'test'
Expand Down Expand Up @@ -292,6 +293,10 @@ def app2():
assert CSS2 in r2


# This test seem to fail if run after:
# - test_server_async_local_state_nested_tasks
# - test_server_async_local_state
@bokeh3_failing_all
def test_server_session_info(port):
with config.set(session_history=-1):
html = Markdown('# Title')
Expand Down Expand Up @@ -822,6 +827,7 @@ def test_server_component_css_with_prefix_relative_url(port):
assert 'href="static/extensions/panel/bundled/terminal/[email protected]/css/xterm.css' in content


@bokeh3_failing_all
def test_server_component_css_with_subpath_and_prefix_relative_url(port):
component = Terminal()

Expand Down
3 changes: 2 additions & 1 deletion panel/tests/test_viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
from panel.pane import Markdown, Str, panel
from panel.viewable import Viewable, Viewer

from .util import jb_available
from .util import bokeh3_failing_all, jb_available

all_viewables = [w for w in param.concrete_descendents(Viewable).values()
if not w.__name__.startswith('_') and
not issubclass(w, interactive)]

@bokeh3_failing_all
@jb_available
def test_viewable_ipywidget():
pane = Str('A')
Expand Down
29 changes: 26 additions & 3 deletions panel/tests/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import sys
import time
import warnings

import numpy as np
import pytest

from packaging.version import Version

import panel as pn

from panel.io.server import serve

# Ignore tests which are not yet working with Bokeh 3.
# Will begin to fail again when the first rc is released.
bokeh3_failing = pytest.mark.xfail(
not Version(pn.__version__).is_prerelease,
reason="Bokeh 3: Not working yet"
)
# These tests passes when running alone
# but will fail when running with all the other tests
bokeh3_failing_all = pytest.mark.skipif(
not Version(pn.__version__).is_prerelease,
reason="Bokeh 3: Not working when running all tests"
)


try:
import holoviews as hv
hv_version = Version(hv.__version__)
Expand Down Expand Up @@ -54,8 +71,14 @@ def mpl_figure():


def check_layoutable_properties(layoutable, model):
layoutable.background = '#ffffff'
assert model.background == '#ffffff'
layoutable.styles = {"background": '#fffff0'}
assert model.styles["background"] == '#fffff0'

# Is deprecated, but we still support it for now.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
layoutable.background = '#ffffff'
assert model.styles["background"] == '#ffffff'

layoutable.css_classes = ['custom_class']
if isinstance(layoutable, Markdown):
Expand All @@ -82,7 +105,7 @@ def check_layoutable_properties(layoutable, model):
assert model.max_width == 550

layoutable.margin = 10
assert model.margin == (10, 10, 10, 10)
assert model.margin == 10

layoutable.sizing_mode = 'stretch_width'
assert model.sizing_mode == 'stretch_width'
Expand Down
4 changes: 2 additions & 2 deletions panel/tests/widgets/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def test_widget_signature(widget):


@pytest.mark.parametrize('widget', all_widgets)
def test_widget_linkable_params(widget):
def test_widget_linkable_params(widget, document, comm):
w = widget()
controls = w.controls(jslink=True)
layout = Row(w, controls)

try:
CallbackGenerator.error = True
layout.get_root()
layout.get_root(document, comm)
finally:
CallbackGenerator.error = False

Expand Down
Loading

0 comments on commit 24f163f

Please sign in to comment.