Example #1
0
    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)
Example #2
0
 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.'
     )
Example #3
0
    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)
Example #4
0
 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.'
     )
Example #5
0
 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
Example #6
0
 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
Example #7
0
    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)
Example #8
0
    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
Example #9
0
    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
Example #10
0
 def test_file_html_title_is_escaped(self, test_plot: figure) -> None:
     r = bes.file_html(test_plot, CDN, "&<")
     assert "<title>&amp;&lt;</title>" in r
Example #11
0
 def test_file_html_title_is_escaped(self, test_plot):
     r = bes.file_html(test_plot, CDN, "&<")
     assert "<title>&amp;&lt;</title>" in r
Example #12
0
 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.'
     )
Example #13
0
 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