コード例 #1
0
    def test_compute_query_dict(self, range, query):
        bb = BaseBar(x="key")
        self.dashboard.add_charts([bb])
        bb.filter_widget.value = range
        # test the following function behavior
        bb.compute_query_dict(self.dashboard._query_str_dict)

        assert self.dashboard._query_str_dict["key_bar"] == query
コード例 #2
0
    def test_initiate_chart(self):
        bb = BaseBar(x="key")
        bb.initiate_chart(self.dashboard)

        assert bb.min_value == 0.0
        assert bb.max_value == 4.0
        assert bb.data_points == 5
        assert bb.stride == 1
        assert bb.stride_type == int
コード例 #3
0
    def test_add_reset_event(self):
        bb = BaseBar(x="key")
        self.result = None

        def test_func(event, callback):
            self.result = callback

        bb.add_event = test_func
        # test the following function behavior
        bb.add_reset_event(self.dashboard)
        assert self.result.__name__ == "reset_callback"
コード例 #4
0
    def test_query_chart_by_range(self, query_tuple, result):
        dashboard = self.cux_df.dashboard(charts=[])
        active_chart = BaseBar(x="key")
        active_chart.stride = 1
        active_chart.min_value = 0
        bdsi = dashboard._charts["_datasize_indicator"]
        self.result = ""

        def reset_chart(datatile_result):
            self.result = datatile_result

        bdsi.reset_chart = reset_chart
        datatile = pd.DataFrame({0: {0: 1.0, 1: 2.0, 2: 3.0, 3: 4.0, 4: 5.0}})
        bdsi.query_chart_by_range(active_chart, query_tuple, datatile)

        assert result == self.result
コード例 #5
0
    def test_compute_query_dict(self, range, query):
        bb = BaseBar(x="key")
        bb.min_value = self.dashboard._data[bb.x].min()
        bb.max_value = self.dashboard._data[bb.x].max()
        if bb.data_points > self.dashboard._data[bb.x].shape[0]:
            bb.data_points = self.dashboard._data[bb.x].shape[0]
        bb.add_range_slider_filter(self.dashboard)
        self.dashboard.add_charts([bb])
        bb.filter_widget.value = range
        # test the following function behavior
        bb.compute_query_dict(self.dashboard._query_str_dict)

        assert self.dashboard._query_str_dict["key_bar"] == query
コード例 #6
0
    def test_add_range_slider_filter(self):
        bb = BaseBar(x="key")
        bb.min_value = self.dashboard._data[bb.x].min()
        bb.max_value = self.dashboard._data[bb.x].max()
        if bb.data_points > self.dashboard._data[bb.x].shape[0]:
            bb.data_points = self.dashboard._data[bb.x].shape[0]
        bb.add_range_slider_filter(self.dashboard)

        assert type(bb.filter_widget) == pn.widgets.RangeSlider
        assert bb.filter_widget.value == (0, 4)
コード例 #7
0
    def test_query_chart_by_indices(self, old_indices, new_indices, prev_value,
                                    result):
        active_chart = BaseBar(x="key")
        active_chart.stride = 1
        active_chart.min_value = 0
        self.result = ""
        dashboard = self.cux_df.dashboard(charts=[active_chart])
        dashboard._active_view = active_chart.name
        dashboard._calc_data_tiles(cumsum=False)
        bdsi = dashboard._charts["_datasize_indicator"]
        bdsi.chart.value = prev_value

        def reset_chart(datatile_result):
            self.result = datatile_result

        bdsi.reset_chart = reset_chart
        datatile = pd.DataFrame({0: {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0}})
        bdsi.query_chart_by_indices(active_chart, old_indices, new_indices,
                                    datatile)

        assert result == self.result
コード例 #8
0
    def test_add_events(self, event, result):
        bb = BaseBar(x="key")
        self.result = None

        def test_func(cls):
            self.result = "func_Called"

        bb.add_reset_event = test_func
        bb.reset_event = event
        # test the following function behavior
        bb.add_events(self.dashboard)

        assert self.result == result
コード例 #9
0
    def test_variables(self):
        bb = BaseBar(x="test_x")

        assert bb.chart_type == "bar"
        assert bb.reset_event is None
        assert bb._datatile_loaded_state is False
        assert bb.filter_widget is None
        assert bb.use_data_tiles is True
        assert bb.datatile_active_color == "#8ab4f7"
        assert bb.x == "test_x"
        assert bb.y is None
        assert bb.data_points == int(100)
        assert bb.add_interaction is True
        assert bb.aggregate_fn == "count"
        assert bb.width == 400
        assert bb.height == 400
        assert bb.stride is None
        assert bb.stride_type == int
        assert bb.library_specific_params == {}
