def test_server_source_updated_after_edit( self, bokeh_server_page: BokehServerPage) -> None: data = {'x': [1, 2, 5, 6], 'y': [60, 50, 20, 10]} source = ColumnDataSource(data) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True, editor=NumberEditor()) ], source=source, editable=True) def modify_doc(doc): plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.tags.append( CustomJS(name="custom-action", args=dict(s=source), code=RECORD("data", "s.data"))) doc.add_root(column(plot, table)) page = bokeh_server_page(modify_doc) page.eval_custom_action() results = page.results assert results == {'data': {'x': [1, 2, 5, 6], 'y': [60, 50, 20, 10]}} assert get_table_column_cells(page.driver, table, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, table, 2) == ['60', '50', '20', '10'] cell = get_table_cell(page.driver, table, 3, 2) assert cell.text == '20' enter_text_in_cell(page.driver, table, 3, 2, '100') page.eval_custom_action() results = page.results assert results == {'data': {'x': [1, 2, 5, 6], 'y': [60, 50, 100, 10]}} assert source.data == {'x': [1, 2, 5, 6], 'y': [60, 50, 100, 10]} assert get_table_column_cells(page.driver, table, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, table, 2) == ['60', '50', '100', '10']
def test_server_sorted_after_stream(self, bokeh_server_page): data = {'x': [1,2,5,6], 'y': [60,50,20,10]} source = ColumnDataSource(data) def modify_doc(doc): plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True) ], source=source, editable=False) button = Button(css_classes=["foo"]) def cb(): source.stream({'x': [100], 'y': [100]}) button.on_click(cb) doc.add_root(column(plot, table, button)) page = bokeh_server_page(modify_doc) page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,50,20,10]}} assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 1) assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 2, True) assert get_table_column_cells(page.driver, 1) == ['6', '5', '2', '1'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '50', '60'] button = page.driver.find_element_by_class_name('foo') button.click() page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6,100], 'y': [60,50,20,10,100]}} assert source.data == {'x': [1,2,5,6,100], 'y': [60,50,20,10,100]} assert get_table_column_cells(page.driver, 1) == ['6', '5', '2', '1', '100'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '50', '60', '100']
def test_server_sorted_after_stream(self, bokeh_server_page) -> None: data = {'x': [1,2,5,6], 'y': [60,50,20,10]} source = ColumnDataSource(data) def modify_doc(doc): plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True) ], source=source, editable=False) button = Button(css_classes=["foo"]) def cb(): source.stream({'x': [100], 'y': [100]}) button.on_click(cb) doc.add_root(column(plot, table, button)) page = bokeh_server_page(modify_doc) page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,50,20,10]}} assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 1) assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 2, True) assert get_table_column_cells(page.driver, 1) == ['6', '5', '2', '1'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '50', '60'] button = page.driver.find_element_by_class_name('foo') button.click() page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6,100], 'y': [60,50,20,10,100]}} assert source.data == {'x': [1,2,5,6,100], 'y': [60,50,20,10,100]} assert get_table_column_cells(page.driver, 1) == ['6', '5', '2', '1', '100'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '50', '60', '100']
def test_server_source_updated_after_edit(self, bokeh_server_page): data = {'x': [1,2,5,6], 'y': [60,50,20,10]} source = ColumnDataSource(data) def modify_doc(doc): plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True, editor=NumberEditor()) ], source=source, editable=True) doc.add_root(column(plot, table)) page = bokeh_server_page(modify_doc) page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,50,20,10]}} assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] cell = get_table_cell(page.driver, 3, 2) assert cell.text == '20' enter_text_in_cell(page.driver, cell, '100') page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,50,100,10]}} assert source.data == {'x': [1,2,5,6], 'y': [60,50,100,10]} assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '100', '10']
def test_server_sorted_after_edit(self, bokeh_server_page): data = {'x': [1,2,5,6], 'y': [60,50,20,10]} source = ColumnDataSource(data) def modify_doc(doc): plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True, editor=NumberEditor()) ], source=source, editable=True) doc.add_root(column(plot, table)) page = bokeh_server_page(modify_doc) page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,50,20,10]}} assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 1) assert get_table_column_cells(page.driver, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, 2, True) assert get_table_column_cells(page.driver, 1) == ['6', '5', '2', '1'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '50', '60'] cell = get_table_cell(page.driver, 3, 2) assert cell.text == '50' enter_text_in_cell(page.driver, cell, '100') page.click_custom_action() results = page.results assert results == {'data': {'x': [1,2,5,6], 'y': [60,100,20,10]}} assert source.data == {'x': [1,2,5,6], 'y': [60,100,20,10]} assert get_table_column_cells(page.driver, 1) == ['6', '5', '1', '2'] assert get_table_column_cells(page.driver, 2) == ['10', '20', '60', '100']
def test_server_sorted_after_stream( self, bokeh_server_page: BokehServerPage) -> None: button = Button() data = {'x': [1, 2, 5, 6], 'y': [60, 50, 20, 10]} source = ColumnDataSource(data) table = DataTable(columns=[ TableColumn(field="x", title="x", sortable=True), TableColumn(field="y", title="y", sortable=True) ], source=source, editable=False) def modify_doc(doc): plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.tags.append( CustomJS(name="custom-action", args=dict(s=source), code=RECORD("data", "s.data"))) def cb(): source.stream({'x': [100], 'y': [100]}) button.on_click(cb) doc.add_root(column(plot, table, button)) page = bokeh_server_page(modify_doc) page.eval_custom_action() results = page.results assert results == {'data': {'x': [1, 2, 5, 6], 'y': [60, 50, 20, 10]}} assert get_table_column_cells(page.driver, table, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, table, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, table, 1) assert get_table_column_cells(page.driver, table, 1) == ['1', '2', '5', '6'] assert get_table_column_cells(page.driver, table, 2) == ['60', '50', '20', '10'] sort_table_column(page.driver, table, 2, True) assert get_table_column_cells(page.driver, table, 1) == ['6', '5', '2', '1'] assert get_table_column_cells(page.driver, table, 2) == ['10', '20', '50', '60'] button_el = find_element_for(page.driver, button) button_el.click() page.eval_custom_action() results = page.results assert results == { 'data': { 'x': [1, 2, 5, 6, 100], 'y': [60, 50, 20, 10, 100] } } assert source.data == { 'x': [1, 2, 5, 6, 100], 'y': [60, 50, 20, 10, 100] } assert get_table_column_cells(page.driver, table, 1) == ['6', '5', '2', '1', '100'] assert get_table_column_cells(page.driver, table, 2) == ['10', '20', '50', '60', '100']