From 3fdfa3248d1bd838fee88af6a277bf94eeaad87a Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 2 Nov 2020 10:38:00 +0100 Subject: [PATCH] Fix changing of alert_type on Alert pane (#1734) * Fix changing of alert_type on Alert pane * Fixed Markdown test --- panel/pane/alert.py | 2 +- panel/pane/markup.py | 2 +- panel/tests/pane/test_alert.py | 6 +++++- panel/tests/util.py | 7 ++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/panel/pane/alert.py b/panel/pane/alert.py index d9d279a27c..d9cb1b2acb 100644 --- a/panel/pane/alert.py +++ b/panel/pane/alert.py @@ -21,7 +21,7 @@ class Alert(Markdown): priority = 0 - _rename=dict(Markdown._rename, alert_type=None) + _rename = dict(Markdown._rename, alert_type=None) @classmethod def applies(cls, obj): diff --git a/panel/pane/markup.py b/panel/pane/markup.py index 487172ff4c..fbdf2af23b 100644 --- a/panel/pane/markup.py +++ b/panel/pane/markup.py @@ -269,7 +269,7 @@ class Markdown(DivPaneBase): _target_transforms = {'object': None} - _rerender_params = ['object', 'dedent', 'extensions'] + _rerender_params = ['object', 'dedent', 'extensions', 'css_classes'] @classmethod def applies(cls, obj): diff --git a/panel/tests/pane/test_alert.py b/panel/tests/pane/test_alert.py index 03df660629..6431c325d2 100644 --- a/panel/tests/pane/test_alert.py +++ b/panel/tests/pane/test_alert.py @@ -16,13 +16,17 @@ def test_constructor(): @pytest.mark.parametrize(["alert_type"], [(alert_type,) for alert_type in ALERT_TYPES]) -def test_alert_type_change(alert_type): +def test_alert_type_change(alert_type, document, comm): """Test that an alert can change alert_type""" alert = Alert(text="This is some text") + model = alert.get_root(document, comm) + alert.alert_type = alert_type assert set(alert.css_classes) == {"alert", f"alert-{alert_type}"} + assert set(model.css_classes) == {"alert", f"alert-{alert_type}", "markdown"} + def test_existing_css_classes(): """Test that an alert can change alert_type""" alert = Alert(text="This is some text", css_classes=["important"]) diff --git a/panel/tests/util.py b/panel/tests/util.py index e99c44255a..8442bc1815 100644 --- a/panel/tests/util.py +++ b/panel/tests/util.py @@ -41,6 +41,8 @@ py3_only = pytest.mark.skipif(sys.version_info.major < 3, reason="requires Python 3") +from panel.pane.markup import Markdown + def mpl_figure(): import matplotlib.pyplot as plt @@ -56,7 +58,10 @@ def check_layoutable_properties(layoutable, model): assert model.background == '#ffffff' layoutable.css_classes = ['custom_class'] - assert model.css_classes == ['custom_class'] + if isinstance(layoutable, Markdown): + assert model.css_classes == ['custom_class', 'markdown'] + else: + assert model.css_classes == ['custom_class'] layoutable.width = 500 assert model.width == 500