[pygobject/pygobject-3-2] Fix warnings on None values in added tree/list store rows



commit 1b3f8b1fde2ba25592eb038341eabf6157f12c25
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Wed Mar 21 14:34:36 2012 +0100

    Fix warnings on None values in added tree/list store rows
    
    Commit bf8c95836e1c changed the List/TreeStore overrides to use
    insert_with_valuesv(), but supplied all columns instead of just those which are
    not None. With this, None values cause warnings like
    
    (runtests.py:12375): Gtk-WARNING **: /build/buildd/gtk+3.0-3.3.20/./gtk/gtkliststore.c:851: Unable to convert from (null) to gboolean
    
    Update the tests to make warnings fatal, to catch this better.
    
    Change _convert_row() to skip the None entries and return the list of not-None
    columns, and use the latter instead of a simple range(n_columns). This matches
    the behaviour before bf8c95836e1c, where columns with None values were skipped
    as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672463

 gi/overrides/Gtk.py     |   26 ++++++++++++++------------
 tests/test_overrides.py |    5 +++++
 2 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 9d3ba0a..4018b32 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -809,19 +809,23 @@ class TreeModel(Gtk.TreeModel):
             raise ValueError('row sequence has the incorrect number of elements')
 
         result = []
-        for i in range(n_columns):
-            value = row[i]
-            result.append(self._convert_value(i, value))
-        return result
+        columns = []
+        for cur_col, value in enumerate(row):
+            # do not try to set None values, they are causing warnings
+            if value is None:
+                continue
+            result.append(self._convert_value(cur_col, value))
+            columns.append(cur_col)
+        return (result, columns)
 
     def set_row(self, treeiter, row):
-        converted_row = self._convert_row(row)
-        for i in range(self.get_n_columns()):
-            value = row[i]
+        converted_row, columns = self._convert_row(row)
+        for column in columns:
+            value = row[column]
             if value is None:
                continue  # None means skip this row
 
-            self.set_value(treeiter, i, value)
+            self.set_value(treeiter, column, value)
 
     def _convert_value(self, column, value):
             if value is None:
@@ -949,8 +953,7 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
 
     def _do_insert(self, position, row):
         if row is not None:
-            row = self._convert_row(row)
-            columns = range(len(row))
+            row, columns = self._convert_row(row)
             treeiter = self.insert_with_valuesv(position, columns, row)
         else:
             treeiter = Gtk.ListStore.insert(self, position)
@@ -1179,8 +1182,7 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
 
     def _do_insert(self, parent, position, row):
         if row is not None:
-            row = self._convert_row(row)
-            columns = range(len(row))
+            row, columns = self._convert_row(row)
             treeiter = self.insert_with_values(parent, position, columns, row)
         else:
             treeiter = Gtk.TreeStore.insert(self, parent, position)
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 58c77bf..5a3457c 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -19,6 +19,11 @@ from gi.repository import GdkPixbuf
 import gi.overrides as overrides
 import gi.types
 
+# in general we don't want tests to raise warnings, except when explicitly
+# testing with bad values; in those cases it will temporarily be set back to
+# ERROR
+GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING)
+
 class TestGLib(unittest.TestCase):
 
     def test_gvariant_create(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]