Пример #1
0
    def test_empty_construction(self):
        """Test a simple creating An AsynchTaskProgressBox 
        and then adding keys and dictionaries after creation

        """
        grid = DictionaryGrid()
        self.assertEqual((grid != None), True)
        grid.keys = ["key1", "key2"]
        self.assertEqual(grid.get_model().get_n_columns(), 3)
        grid.append_row({"key1": "val11", "key2": "val12"})
        self.assertEqual(len(grid.get_model()), 1)
    def test_with_set_column_titles(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(dictionaries = dicts, keys=["key1_1","key1_2","key1_3"])
        titles = {"key1_1":"KEY1","key1_2":"KEY2","key1_3":"KEY3"}
        grid.set_column_titles(titles)
        grid_filter = GridFilter(grid)

        filter_row = grid_filter.rows[0]
        column_combo = filter_row.get_children()[0].get_children()[0]
        #make sure the correct titles are appearing
        itr = column_combo.get_model().get_iter(0)
        self.assertEqual(column_combo.get_model().get_value(itr,0),"KEY1")

        itr = column_combo.get_model().get_iter(1)
        self.assertEqual(column_combo.get_model().get_value(itr,0),"KEY2")

        itr = column_combo.get_model().get_iter(2)
        self.assertEqual(column_combo.get_model().get_value(itr,0),"KEY3")

        #make sure filtering still works
        filter_combo = filter_row.get_children()[1].get_children()[0].get_children()[0]
        filter_combo.set_active(1)
        entry = filter_row.get_children()[1].get_children()[0].get_children()[1]
        entry.set_text("val5_1")
        self.assertEqual(len(grid.get_model()),4)
Пример #3
0
    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"])
Пример #4
0
    def test_constructor_with_dicts(self):
        """test creating a grid with dictionaries in the contructor"""
        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"
        }]

        #build the CouchGrid
        grid = DictionaryGrid(dicts)
        self.assertEqual(grid.get_model().get_n_columns(), 4)
        self.assertEqual(len(grid.get_model()), 2)
Пример #5
0
    def test_remove_selected_rows(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)
        selection = grid.get_selection()
        grid.remove_selected_rows()

        #select the last row and remove it
        selection.select_path((4, ))
        grid.remove_selected_rows()

        #the last row should then be selected and there should be 4 rows now
        self.assertEqual(len(grid.get_model()), 4)
        self.assertEqual(len(grid.selected_rows), 1)
        self.assertEqual(grid.selected_rows[0]["key1_1"], "val4_1")

        #select the first and third rows and remove them
        selection = grid.get_selection()
        selection.unselect_all()
        selection.select_path((0, ))
        selection.select_path((2, ))
        grid.remove_selected_rows()

        #make sure the now last row is selected, and there are 2 rows left
        self.assertEqual(len(grid.get_model()), 2)
        self.assertEqual(len(grid.selected_rows), 1)
        self.assertEqual(grid.selected_rows[0]["key1_2"], "val4_2")
 def test_create_a_grid(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_filter = GridFilter(grid)
     self.assertEqual(len(grid.get_model()),5)
Пример #7
0
    def test_constructor_with_dicts_and_keys(self):
        """test creating a grid with dictionaries in the contructor
        as well as keys in the contructor, with fewer keys than
        items in the dictionary

        """
        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"
        }]
        keys = ["key1_1", "key1_3"]

        #build the CouchGrid
        grid = DictionaryGrid(dicts, keys)
        self.assertEqual(grid.get_model().get_n_columns(), 4)
        self.assertEqual(len(grid.get_model()), 2)
 def test_filter_a_row(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_filter = GridFilter(grid)
     filter_row = grid_filter.rows[0]
     filter_combo = filter_row.get_children()[1].get_children()[0].get_children()[0]
     filter_combo.set_active(1)
     entry = filter_row.get_children()[1].get_children()[0].get_children()[1]
     entry.set_text("val5_1")
     self.assertEqual(len(grid.get_model()),4)
Пример #9
0
    def test_dicts_with_different_keys(self):
        dicts = [{
            "key1_1": "val1_1",
            "key1_2": "val1_2",
            "__extra": ["boo", "biz", "baz"]
        }, {
            "key2_1": "val2_1",
            "key2_2": "val2_2",
            "__extra": self
        }]
        grid = DictionaryGrid(dicts)

        #make sure there are 5 columns
        self.assertEqual(grid.get_model().get_n_columns(), 5)
    def test_remove_selected_with_filter(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_filter = GridFilter(grid)
        filter_row = grid_filter.rows[0]
        filter_combo = filter_row.get_children()[1].get_children()[0].get_children()[0]
        filter_combo.set_active(1)
        entry = filter_row.get_children()[1].get_children()[0].get_children()[1]
        entry.set_text("val5_1")
                
        selection = grid.get_selection()
        selection.select_path((1,))
        selection.select_path((2,))

        grid.remove_selected_rows()

        self.assertEqual(len(grid.get_model()),2)
Пример #11
0
 def test_NONE_values(self):
     keys = ["id", "price", "bool?", "foo"]
     dicts = [{"price": None, "id": None, "bool?": None, "foo": None}]
     grid = DictionaryGrid(dicts)
     self.assertEqual(len(grid.get_model()), 1)