def test_server_source_callback_triggered_after_edit(self, bokeh_server_page) -> None:
        data = {'x': [1,2,5,6], 'y': [60,50,20,10]}
        source = ColumnDataSource(data)

        result = []

        def modify_doc(doc):
            plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)

            table = DataTable(columns=[
                TableColumn(field="x", title="x", sortable=True),
                TableColumn(field="y", title="y", sortable=True, editor=NumberEditor())
            ], source=source, editable=True)

            def cb(attr, old, new):
                result.append("CALLED")

            source.on_change('data', cb)
            doc.add_root(column(plot, table))

        page = bokeh_server_page(modify_doc)

        assert result == []

        cell = get_table_cell(page.driver, 3, 2)
        assert cell.text == '20'
        enter_text_in_cell(page.driver, cell, '100')

        assert result == ["CALLED"]
    def test_server_source_callback_triggered_after_edit(self, bokeh_server_page):
        data = {'x': [1,2,5,6], 'y': [60,50,20,10]}
        source = ColumnDataSource(data)

        result = []

        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)

            table = DataTable(columns=[
                TableColumn(field="x", title="x", sortable=True),
                TableColumn(field="y", title="y", sortable=True, editor=NumberEditor())
            ], source=source, editable=True)

            def cb(attr, old, new):
                result.append("CALLED")

            source.on_change('data', cb)
            doc.add_root(column(plot, table))

        page = bokeh_server_page(modify_doc)

        assert result == []

        cell = get_table_cell(page.driver, 3, 2)
        assert cell.text == '20'
        enter_text_in_cell(page.driver, cell, '100')

        assert result == ["CALLED"]
Example #3
0
    def test_server_edit_does_not_duplicate_data_update_event(
            self, bokeh_server_page):
        def modify_doc(doc):
            data = {'x': [1, 2, 3, 4], 'y': [10, 20, 30, 40]}
            source = ColumnDataSource(data)

            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"),
                TableColumn(field="y", 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, 3, 4], 'y': [10, 20, 30, 40]}}

        cell = get_table_cell(page.driver, 3, 2)
        assert cell.text == '30'
        enter_text_in_cell(page.driver, cell, '100')

        page.click_custom_action()

        results = page.results
        assert results == {'data': {'x': [1, 2, 3, 4], 'y': [10, 20, 100, 40]}}

        # if the server receives something back like:
        #
        # Message 'PATCH-DOC' (revision 1) content: {
        #     'events': [{
        #         'kind': 'ModelChanged',
        #         'model': {'type': 'ColumnDataSource', 'id': '1001'},
        #         'attr': 'data', 'new': {'x': [1,2,3,4], 'y': [10, 20, 100, 40]}
        #     }],
        #     'references': []
        # }
        #
        # Then that means the client got our stream message and erroneously ping
        # ponged a full data update back to us
        for msg in page.message_test_port.received:
            assert not any(
                is_cds_data_patch(evt)
                for evt in msg.content.get('events', []))
Example #4
0
    def test_server_edit_does_not_duplicate_data_update_event(
            self, bokeh_server_page: BokehServerPage) -> None:
        data = {'x': [1, 2, 3, 4], 'y': [10, 20, 30, 40]}
        source = ColumnDataSource(data)

        table = DataTable(columns=[
            TableColumn(field="x"),
            TableColumn(field="y", 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, 3, 4], 'y': [10, 20, 30, 40]}}

        cell = get_table_cell(page.driver, table, 3, 2)
        assert cell.text == '30'
        enter_text_in_cell(page.driver, table, 3, 2, '100')

        page.eval_custom_action()

        results = page.results
        assert results == {'data': {'x': [1, 2, 3, 4], 'y': [10, 20, 100, 40]}}

        # if the server receives something back like:
        #
        # Message 'PATCH-DOC' (revision 1) content: {
        #     'events': [{
        #         'kind': 'ModelChanged',
        #         'model': {'id': '1001'},
        #         'attr': 'data', 'new': {'x': [1,2,3,4], 'y': [10, 20, 100, 40]}
        #     }],
        #     'references': []
        # }
        #
        # Then that means the client got our stream message and erroneously ping
        # ponged a full data update back to us
        assert not has_cds_data_patches(page.message_test_port.received)
