Here are the examples of the python api bokeh.resources.Resources taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
21 Examples
3
View Source File : html.py
License : BSD 3-Clause "New" or "Revised" License
Project Creator : holzschu
License : BSD 3-Clause "New" or "Revised" License
Project Creator : holzschu
def file_contents(self, args, doc):
'''
'''
resources = Resources(mode="cdn", root_dir=None)
return file_html(doc, resources)
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
3
View Source File : test_export.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_get_screenshot_as_png_with_unicode_minified(webdriver):
p = figure(title="유니 코드 지원을위한 작은 테스트")
png = bie.get_screenshot_as_png(p, driver=webdriver, resources=Resources(mode="inline", minified=True))
assert len(png.tobytes()) > 0
@pytest.mark.unit
3
View Source File : test_export.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_get_screenshot_as_png_with_unicode_unminified(webdriver):
p = figure(title="유니 코드 지원을위한 작은 테스트")
png = bie.get_screenshot_as_png(p, driver=webdriver, resources=Resources(mode="inline", minified=False))
assert len(png.tobytes()) > 0
@pytest.mark.unit
3
View Source File : test_output.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_with_args(self, mock_run_notebook_hook):
load_jupyter_args = (Resources(), True, True, 1000)
bio.output_notebook(*load_jupyter_args)
assert mock_run_notebook_hook.call_count == 1
assert mock_run_notebook_hook.call_args[0] == ("jupyter", "load") + load_jupyter_args
assert mock_run_notebook_hook.call_args[1] == {}
@patch('bokeh.io.state.State.reset')
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_log_level(self):
r = resources.Resources()
for level in LOG_LEVELS:
r.log_level = level
assert r.log_level == level
if not r.dev:
assert r.js_raw[-1] == 'Bokeh.set_log_level("%s");' % level
with pytest.raises(ValueError):
setattr(r, "log_level", "foo")
def test_module_attrs(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_inline(self):
r = resources.Resources(mode="inline")
assert r.mode == "inline"
assert r.dev == False
assert len(r.js_raw) == 5
assert r.js_raw[-1] == DEFAULT_LOG_JS_RAW
assert len(r.css_raw) == 3
assert r.messages == []
def test_get_cdn_urls(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_server_default(self):
r = resources.Resources(mode="server")
assert r.mode == "server"
assert r.dev == False
assert r.js_raw == [DEFAULT_LOG_JS_RAW]
assert r.css_raw == []
assert r.messages == []
assert r.js_files == ['http://localhost:5006/static/js/bokeh.min.js',
'http://localhost:5006/static/js/bokeh-widgets.min.js',
'http://localhost:5006/static/js/bokeh-tables.min.js',
'http://localhost:5006/static/js/bokeh-gl.min.js']
assert r.css_files == ['http://localhost:5006/static/css/bokeh.min.css',
'http://localhost:5006/static/css/bokeh-widgets.min.css',
'http://localhost:5006/static/css/bokeh-tables.min.css']
def test_server_root_url(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_server_root_url(self):
r = resources.Resources(mode="server", root_url="http://foo/")
assert r.js_raw == [DEFAULT_LOG_JS_RAW]
assert r.css_raw == []
assert r.messages == []
assert r.js_files == ['http://foo/static/js/bokeh.min.js',
'http://foo/static/js/bokeh-widgets.min.js',
'http://foo/static/js/bokeh-tables.min.js',
'http://foo/static/js/bokeh-gl.min.js']
assert r.css_files == ['http://foo/static/css/bokeh.min.css',
'http://foo/static/css/bokeh-widgets.min.css',
'http://foo/static/css/bokeh-tables.min.css']
def test_server_root_url_empty(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_server_root_url_empty(self):
r = resources.Resources(mode="server", root_url="")
assert r.js_raw == [DEFAULT_LOG_JS_RAW]
assert r.css_raw == []
assert r.messages == []
assert r.js_files == ['static/js/bokeh.min.js',
'static/js/bokeh-widgets.min.js',
'static/js/bokeh-tables.min.js',
'static/js/bokeh-gl.min.js']
assert r.css_files == ['static/css/bokeh.min.css',
'static/css/bokeh-widgets.min.css',
'static/css/bokeh-tables.min.css']
def test_server_with_versioner(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_server_with_versioner(self):
def versioner(path):
return path + "?v=VERSIONED"
r = resources.Resources(mode="server", root_url="http://foo/",
path_versioner=versioner)
assert r.js_files == ['http://foo/static/js/bokeh.min.js?v=VERSIONED',
'http://foo/static/js/bokeh-widgets.min.js?v=VERSIONED',
'http://foo/static/js/bokeh-tables.min.js?v=VERSIONED',
'http://foo/static/js/bokeh-gl.min.js?v=VERSIONED']
assert r.css_files == ['http://foo/static/css/bokeh.min.css?v=VERSIONED',
'http://foo/static/css/bokeh-widgets.min.css?v=VERSIONED',
'http://foo/static/css/bokeh-tables.min.css?v=VERSIONED']
def test_server_dev(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_server_dev(self):
r = resources.Resources(mode="server-dev")
assert r.mode == "server"
assert r.dev == True
assert len(r.js_raw) == 2
assert r.css_raw == []
assert r.messages == []
r = resources.Resources(mode="server-dev", root_url="http://foo/")
assert r.js_raw == [DEFAULT_LOG_JS_RAW, "Bokeh.settings.dev = true"]
assert r.css_raw == []
assert r.messages == []
def test_relative(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_relative(self):
r = resources.Resources(mode="relative")
assert r.mode == "relative"
assert r.dev == False
assert r.js_raw == [DEFAULT_LOG_JS_RAW]
assert r.css_raw == []
assert r.messages == []
def test_relative_dev(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_relative_dev(self):
r = resources.Resources(mode="relative-dev")
assert r.mode == "relative"
assert r.dev == True
assert r.js_raw == [DEFAULT_LOG_JS_RAW, "Bokeh.settings.dev = true"]
assert r.css_raw == []
assert r.messages == []
def test_absolute(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_absolute(self):
r = resources.Resources(mode="absolute")
assert r.mode == "absolute"
assert r.dev == False
assert r.js_raw == [DEFAULT_LOG_JS_RAW]
assert r.css_raw == []
assert r.messages == []
def test_absolute_dev(self):
3
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_absolute_dev(self):
r = resources.Resources(mode="absolute-dev")
assert r.mode == "absolute"
assert r.dev == True
assert r.js_raw == [DEFAULT_LOG_JS_RAW, "Bokeh.settings.dev = true"]
assert r.css_raw == []
assert r.messages == []
def test_argument_checks(self):
0
View Source File : consumers.py
License : BSD 3-Clause "New" or "Revised" License
Project Creator : holzschu
License : BSD 3-Clause "New" or "Revised" License
Project Creator : holzschu
def resources(self, absolute_url: Optional[str] = None) -> Resources:
root_url = urljoin(absolute_url, self._prefix) if absolute_url else self._prefix
return Resources(mode="server", root_url=root_url, path_versioner=StaticHandler.append_version)
class SessionConsumer(AsyncHttpConsumer, ConsumerHelper):
0
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_basic(self):
r = resources.Resources()
assert r.mode == "inline"
def test_log_level(self):
0
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_argument_checks(self):
with pytest.raises(ValueError):
resources.Resources("foo")
for mode in ("inline", "cdn", "server", "server-dev", "absolute", "absolute-dev"):
with pytest.raises(ValueError):
resources.Resources(mode, root_dir="foo")
for mode in ("inline", "server", "server-dev", "relative", "relative-dev", "absolute", "absolute-dev"):
with pytest.raises(ValueError):
resources.Resources(mode, version="foo")
for mode in ("inline", "cdn", "relative", "relative-dev", "absolute", "absolute-dev"):
with pytest.raises(ValueError):
resources.Resources(mode, root_url="foo")
## Test external resources
def test_external_js_and_css_resource_embedding():
0
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_external_js_and_css_resource_embedding():
""" This test method has to be at the end of the test modules because
subclassing a Model causes the CustomModel to be added as a MetaModel and
messes up the Resources state for the other tests.
"""
# External resources can be defined as a string or list of strings
class CustomModel1(Model):
__javascript__ = "external_js_1"
__css__ = "external_css_1"
class CustomModel2(Model):
__javascript__ = ["external_js_2", "external_js_3"]
__css__ = ["external_css_2", "external_css_3"]
class CustomModel3(Model):
__javascript__ = ["external_js_1", "external_js_3"]
__css__ = ["external_css_1", "external_css_2"]
r = resources.Resources()
assert "external_js_1" in r.js_files
assert "external_css_1" in r.css_files
assert "external_js_2" in r.js_files
assert "external_js_3" in r.js_files
assert "external_css_2" in r.css_files
assert "external_css_3" in r.css_files
# Deduplication should keep the first instance of every file
assert r.css_files.count("external_css_1") == 1
assert r.css_files.count("external_css_2") == 1
assert r.js_files.count("external_js_3") == 1
assert r.js_files.count("external_js_1") == 1
def test_external_js_and_css_resource_ordering():
0
View Source File : test_resources.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_external_js_and_css_resource_ordering():
class ZClass(Model):
__javascript__ = "z_class"
class AClass(Model):
__javascript__ = "a_class"
r = resources.Resources()
# a_class is before z_class because they're sorted alphabetically
assert r.js_files.index("a_class") < r.js_files.index("z_class")
# The files should be in the order defined by the lists in CustomModel2 and CustomModel3
assert r.css_files.index("external_css_3") > r.css_files.index("external_css_2")
assert r.js_files.index("external_js_3") > r.js_files.index("external_js_2")
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
0
View Source File : __init__.py
License : Apache License 2.0
Project Creator : spotify
License : Apache License 2.0
Project Creator : spotify
def set_display_settings():
"""Enable notebook output settings if running in a jupyter notebook"""
from IPython.core.getipython import get_ipython
from ipykernel.zmqshell import ZMQInteractiveShell
from bokeh.io import output_notebook
from bokeh.resources import Resources
from bokeh.io.state import curstate
ipython_instance = get_ipython()
if ipython_instance is not None:
if isinstance(ipython_instance, ZMQInteractiveShell):
_IPYTHON_INSTANCE = True
# Defer to previous call to ``output_notebook`` so that users
# can specify their own notebook type and Bokeh resources
if curstate().notebook_type is None:
# Inline resources uses bokeh.js from the local version.
# This enables offline usage.
output_notebook(Resources('inline'), hide_banner=True)
set_display_settings()