def test_set_a_column_title(self): dicts = [{ "key1_1": "val1_1", "key1_2": "val1_2", "key1_3": "val1_3" }, { "key1_1": "val2_1", "key1_2": "val2_2", "key1_3": "val2_3" }, { "key1_1": "val3_1", "key1_2": "val3_2", "key1_3": "val3_3" }, { "key1_1": "val4_1", "key1_2": "val4_2", "key1_3": "val4_3" }, { "key1_1": "val5_1", "key1_2": "val5_2", "key1_3": "val5_3" }] grid = DictionaryGrid(dicts) grid.columns["key1_1"].set_title("KEY") for c in grid.get_columns(): if c.key == "key1_1": self.assertEqual(c.get_title(), "KEY")
def test_extra_data_from_selected(self): """Ensure that keys starting with _ are not displayed, but the valuesa retrievable. """ dicts = [{ "key1_1": "val1_1", "key1_2": "val1_2", "__extra": ["boo", "biz", "baz"] }, { "key1_1": "val2_1", "key1_2": "val2_2", "__extra": self }] grid = DictionaryGrid(dicts) #make sure there are 2 columns self.assertEqual(len(grid.get_model()), 2) #ensure that none of the columns are named _extra cols = grid.get_columns() for c in cols: self.assertEqual(c.get_title().startswith("key"), True) #select the first row selection = grid.get_selection() selection.select_path((0, )) selected_dict = grid.selected_rows[0] self.assertEqual(selected_dict["__extra"], ["boo", "biz", "baz"])
def test_use_custom_columns(self): """Ensure that type hins work so inferred types can be overridden and non-inferred type can be set. """ keys = ["id", "price", "bool?", "foo"] hints = { "id": StringColumn, "price": IntegerColumn, "bool?": CurrencyColumn, "foo": CheckColumn } dicts = [{"price": 100, "id": "asdfas", "bool?": 10.01, "foo": True}] grid = DictionaryGrid(dicts, keys=keys, type_hints=hints) for c in grid.get_columns(): key = c.key col_type = c.column_type if key == "id": self.assertEqual(col_type, gobject.TYPE_STRING) elif key == "price": self.assertEqual(col_type, gobject.TYPE_STRING) elif key == "bool?": self.assertEqual(col_type, gobject.TYPE_STRING) elif key == "foo": self.assertEqual(col_type, gobject.TYPE_INT) else: self.assertEqual("Extra key Found", False)