Ejemplo n.º 1
0
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}
Ejemplo n.º 2
0
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}
Ejemplo n.º 3
0
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] == {}
Ejemplo n.º 4
0
def callback():
    global i
    ds.data['x'].append(xlist[i])
    ds.data['y'].append(ylist[i])
    ds.trigger('data', ds.data, ds.data)
    if i < xlist.shape[0] - 1:
        i = i + 1
    else:
        new.reset()
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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] == {}
Ejemplo n.º 7
0
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] == {}
Ejemplo n.º 8
0
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] == {}