def test_constructor(): """Test that an Alert can be instantiated""" alert = Alert(text="This is some text") # pylint: disable=no-member assert set(alert.css_classes) == { "alert", f"alert-{Alert.param.alert_type.default}" }
def test_existing_css_classes(): """Test that an alert can change alert_type""" alert = Alert(text="This is some text", css_classes=["important"]) assert set(alert.css_classes) == {"alert", f"alert-{Alert.param.alert_type.default}", "important"} alert.alert_type="info" assert set(alert.css_classes) == {"alert", "alert-info", "important"}
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)
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_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_all_view(): """Test that we can construct and view all Alerts""" alerts = [] for alert_type in ALERT_TYPES: text = f"""\ This is a **{alert_type}** alert with [an example link](https://panel.holoviz.org/). Give it a click if you like.""" alert = Alert(text=text, alert_type=alert_type) alerts.append(alert) assert "alert" in alert.css_classes assert f"alert-{alert_type}" in alert.css_classes return pn.Column(*alerts, sizing_mode="stretch_width")
def test_all_view(): """Test that we can construct and view all Alerts""" alerts = [] for alert_type in ALERT_TYPES: text = f"""\ This is a **{alert_type}** alert with [an example link](https://panel.holoviz.org/). Give it a click if you like.""" alert = Alert(object=text, alert_type=alert_type) alert_app = pn.Column( alert, pn.Param( alert, parameters=["object", "alert_type"], widgets={"object": pn.widgets.TextAreaInput}, ), ) alerts.append(alert_app) assert "alert" in alert.css_classes assert f"alert-{alert_type}" in alert.css_classes return pn.Column(*alerts, margin=50)
def test_alert_type_change(alert_type): """Test that an alert can change alert_type""" alert = Alert(text="This is some text") alert.alert_type = alert_type assert set(alert.css_classes) == {"alert", f"alert-{alert_type}"}