Here are the examples of the python api bokeh.document.events.ColumnsStreamedEvent taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_combine_with_hint_defers(self, mock_combine):
mock_combine.return_value = False
m = FakeModel()
h = bde.ColumnsStreamedEvent("doc", m, dict(foo=1), 200, "setter", "invoker")
h2 = bde.ColumnsStreamedEvent("doc", m, dict(foo=2), 300, "setter", "invoker")
e = bde.ModelChangedEvent("doc", "model", "attr", "old", "new", "snew", hint=h, callback_invoker="invoker")
e2 = bde.ModelChangedEvent("doc", "model", "attr", "old2", "new2", "snew2", hint=h2, callback_invoker="invoker2")
assert e.combine(e2) == False
assert mock_combine.call_count == 1
assert mock_combine.call_args[0] == (h2,)
assert mock_combine.call_args[1] == {}
# ColumnDataChangedEvent ------------------------------------------------------
class TestColumnDataChangedEvent(object):
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_init(self):
m = FakeModel()
e = bde.ColumnsStreamedEvent("doc", m, dict(foo=1), 200, "setter", "invoker")
assert e.document == "doc"
assert e.column_source == m
assert e.data == dict(foo=1)
assert e.rollover == 200
assert e.setter == "setter"
assert e.callback_invoker == "invoker"
def test_generate(self):
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_generate(self):
m = FakeModel()
e = bde.ColumnsStreamedEvent("doc", m, dict(foo=1), 200, "setter", "invoker")
refs = dict(foo=10)
bufs = set()
r = e.generate(refs, bufs)
assert r == dict(kind="ColumnsStreamed", column_source="ref", data=dict(foo=1), rollover=200)
assert refs == dict(foo=10)
assert bufs == set()
def test_dispatch(self):
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_dispatch(self):
m = FakeModel()
e = bde.ColumnsStreamedEvent("doc", m, dict(foo=1), 200, "setter", "invoker")
e.dispatch(FakeEmptyDispatcher())
d = FakeFullDispatcher()
e.dispatch(d)
assert d.called == ['_document_changed', '_document_patched', '_columns_streamed']
def test_combine_ignores_all(self):
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_combine_ignores_all(self):
m = FakeModel()
e = bde.ColumnsStreamedEvent("doc", m, dict(foo=1), 200, "setter", "invoker")
e2 = bde.ColumnsStreamedEvent("doc", m, dict(foo=2), 300, "setter", "invoker")
assert e.combine(e2) == False
assert e.column_source is m
assert e.data == dict(foo=1)
assert e.rollover == 200
def test_pandas_data(self, pd):
3
View Source File : test_events.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_pandas_data(self, pd):
m = FakeModel()
df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
e = bde.ColumnsStreamedEvent("doc", m, df, 200, "setter", "invoker")
assert isinstance(e.data, dict)
assert e.data == {c: df[c] for c in df.columns}
# ColumnsPatchedEvent ---------------------------------------------------------
class TestColumnsPatchedEvent(object):
0
View Source File : test_patch_doc.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_patch_event_contains_setter(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)
cds = ColumnDataSource(data={'a': np.array([0., 1., 2.])})
sample.add_root(cds)
mock_session = object()
def sample_document_callback_assert(event):
"""Asserts that setter is correctly set on event"""
assert event.setter is mock_session
sample.on_change(sample_document_callback_assert)
# Model property changed
event = ModelChangedEvent(sample, root, 'child', root.child, new_child, new_child)
msg = Protocol("1.0").create("PATCH-DOC", [event])
msg.apply_to_document(sample, mock_session)
assert msg.buffers == []
# RootAdded
event2 = RootAddedEvent(sample, root)
msg2 = Protocol("1.0").create("PATCH-DOC", [event2])
msg2.apply_to_document(sample, mock_session)
assert msg2.buffers == []
# RootRemoved
event3 = RootRemovedEvent(sample, root)
msg3 = Protocol("1.0").create("PATCH-DOC", [event3])
msg3.apply_to_document(sample, mock_session)
assert msg3.buffers == []
# ColumnsStreamed
event4 = ModelChangedEvent(sample, cds, 'data', 10, None, None,
hint=ColumnsStreamedEvent(sample, cds, {"a": [3]}, None, mock_session))
msg4 = Protocol("1.0").create("PATCH-DOC", [event4])
msg4.apply_to_document(sample, mock_session)
assert msg4.buffers == []
# ColumnsPatched
event5 = ModelChangedEvent(sample, cds, 'data', 10, None, None,
hint=ColumnsPatchedEvent(sample, cds, {"a": [(0, 11)]}))
msg5 = Protocol("1.0").create("PATCH-DOC", [event5])
msg5.apply_to_document(sample, mock_session)
assert msg5.buffers == []
# ColumnDataChanged, use_buffers=False
event6 = ModelChangedEvent(sample, cds, 'data', {'a': np.array([0., 1.])}, None, None,
hint=ColumnDataChangedEvent(sample, cds))
msg6 = Protocol("1.0").create("PATCH-DOC", [event6], use_buffers=False)
msg6.apply_to_document(sample, mock_session)
assert msg6.buffers == []
print(cds.data)
# ColumnDataChanged, use_buffers=True
event7 = ModelChangedEvent(sample, cds, 'data', {'a': np.array([0., 1.])}, None, None,
hint=ColumnDataChangedEvent(sample, cds))
msg7 = Protocol("1.0").create("PATCH-DOC", [event7])
# can't test apply, doc not set up to *receive* binary buffers
# msg7.apply_to_document(sample, mock_session)
assert len(msg7.buffers) == 1
buf = msg7.buffers.pop()
assert len(buf) == 2
assert isinstance(buf[0], dict)
assert list(buf[0]) == ['id']
# reports CDS buffer *as it is* Normally events called by setter and
# value in local object would have been already mutated.
assert buf[1] == np.array([11., 1., 2., 3]).tobytes()
class _Event(object):