def test_set_defaults(): fake_grid_options_a = {"foo": "bar"} set_defaults(show_toolbar=False, precision=4, grid_options=fake_grid_options_a) def assert_widget_vals_a(widget): assert not widget.show_toolbar assert widget.precision == 4 assert widget.grid_options == fake_grid_options_a df = create_df() view = show_grid(df) assert_widget_vals_a(view) view = sqlgridWidget(df=df) assert_widget_vals_a(view) fake_grid_options_b = {"foo": "buzz"} set_defaults(show_toolbar=True, precision=2, grid_options=fake_grid_options_b) def assert_widget_vals_b(widget): assert widget.show_toolbar assert widget.precision == 2 assert widget.grid_options == fake_grid_options_b df = create_df() view = show_grid(df) assert_widget_vals_b(view) view = sqlgridWidget(df=df) assert_widget_vals_b(view)
def test_object_dtype_categorical(): cat_series = pd.Series( pd.Categorical(my_object_vals, categories=my_object_vals)) widget = show_grid(cat_series) constraints_enum = widget._columns[0]["constraints"]["enum"] assert not isinstance(constraints_enum[0], dict) assert not isinstance(constraints_enum[1], dict) widget._handle_sqlgrid_msg_helper({ "type": "show_filter_dropdown", "field": 0, "search_val": None }) widget._handle_sqlgrid_msg_helper({ "field": 0, "filter_info": { "field": 0, "selected": [0], "type": "text", "excluded": [], }, "type": "change_filter", }) assert len(widget._df) == 1 assert widget._df[0][0] == cat_series[0]
def test_instance_created(): event_history = init_event_history(All) sqlgrid_widget = show_grid(create_df()) assert event_history == [{"name": "instance_created"}] assert sqlgrid_widget.id
def test_multi_interval_index(): df = create_interval_index_df() df["A"] = np.array([3] * 1000, dtype="int32") df.set_index(["time", "time_bin"], inplace=True) show_grid(df)
def test_interval_index(): df = create_interval_index_df() df.set_index("time_bin", inplace=True) show_grid(df)