Example #5
0
    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_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']
Example #7
0
    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_edit_does_not_duplicate_data_update_event(self, bokeh_server_page):
        def modify_doc(doc):
            data = {'x': [1,2,3,4], 'y': [10,20,30,40]}
            source = ColumnDataSource(data)

            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"),
                TableColumn(field="y", 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,3,4], 'y': [10,20,30,40]}}

        cell = get_table_cell(page.driver, 3, 2)
        assert cell.text == '30'
        enter_text_in_cell(page.driver, cell, '100')

        page.click_custom_action()

        results = page.results
        assert results ==  {'data': {'x': [1,2,3,4], 'y': [10, 20, 100, 40]}}

        # if the server receives something back like:
        #
        # Message 'PATCH-DOC' (revision 1) content: {
        #     'events': [{
        #         'kind': 'ModelChanged',
        #         'model': {'type': 'ColumnDataSource', 'id': '1001'},
        #         'attr': 'data', 'new': {'x': [1,2,3,4], 'y': [10, 20, 100, 40]}
        #     }],
        #     'references': []
        # }
        #
        # Then that means the client got our stream message and erroneously ping
        # ponged a full data update back to us
        assert not has_cds_data_patches(page.message_test_port.received)
Example #9
0
    def test_editing_updates_source(self, bokeh_model_page):
        page = bokeh_model_page(self.table)

        # Click row 1 (which triggers the selection callback)
        cell = get_table_cell(page.driver, 1, 1)
        cell.click()
        results = page.results
        assert results['values'] == self.values

        # Now double click, enter the text new value and <enter>
        cell = get_table_cell(page.driver, 1, 1)
        enter_text_in_cell(page.driver, cell, "baz")

        # Click row 2 (which triggers callback again so we can inspect the data)
        cell = get_table_cell(page.driver, 2, 1)
        cell.click()
        results = page.results
        assert results['values'] == ["baz", "bar"]

        assert page.has_no_console_errors()
Example #10
0
    def test_editing_updates_source(self, bokeh_model_page):
        page = bokeh_model_page(self.table)

        # Click row 1 (which triggers the selection callback)
        cell = get_table_cell(page.driver, 1, 1)
        cell.click()
        results = page.results
        assert results['values'] == self.values

        # Now double click, enter the text new value and <enter>
        cell = get_table_cell(page.driver, 1, 1)
        enter_text_in_cell(page.driver, cell, "baz")

        # Click row 2 (which triggers callback again so we can inspect the data)
        cell = get_table_cell(page.driver, 2, 1)
        cell.click()
        results = page.results
        assert results['values'] == ["baz", "bar"]

        assert page.has_no_console_errors()
Example #11
0
    def test_editing_does_not_update_source_on_bad_values(self, bad, bokeh_model_page) -> None:
        self.table.editable = False
        page = bokeh_model_page(self.table)

        # Click row 1 (which triggers the selection callback)
        cell = get_table_cell(page.driver, 1, 1)
        cell.click()
        results = page.results
        assert results['values'] == self.values

        # Now double click, enter the text new value and <enter>
        cell = get_table_cell(page.driver, 1, 1)
        enter_text_in_cell(page.driver, cell, bad)

        # Click row 2 (which triggers callback again so we can inspect the data)
        cell = get_table_cell(page.driver, 2, 1)
        cell.click()
        results = page.results
        assert results['values'] == self.values

        assert page.has_no_console_errors()
Example #12
0
    def test_editing_updates_source(self,
                                    bokeh_model_page: BokehModelPage) -> None:
        table = make_table(self.editor, self.values)
        page = bokeh_model_page(table)

        # Click row 1 (which triggers the selection callback)
        cell = get_table_cell(page.driver, table, 1, 1)
        cell.click()
        results = page.results
        assert results['values'] == self.values

        # Now double click, enter the text new value and <enter>
        enter_text_in_cell(page.driver, table, 1, 1, "33.5")

        # Click row 2 (which triggers callback again so we can inspect the data)
        cell = get_table_cell(page.driver, table, 2, 1)
        cell.click()
        results = page.results
        assert results['values'] == [33.5, 2.2]

        assert page.has_no_console_errors()