From 3624b5f5074e5366ab82945878db6d22b370aec6 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 30 Sep 2021 12:36:12 +0200 Subject: [PATCH] Resolve issues with inline resources on save (#2794) * Fix saving using inline resources * Add tests --- panel/io/save.py | 2 +- panel/tests/io/test_save.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/panel/io/save.py b/panel/io/save.py index ee20d66334..88e16cc8e0 100644 --- a/panel/io/save.py +++ b/panel/io/save.py @@ -252,7 +252,7 @@ def save(panel, filename, title=None, resources=None, template=None, resources = Resources.from_bokeh(resources) # Set resource mode - with set_resource_mode(mode): + with set_resource_mode(resources): html = file_html(doc, resources, title, **kwargs) if hasattr(filename, 'write'): if isinstance(filename, io.BytesIO): diff --git a/panel/tests/io/test_save.py b/panel/tests/io/test_save.py index 265c14a774..f0b7ce31e5 100644 --- a/panel/tests/io/test_save.py +++ b/panel/tests/io/test_save.py @@ -1,6 +1,8 @@ +import re + from io import StringIO -from panel.pane import Vega +from panel.pane import Alert, Vega from panel.models.vega import VegaPlot @@ -30,3 +32,23 @@ def test_save_external(): html = sio.read() for js in VegaPlot.__javascript_raw__: assert js in html + + +def test_save_inline_resources(): + alert = Alert('# Save test') + + sio = StringIO() + alert.save(sio, resources='inline') + sio.seek(0) + html = sio.read() + assert '.bk.alert-primary' in html + + +def test_save_cdn_resources(): + alert = Alert('# Save test') + + sio = StringIO() + alert.save(sio, resources='cdn') + sio.seek(0) + html = sio.read() + assert re.findall('https://unpkg.com/@holoviz/panel@(.*)/dist/css/alerts.css', html)