bokeh.io.state.State

Here are the examples of the python api bokeh.io.state.State taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

13 Examples 7

3 View Source File : test_showing.py
License : MIT License
Project Creator : rthorst

def test__show_with_state_with_no_notebook(mock_get_browser_controller,
                                           mock__show_file_with_state,
                                           mock_show_doc,
                                           mock_get_comms):
    mock_get_browser_controller.return_value = "controller"
    mock_get_comms.return_value = "comms"
    s = State()

    s.output_file("foo.html")
    bis._show_with_state("obj", s, "browser", "new")
    assert s.notebook_type == None

    assert mock_show_doc.call_count == 0

    assert mock__show_file_with_state.call_count == 1
    assert mock__show_file_with_state.call_args[0] == ("obj", s, "new", "controller")
    assert mock__show_file_with_state.call_args[1] == {}

@patch('os.path.abspath')

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_creation(self):
        s = bis.State()
        assert isinstance(s.document, Document)
        assert s.file == None
        assert s.notebook == False

    def test_default_file_resources(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_default_file_resources(self):
        s = bis.State()
        s.output_file("foo.html")
        assert s.file['resources'].minified, True

    def test_output_file(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_output_file(self):
        s = bis.State()
        s.output_file("foo.html")
        assert s.file['filename'] == "foo.html"
        assert s.file['title'] == "Bokeh Plot"
        assert s.file['resources'].log_level == 'info'
        assert s.file['resources'].minified == True

    @patch('bokeh.io.state.log')

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_output_file_file_exists(self, mock_isfile, mock_log):
        mock_isfile.return_value = True
        s = bis.State()
        s.output_file("foo.html")
        assert s.file['filename'] == "foo.html"
        assert s.file['title'] == "Bokeh Plot"
        assert s.file['resources'].log_level == 'info'
        assert s.file['resources'].minified == True
        assert mock_log.info.call_count == 1
        assert mock_log.info.call_args[0] == (
            "Session output file 'foo.html' already exists, will be overwritten.",
        )

    def test_output_notebook_noarg(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_output_notebook_noarg(self):
        s = bis.State()
        s.output_notebook()
        assert s.notebook == True
        assert s.notebook_type == 'jupyter'

    def test_output_notebook_witharg(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_output_notebook_witharg(self):
        s = bis.State()
        s.output_notebook(notebook_type='notjup')
        assert s.notebook == True
        assert s.notebook_type == 'notjup'

    def test_output_invalid_notebook(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_output_invalid_notebook(self):
        s = bis.State()
        with pytest.raises(Exception):
            s.notebook_type=None
        with pytest.raises(Exception):
            s.notebook_type=10

    def test_reset(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_reset(self):
        s = bis.State()
        d = s.document
        s.output_file("foo.html")
        s.output_notebook()
        s.reset()
        assert s.file == None
        assert s.notebook == False
        assert isinstance(s.document, Document)
        assert s.document != d

    def test_doc_set(self):

3 View Source File : test_state.py
License : MIT License
Project Creator : rthorst

    def test_doc_set(self):
        s = bis.State()
        d = Document()
        s.document = d
        assert isinstance(s.document, Document)
        assert s.document == d

def test_curstate():

0 View Source File : test_notebook.py
License : MIT License
Project Creator : rthorst

def test_show_doc_no_server(mock_notebook_content,
                            mock__publish_display_data,
                            mock_get_comms):
    mock_get_comms.return_value = "comms"
    s = State()
    d = Document()
    mock_notebook_content.return_value = ["notebook_script", "notebook_div", d]

    class Obj(object):
        id = None
        def references(self): return []

    assert mock__publish_display_data.call_count == 0
    binb.show_doc(Obj(), s, True)

    expected_args = ({'application/javascript': 'notebook_script', 'application/vnd.bokehjs_exec.v0+json': ''},)
    expected_kwargs = {'metadata': {'application/vnd.bokehjs_exec.v0+json': {'id': None}}}

    assert d._hold is not None
    assert mock__publish_display_data.call_count == 2 # two mime types
    assert mock__publish_display_data.call_args[0] == expected_args
    assert mock__publish_display_data.call_args[1] == expected_kwargs

class Test_push_notebook(object):

0 View Source File : test_showing.py
License : MIT License
Project Creator : rthorst

def test__show_with_state_with_notebook(mock_get_browser_controller,
                                        mock__show_file_with_state,
                                        mock_run_notebook_hook):
    mock_get_browser_controller.return_value = "controller"
    s = State()

    p = Plot()

    s.output_notebook()
    bis._show_with_state(p, s, "browser", "new")
    assert s.notebook_type == "jupyter"

    assert mock_run_notebook_hook.call_count == 1
    assert mock_run_notebook_hook.call_args[0] == ("jupyter", "doc", p, s, False)
    assert mock_run_notebook_hook.call_args[1] == {}

    assert mock__show_file_with_state.call_count == 0

    s.output_file("foo.html")
    bis._show_with_state(p, s, "browser", "new")
    assert s.notebook_type == "jupyter"

    assert mock_run_notebook_hook.call_count == 2
    assert mock_run_notebook_hook.call_args[0] == ("jupyter", "doc", p, s, False)
    assert mock_run_notebook_hook.call_args[1] == {}

    assert mock__show_file_with_state.call_count == 1
    assert mock__show_file_with_state.call_args[0] == (p, s, "new", "controller")
    assert mock__show_file_with_state.call_args[1] == {}

@patch('bokeh.io.notebook.get_comms')

0 View Source File : test_showing.py
License : MIT License
Project Creator : rthorst

def test(mock_save, mock_abspath):
    controller = Mock()
    mock_save.return_value = "savepath"

    s = State()
    s.output_file("foo.html")

    bis._show_file_with_state("obj", s, "window", controller)

    assert mock_save.call_count == 1
    assert mock_save.call_args[0] == ("obj",)
    assert mock_save.call_args[1] == {"state": s}

    assert controller.open.call_count == 1
    assert controller.open.call_args[0] == ("file://savepath",)
    assert controller.open.call_args[1] == {"new": 1}

    bis._show_file_with_state("obj", s, "tab", controller)

    assert mock_save.call_count == 2
    assert mock_save.call_args[0] == ("obj",)
    assert mock_save.call_args[1] == {"state": s}

    assert controller.open.call_count == 2
    assert controller.open.call_args[0] == ("file://savepath",)
    assert controller.open.call_args[1] == {"new": 2}

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------