def test_return_type(self, test_plot): class fake_template: def __init__(self, tester, user_template_variables=None): self.tester = tester self.template_variables = { "title", "bokeh_js", "bokeh_css", "plot_script", "doc", "docs", "base", } if user_template_variables is not None: self.template_variables.update(user_template_variables) def render(self, template_variables): assert self.template_variables.issubset(set(template_variables.keys())) return "template result" r = bes.file_html(test_plot, CDN, "title") assert isinstance(r, str) r = bes.file_html(test_plot, CDN, "title", fake_template(self)) assert isinstance(r, str) r = bes.file_html(test_plot, CDN, "title", fake_template(self, {"test_var"}), {"test_var": "test"}) assert isinstance(r, str)
def test_file_html_provides_warning_if_no_js(self, mock_warn: MagicMock, test_plot: figure) -> None: css_resources = CSSResources() bes.file_html(test_plot, (None, css_resources), "title") mock_warn.assert_called_once_with( 'No Bokeh JS Resources provided to template. If required you will need to provide them manually.' )
def test_return_type(self, test_plot): class fake_template: def __init__(self, tester, user_template_variables=None): self.tester = tester self.template_variables = { "title", "bokeh_js", "bokeh_css", "plot_script", "doc", "docs", "base", } if user_template_variables is not None: self.template_variables.update(user_template_variables) def render(self, template_variables): assert self.template_variables.issubset( set(template_variables.keys())) return "template result" r = bes.file_html(test_plot, CDN, "title") assert isinstance(r, str) r = bes.file_html(test_plot, CDN, "title", fake_template(self)) assert isinstance(r, str) r = bes.file_html(test_plot, CDN, "title", fake_template(self, {"test_var"}), {"test_var": "test"}) assert isinstance(r, str)
def test_file_html_provides_warning_if_no_css(self, mock_warn, test_plot) -> None: js_resources = JSResources() bes.file_html(test_plot, (js_resources, None), "title") mock_warn.assert_called_once_with( 'No Bokeh CSS Resources provided to template. If required you will need to provide them manually.' )
def test_file_html_handles_css_only_resources(self, mock_warn, test_plot): css_resources = CSSResources(mode="relative", components=["bokeh"]) template = Template("<head>{{ bokeh_css }}</head><body></body>") output = bes.file_html(test_plot, (None, css_resources), "title", template=template) html = "<head>%s</head><body></body>" % css_resources.render_css() assert output == html
def test_file_html_handles_js_only_resources(self, mock_warn: MagicMock, test_plot: figure) -> None: js_resources = JSResources(mode="relative", components=["bokeh"]) template = Template("<head>{{ bokeh_js }}</head><body></body>") output = bes.file_html(test_plot, (js_resources, None), "title", template=template) html = "<head>%s</head><body></body>" % js_resources.render_js() assert output == html
def test_return_type(self, test_plot: figure) -> None: class fake_template: def __init__( self, tester: Any, user_template_variables: Set[str] | None = None) -> None: self.tester = tester self.template_variables = { "title", "bokeh_js", "bokeh_css", "plot_script", "doc", "docs", "base", } if user_template_variables is not None: self.template_variables.update(user_template_variables) def render(self, template_variables: Dict[str, Any]) -> str: assert self.template_variables.issubset( set(template_variables.keys())) return "template result" r = bes.file_html(test_plot, CDN, "title") assert isinstance(r, str) r = bes.file_html( test_plot, CDN, "title", template=fake_template(self)) # type: ignore[arg-type] assert isinstance(r, str) r = bes.file_html( test_plot, CDN, "title", template=fake_template(self, {"test_var"}), # type: ignore[arg-type] template_variables={"test_var": "test"}) assert isinstance(r, str)
def test_entire_doc_is_not_used(self) -> None: from bokeh.document import Document from bokeh.models import Button fig = figure() fig.x([0], [0]) button = Button(label="Button") d = Document() d.add_root(fig) d.add_root(button) out = bes.file_html([fig], CDN) # this is a very coarse test but it will do assert "bokeh-widgets" not in out
def test_entire_doc_is_not_used(self): from bokeh.document import Document from bokeh.models import Button fig = figure() fig.x([0], [0]) button = Button(label="Button") d = Document() d.add_root(fig) d.add_root(button) out = bes.file_html([fig], CDN) # this is a very coarse test but it will do assert "bokeh-widgets" not in out
def test_file_html_title_is_escaped(self, test_plot: figure) -> None: r = bes.file_html(test_plot, CDN, "&<") assert "<title>&<</title>" in r
def test_file_html_title_is_escaped(self, test_plot): r = bes.file_html(test_plot, CDN, "&<") assert "<title>&<</title>" in r
def test_file_html_provides_warning_if_no_js(self, mock_warn, test_plot): css_resources = CSSResources() bes.file_html(test_plot, (None, css_resources), "title") mock_warn.assert_called_once_with( 'No Bokeh JS Resources provided to template. If required you will need to provide them manually.' )
def test_file_html_handles_css_only_resources(self, mock_warn, test_plot): css_resources = CSSResources(mode="relative", components=["bokeh"]) template = Template("<head>{{ bokeh_css }}</head><body></body>") output = bes.file_html(test_plot, (None, css_resources), "title", template=template) html = encode_utf8("<head>%s</head><body></body>" % css_resources.render_css()) assert output == html