コード例 #1
0
    def test_no_notebook(self, mock_get_browser_controller,
                         mock__show_file_with_state,
                         mock__show_server_with_state,
                         mock__show_notebook_with_state, mock_get_comms):
        mock_get_browser_controller.return_value = "controller"
        mock_get_comms.return_value = "comms"
        s = io.State()

        s.output_file("foo.html")
        io._show_with_state("obj", s, "browser", "new")
        self.assertFalse(mock__show_notebook_with_state.called)
        self.assertFalse(mock__show_server_with_state.called)
        self._check_func_called(mock__show_file_with_state,
                                ("obj", s, "new", "controller"), {})

        s._session_coords = _SessionCoordinates(
            dict(session_id="fakesession",
                 url="http://example.com",
                 app_path='/'))
        s._server_enabled = True
        io._show_with_state("obj", s, "browser", "new")
        self.assertFalse(mock__show_notebook_with_state.called)
        self._check_func_called(mock__show_server_with_state,
                                ("obj", s, "new", "controller"), {})
        self._check_func_called(mock__show_file_with_state,
                                ("obj", s, "new", "controller"), {})
コード例 #2
0
    def test_notebook(self, mock_get_browser_controller,
                      mock__show_file_with_state, mock__show_server_with_state,
                      mock__show_notebook_with_state):
        mock_get_browser_controller.return_value = "controller"
        s = io.State()
        s.output_notebook()
        io._show_with_state("obj", s, "browser", "new")
        self._check_func_called(mock__show_notebook_with_state,
                                ("obj", s, False), {})
        self.assertFalse(mock__show_server_with_state.called)
        self.assertFalse(mock__show_file_with_state.called)

        s.output_file("foo.html")
        io._show_with_state("obj", s, "browser", "new")
        self._check_func_called(mock__show_notebook_with_state,
                                ("obj", s, False), {})
        self.assertFalse(mock__show_server_with_state.called)
        self._check_func_called(mock__show_file_with_state,
                                ("obj", s, "new", "controller"), {})

        s._session = Mock
        io._show_with_state("obj", s, "browser", "new")
        self._check_func_called(mock__show_notebook_with_state,
                                ("obj", s, False), {})
        self.assertFalse(mock__show_server_with_state.called)
        self._check_func_called(mock__show_file_with_state,
                                ("obj", s, "new", "controller"), {})
コード例 #3
0
    def test_no_server(self, mock_notebook_div, mock_publish_display_data):
        s = io.State()
        s._session = None
        mock_notebook_div.return_value = "notebook_div"

        io._show_notebook_with_state("obj", s)
        self._check_func_called(mock_publish_display_data, ({"text/html": "notebook_div"},), {})
コード例 #4
0
ファイル: test_io.py プロジェクト: tsaaii/bokeh
    def test_no_server(self, mock_notebook_content, mock_publish_display_data,
                       mock_get_comms):
        mock_get_comms.return_value = "comms"
        s = io.State()
        mock_notebook_content.return_value = [
            "notebook_script", "notebook_div"
        ]

        class Obj(object):
            _id = None

        io._nb_loaded = True
        io._show_jupyter_doc_with_state(Obj(), s, True)
        io._nb_loaded = False

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

        self._check_func_called(mock_publish_display_data, expected_args,
                                expected_kwargs)
コード例 #5
0
    def test_with_server(self, mock_push, mock_autoload_server, mock_publish_display_data):
        s = io.State()
        s._session_id = "fakesession"
        mock_autoload_server.return_value = "snippet"

        io._show_notebook_with_state("obj", s)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(mock_publish_display_data, ({"text/html":"snippet"},), {})
コード例 #6
0
    def test_no_server(self, mock_notebook_div, mock_publish_display_data, mock_get_comms):
        mock_get_comms.return_value = "comms"
        s = io.State()
        mock_notebook_div.return_value = "notebook_div"

        io._nb_loaded = True
        io._show_jupyter_with_state("obj", s, True)
        io._nb_loaded = False
        self._check_func_called(mock_publish_display_data, ({"text/html": "notebook_div"},), {})
コード例 #7
0
    def test_no_notebook(self, mock_get_browser_controller,
            mock__show_file_with_state, mock__show_jupyter_with_state,
            mock_get_comms):
        mock_get_browser_controller.return_value = "controller"
        mock_get_comms.return_value = "comms"
        s = io.State()

        s.output_file("foo.html")
        io._show_with_state("obj", s, "browser", "new")
        self.assertFalse(mock__show_jupyter_with_state.called)
        self._check_func_called(mock__show_file_with_state, ("obj", s, "new", "controller"), {})
コード例 #8
0
    def test(self, mock_save, mock_abspath):
        s = io.State()
        s.output_file("foo.html")
        controller = Mock()
        mock_save.return_value = "savepath"

        io._show_file_with_state("obj", s, "window", controller)
        self._check_func_called(mock_save, ("obj",), {"state": s})
        self._check_func_called(controller.open, ("file://savepath",), {"new": 1})

        io._show_file_with_state("obj", s, "tab", controller)
        self._check_func_called(mock_save, ("obj",), {"state": s})
        self._check_func_called(controller.open, ("file://savepath",), {"new": 2})
コード例 #9
0
    def test(self, mock_push):
        s = io.State()
        s._session = Mock()
        s._session.object_link.return_value = "link"
        controller = Mock()

        io._show_server_with_state("obj", s, "window", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(controller.open, ("link", ), {"new": 1})

        io._show_server_with_state("obj", s, "tab", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(controller.open, ("link", ), {"new": 2})
コード例 #10
0
    def test(self, mock_push):
        s = io.State()
        s._session_id = "thesession"
        s._server_url = "http://example.com"
        controller = Mock()

        io._show_server_with_state("obj", s, "window", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(controller.open, ("http://example.com?bokeh-session-id=thesession",), {"new": 1})

        io._show_server_with_state("obj", s, "tab", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(controller.open, ("http://example.com?bokeh-session-id=thesession",), {"new": 2})
コード例 #11
0
    def test_ShowNotebookWithState_bokehjs_load_failed(
            self, mock_get_browser_controller, mock_warn):
        mock_get_browser_controller.return_value = "controller"
        s = io.State()
        s.output_notebook()
        io._show_with_state("obj", s, "browser", "new")
        self.assertTrue(mock_warn.called)
        self.assertEqual(mock_warn.call_args[0], ("""

BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this
may be due to a slow or bad network connection. Possible fixes:

* ALWAYS run `output_notebook()` in a cell BY ITSELF, AT THE TOP, with no other code
* re-rerun `output_notebook()` to attempt to load from CDN again, or
* use INLINE resources instead, as so:

    from bokeh.resources import INLINE
    output_notebook(resources=INLINE)
""", ))
        self.assertEqual(mock_warn.call_args[1], {})
コード例 #12
0
    def test(self, mock_push):
        s = io.State()
        s._session_coords = _SessionCoordinates(
            dict(session_id="thesession",
                 url="http://example.com",
                 app_path='/foo'))
        s._server_enabled = True
        controller = Mock()

        io._show_server_with_state("obj", s, "window", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(
            controller.open,
            ("http://example.com/foo?bokeh-session-id=thesession", ),
            {"new": 1})

        io._show_server_with_state("obj", s, "tab", controller)
        self._check_func_called(mock_push, (), {"state": s})
        self._check_func_called(
            controller.open,
            ("http://example.com/foo?bokeh-session-id=thesession", ),
            {"new": 2})