def test_PropertyValueDict_mutators(mock_notify): pvd = pc.PropertyValueDict(dict(foo=10, bar=20, baz=30)) mock_notify.reset() del pvd['foo'] assert mock_notify.called mock_notify.reset() pvd['foo'] = 11 assert mock_notify.called mock_notify.reset() pvd.pop('foo') assert mock_notify.called mock_notify.reset() pvd.popitem() assert mock_notify.called mock_notify.reset() pvd.setdefault('baz') assert mock_notify.called mock_notify.reset() pvd.clear() assert mock_notify.called mock_notify.reset() pvd.update(bar=1) assert mock_notify.called
def test_PropertyValueDict__patch(mock_notify): from bokeh.server.events import ColumnsPatchedEvent source = ColumnDataSource(data=dict(foo=[10, 20])) pvd = pc.PropertyValueDict(source.data) mock_notify.reset() pvd._patch("doc", source, dict(foo=[(1, 40)]), setter='setter') assert mock_notify.called_once assert mock_notify.call_args[0] == ({'foo': [10, 40]},) assert 'hint' in mock_notify.call_args[1] assert isinstance(mock_notify.call_args[1]['hint'], ColumnsPatchedEvent) assert mock_notify.call_args[1]['hint'].setter == 'setter'
def test_PropertyValueDict__patch_with_slice_indices(mock_notify): from bokeh.protocol.events import ColumnsPatchedEvent source = ColumnDataSource(data=dict(foo=[10, 20, 30, 40, 50])) pvd = pc.PropertyValueDict(source.data) mock_notify.reset() pvd._patch("doc", source, dict(foo=[(slice(2), [1, 2])]), setter='setter') assert mock_notify.called_once assert mock_notify.call_args[0] == ({'foo': [1, 2, 30, 40, 50]}, ) assert pvd == dict(foo=[1, 2, 30, 40, 50]) assert 'hint' in mock_notify.call_args[1] assert isinstance(mock_notify.call_args[1]['hint'], ColumnsPatchedEvent) assert mock_notify.call_args[1]['hint'].setter == 'setter'
def test_PropertyValueDict__stream_list_with_rollover(mock_notify): from bokeh.server.events import ColumnsStreamedEvent source = ColumnDataSource(data=dict(foo=[10, 20, 30])) pvd = pc.PropertyValueDict(source.data) mock_notify.reset() pvd._stream("doc", source, dict(foo=[40]), rollover=3, setter="setter") assert mock_notify.called_once assert mock_notify.call_args[0] == ({'foo': [20, 30, 40]},) assert 'hint' in mock_notify.call_args[1] assert isinstance(mock_notify.call_args[1]['hint'], ColumnsStreamedEvent) assert mock_notify.call_args[1]['hint'].setter == 'setter' assert mock_notify.call_args[1]['hint'].rollover == 3
def test_PropertyValueDict__stream_array_with_rollover(mock_notify): from bokeh.server.events import ColumnsStreamedEvent import numpy as np source = ColumnDataSource(data=dict(foo=np.array([10, 20, 30]))) pvd = pc.PropertyValueDict(source.data) mock_notify.reset() pvd._stream("doc", source, dict(foo=[40]), rollover=3, setter="setter") assert mock_notify.called_once assert len(mock_notify.call_args[0]) == 1 assert 'foo' in mock_notify.call_args[0][0] assert (mock_notify.call_args[0][0]['foo'] == np.array([10, 20, 30])).all() assert 'hint' in mock_notify.call_args[1] assert isinstance(mock_notify.call_args[1]['hint'], ColumnsStreamedEvent) assert mock_notify.call_args[1]['hint'].setter == 'setter' assert mock_notify.call_args[1]['hint'].rollover == 3