bokeh.server.protocol.Protocol.create

Here are the examples of the python api bokeh.server.protocol.Protocol.create taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

Example 1

Project: bokeh Source File: test_pull_doc.py
    def test_create_reply_then_parse(self):
        sample = self._sample_doc()
        msg = Protocol("1.0").create("PULL-DOC-REPLY", 'fakereqid', sample)
        copy = docuement.Docuement()
        msg.push_to_docuement(copy)
        assert len(sample.roots) == 2
        assert len(copy.roots) == 2

Example 2

Project: bokeh Source File: test_push_doc.py
    def test_create_then_parse(self):
        sample = self._sample_doc()
        msg = Protocol("1.0").create("PUSH-DOC", sample)
        copy = docuement.Docuement()
        msg.push_to_docuement(copy)
        assert len(sample.roots) == 2
        assert len(copy.roots) == 2

Example 3

Project: bokeh Source File: test_patch_doc.py
    def test_create_then_apply_model_changed(self):
        sample = self._sample_doc()

        foos = []
        for r in sample.roots:
            foos.append(r.foo)
        assert foos == [ 2, 2 ]

        obj = next(iter(sample.roots))
        assert obj.foo == 2
        event = docuement.ModelChangedEvent(sample, obj, 'foo', obj.foo, 42, 42)
        msg = Protocol("1.0").create("PATCH-DOC", [event])

        copy = docuement.Docuement.from_json_string(sample.to_json_string())
        msg.apply_to_docuement(copy)

        foos = []
        for r in copy.roots:
            foos.append(r.foo)
        foos.sort()
        assert foos == [ 2, 42 ]

Example 4

Project: bokeh Source File: test_patch_doc.py
    def test_should_suppress_model_changed(self):
        sample = self._sample_doc()
        root = None
        other_root = None
        for r in sample.roots:
            if r.child is not None:
                root = r
            else:
                other_root = r
        assert root is not None
        assert other_root is not None
        new_child = AnotherModelInTestPatchDoc(bar=56)

        # integer property changed
        event1 = docuement.ModelChangedEvent(sample, root, 'foo', root.foo, 42, 42)
        msg = Protocol("1.0").create("PATCH-DOC", [event1])
        assert msg.should_suppress_on_change(event1)
        assert not msg.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'foo', root.foo, 43, 43))
        assert not msg.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'bar', root.foo, 43, 43))
        assert not msg.should_suppress_on_change(docuement.ModelChangedEvent(sample, other_root, 'foo', root.foo, 43, 43))

        # Model property changed
        event2 = docuement.ModelChangedEvent(sample, root, 'child', root.child, new_child, new_child)
        msg2 = Protocol("1.0").create("PATCH-DOC", [event2])
        assert msg2.should_suppress_on_change(event2)
        assert not msg2.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'child', root.child, other_root, other_root))
        assert not msg2.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'blah', root.child, new_child, new_child))
        assert not msg2.should_suppress_on_change(docuement.ModelChangedEvent(sample, other_root, 'child', other_root.child, new_child, new_child))

        # Model property changed to None
        event3 = docuement.ModelChangedEvent(sample, root, 'child', root.child, None, None)
        msg3 = Protocol("1.0").create("PATCH-DOC", [event3])
        assert msg3.should_suppress_on_change(event3)
        assert not msg3.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'child', root.child, other_root, other_root))
        assert not msg3.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'blah', root.child, None, None))
        assert not msg3.should_suppress_on_change(docuement.ModelChangedEvent(sample, other_root, 'child', other_root.child, None, None))

        # Model property changed from None
        event4 = docuement.ModelChangedEvent(sample, other_root, 'child', other_root.child, None, None)
        msg4 = Protocol("1.0").create("PATCH-DOC", [event4])
        assert msg4.should_suppress_on_change(event4)
        assert not msg4.should_suppress_on_change(docuement.ModelChangedEvent(sample, other_root, 'child', other_root.child, root, root))
        assert not msg4.should_suppress_on_change(docuement.ModelChangedEvent(sample, other_root, 'blah', other_root.child, None, None))
        assert not msg4.should_suppress_on_change(docuement.ModelChangedEvent(sample, root, 'child', other_root.child, None, None))

        # RootAdded
        event5 = docuement.RootAddedEvent(sample, root)
        msg5 = Protocol("1.0").create("PATCH-DOC", [event5])
        assert msg5.should_suppress_on_change(event5)
        assert not msg5.should_suppress_on_change(docuement.RootAddedEvent(sample, other_root))
        assert not msg5.should_suppress_on_change(docuement.RootRemovedEvent(sample, root))

        # RootRemoved
        event6 = docuement.RootRemovedEvent(sample, root)
        msg6 = Protocol("1.0").create("PATCH-DOC", [event6])
        assert msg6.should_suppress_on_change(event6)
        assert not msg6.should_suppress_on_change(docuement.RootRemovedEvent(sample, other_root))
        assert not msg6.should_suppress_on_change(docuement.RootAddedEvent(sample, root))

        # ColumnsStreamed
        event7 = docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                            hint=docuement.ColumnsStreamedEvent(sample, root, {}, None))
        msg7 = Protocol("1.0").create("PATCH-DOC", [event7])
        assert msg7.should_suppress_on_change(event7)
        assert not msg7.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsStreamedEvent(sample, root, {}, 10))
        )
        assert not msg7.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsStreamedEvent(sample, root, {"a": [10]}, None))
        )
        assert not msg7.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsStreamedEvent(sample, other_root, {}, None))
        )

        # ColumnsPatched
        event8 = docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                            hint=docuement.ColumnsPatchedEvent(sample, root, {"a": [(0, 11)]}))
        msg8 = Protocol("1.0").create("PATCH-DOC", [event8])
        assert msg8.should_suppress_on_change(event8)
        assert not msg8.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsPatchedEvent(sample, root, {}))
        )
        assert not msg8.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsPatchedEvent(sample, root, {"a": [(0, 10)]}))
        )
        assert msg8.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsPatchedEvent(sample, root, {"a": [(0, 11)]}))
        )
        assert not msg8.should_suppress_on_change(
            docuement.ModelChangedEvent(sample, root, 'data', 10, None, None,
                                       hint=docuement.ColumnsPatchedEvent(sample, other_root, {}))
        )