def test_no_events(self, mock_comms):
        mock_comms.return_value = MagicMock()

        d = Document()

        handle = binb.CommsHandle("comms", d)
        binb.push_notebook(d, None, handle)
        assert mock_comms.call_count == 0
Ejemplo n.º 2
0
    def test_no_events(self, mock_comms):
        mock_comms.return_value = MagicMock()

        d = Document()

        handle = binb.CommsHandle("comms", d)
        binb.push_notebook(d, None, handle)
        assert mock_comms.call_count == 0
    def test_with_events(self, mock_comms):
        mock_comm = MagicMock()
        mock_send = MagicMock(return_value="junk")
        mock_comm.send = mock_send
        mock_comms.return_value = mock_comm

        d = Document()

        handle = binb.CommsHandle("comms", d)
        d.title = "foo"
        binb.push_notebook(d, None, handle)
        assert mock_comms.call_count > 0
        assert mock_send.call_count == 3 # sends header, metadata, then content
        assert json.loads(mock_send.call_args[0][0]) == {u"events": [{u"kind": u"TitleChanged", u"title": u"foo"}], u"references": []}
        assert mock_send.call_args[1] == {}
Ejemplo n.º 4
0
    def test_with_events(self, mock_comms):
        mock_comm = MagicMock()
        mock_send = MagicMock(return_value="junk")
        mock_comm.send = mock_send
        mock_comms.return_value = mock_comm

        d = Document()

        handle = binb.CommsHandle("comms", d)
        d.title = "foo"
        binb.push_notebook(d, None, handle)
        assert mock_comms.call_count > 0
        assert mock_send.call_count == 3 # sends header, metadata, then content
        assert json.loads(mock_send.call_args[0][0]) == {u"events": [{u"kind": u"TitleChanged", u"title": u"foo"}], u"references": []}
        assert mock_send.call_args[1] == {}
Ejemplo n.º 5
0
    def test_with_events(self, mock_comms: PropertyMock) -> None:
        mock_comm = MagicMock()
        mock_send = MagicMock(return_value="junk")
        mock_comm.send = mock_send
        mock_comms.return_value = mock_comm

        d = Document()

        handle = binb.CommsHandle("comms", d)
        d.title = "foo"
        binb.push_notebook(document=d, handle=handle)
        assert mock_comms.call_count > 0
        assert mock_send.call_count == 3  # sends header, metadata, then content
        assert json.loads(mock_send.call_args[0][0]) == {
            "events": [{
                "kind": "TitleChanged",
                "title": "foo"
            }],
        }
        assert mock_send.call_args[1] == {}
Ejemplo n.º 6
0
    def on_epoch_end(self, epoch: int, logs: dict):
        """Callback method that runs when every epoch ends
        It updates given renderer data_source property.
        See https://keras.io/callbacks/, if you know detail.
        """
        # Records logs to self.history
        for k, v in logs.items():
            if k not in self.history:
                self.history[k] = list()
            self.history[k].append(v)

        # Updates renderers
        for renderer in self.renderers:
            renderer.data_source.data.update(
                x=np.arange(epoch + 1),
                **self.history,
            )

        # Finally, update the plot
        push_notebook(handle=self.handle)