コード例 #10
0
    def test_view(self, chart, _chart):
        bnac = BaseBar(x="test_x")
        bnac.chart = chart
        bnac.width = 400

        assert str(bnac.view()) == str(chart_view(_chart, width=bnac.width))
コード例 #11
0
class TestBaseBar:

    df = cudf.DataFrame({
        "key": [0, 1, 2, 3, 4],
        "val": [float(i + 10) for i in range(5)]
    })
    cux_df = cuxfilter.DataFrame.from_dataframe(df)
    dashboard = cux_df.dashboard(charts=[], title="test_title")

    def test_variables(self):
        bb = BaseBar(x="test_x")

        assert bb.chart_type == "bar"
        assert bb.reset_event is None
        assert bb._datatile_loaded_state is False
        assert bb.filter_widget is None
        assert bb.use_data_tiles is True
        assert bb.datatile_active_color == "#8ab4f7"
        assert bb.x == "test_x"
        assert bb.y is None
        assert bb.data_points == int(100)
        assert bb.add_interaction is True
        assert bb.aggregate_fn == "count"
        assert bb.width == 400
        assert bb.height == 400
        assert bb.stride is None
        assert bb.stride_type == int
        assert bb.library_specific_params == {}

    def test_initiate_chart(self):
        bb = BaseBar(x="key")
        bb.initiate_chart(self.dashboard)

        assert bb.min_value == 0.0
        assert bb.max_value == 4.0
        assert bb.data_points == 5
        assert bb.stride == 1
        assert bb.stride_type == int

    @pytest.mark.parametrize("chart, _chart", [(None, None), (1, 1)])
    def test_view(self, chart, _chart):
        bnac = BaseBar(x="test_x")
        bnac.chart = chart
        bnac.width = 400

        assert str(bnac.view()) == str(chart_view(_chart, width=bnac.width))

    @pytest.mark.parametrize(
        "bb, result",
        [
            (
                BaseBar(x="key", y="val"),
                {
                    "X": [0.0, 1.0, 2.0, 3.0, 4.0],
                    "Y": [10.0, 11.0, 12.0, 13.0, 14.0],
                },
            ),
            (
                BaseBar(x="key"),
                {
                    "X": [0.0, 0.8, 1.6, 2.4000000000000004, 4.0],
                    "Y": [1, 1, 1, 1, 1],
                },
            ),
        ],
    )
    def test_calculate_source(self, bb, result):
        bb.initiate_chart(self.dashboard)
        self.result = None

        def func1(dict_temp, patch_update=False):
            self.result = dict_temp

        bb.format_source_data = func1
        bb.calculate_source(self.df)
        assert self.result == result

    def test_add_range_slider_filter(self):
        bb = BaseBar(x="key")
        bb.min_value = self.dashboard._data[bb.x].min()
        bb.max_value = self.dashboard._data[bb.x].max()
        if bb.data_points > self.dashboard._data[bb.x].shape[0]:
            bb.data_points = self.dashboard._data[bb.x].shape[0]
        bb.add_range_slider_filter(self.dashboard)

        assert type(bb.filter_widget) == pn.widgets.RangeSlider
        assert bb.filter_widget.value == (0, 4)

    @pytest.mark.parametrize("range, query", [((3, 4), "3<=key<=4"),
                                              ((0, 0), "0<=key<=0")])
    def test_compute_query_dict(self, range, query):
        bb = BaseBar(x="key")
        bb.min_value = self.dashboard._data[bb.x].min()
        bb.max_value = self.dashboard._data[bb.x].max()
        if bb.data_points > self.dashboard._data[bb.x].shape[0]:
            bb.data_points = self.dashboard._data[bb.x].shape[0]
        bb.add_range_slider_filter(self.dashboard)
        self.dashboard.add_charts([bb])
        bb.filter_widget.value = range
        # test the following function behavior
        bb.compute_query_dict(self.dashboard._query_str_dict)

        assert self.dashboard._query_str_dict["key_bar"] == query

    @pytest.mark.parametrize("event, result", [(None, None),
                                               (ButtonClick, "func_Called")])
    def test_add_events(self, event, result):
        bb = BaseBar(x="key")
        self.result = None

        def test_func(cls):
            self.result = "func_Called"

        bb.add_reset_event = test_func
        bb.reset_event = event
        # test the following function behavior
        bb.add_events(self.dashboard)

        assert self.result == result

    def test_add_reset_event(self):
        bb = BaseBar(x="key")
        self.result = None

        def test_func(event, callback):
            self.result = callback

        bb.add_event = test_func
        # test the following function behavior
        bb.add_reset_event(self.dashboard)
        assert self.result.__name__ == "reset_callback"
コード例 #12
0
 def test_add_range_slider_filter(self):
     bb = BaseBar(x="key")
     self.dashboard.add_charts([bb])
     assert type(bb.filter_widget) == pn.widgets.RangeSlider
     assert bb.filter_widget.value == (0, 4)