[pygobject] Make tests fail on CRITICAL logs, too, and apply to all tests



commit 39650906559fcc39b4be406fa7e25c4788d349a3
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Wed Mar 21 16:59:33 2012 +0100

    Make tests fail on CRITICAL logs, too, and apply to all tests
    
    Instead of setting warnings/criticals to fatal in individual test modules, do
    it in runtests.py, so that it applies to all tests.
    
    We currently have some tests which are known to generate CRITICALs (now marked
    with FIXME), and some WARNINGs (as they test behaviour with known-bad values).
    For these, warnings/criticals are now explicitly permitted.

 tests/runtests.py        |    1 +
 tests/test_gi.py         |    7 ++++++-
 tests/test_overrides.py  |   14 +++++++-------
 tests/test_properties.py |   36 +++++++++++++++++++++---------------
 4 files changed, 35 insertions(+), 23 deletions(-)
---
diff --git a/tests/runtests.py b/tests/runtests.py
index 2a8ecf4..fa58ede 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -13,6 +13,7 @@ if '--help' in sys.argv:
 
 # force untranslated messages, as we check for them in some tests
 os.environ['LC_MESSAGES'] = 'C'
+os.environ['G_DEBUG'] = 'fatal-warnings fatal-criticals'
 
 # Load tests.
 if 'TEST_NAMES' in os.environ:
diff --git a/tests/test_gi.py b/tests/test_gi.py
index edbe461..98bd361 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1974,11 +1974,16 @@ class TestPropertiesObject(unittest.TestCase):
 
     @unittest.expectedFailure
     def test_char(self):
-        # gobject-introspection thinks it has a guint8 type tag, which is wrong
+        # gobject-introspection thinks it has a guint8 type tag, which is
+        # wrong; this will raise an assertion critical which we need to ignore
+        old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING|
+                          GLib.LogLevelFlags.LEVEL_ERROR)
         self.assertEqual(self.obj.props.some_char, 0)
         self.obj.props.some_char = GObject.G_MAXINT8
         self.assertEqual(self.obj.props.some_char, GObject.G_MAXINT8)
 
+        GLib.log_set_always_fatal(old_mask)
+
     def test_uchar(self):
         self.assertEqual(self.obj.props.some_uchar, 0)
         self.obj.props.some_uchar = GObject.G_MAXUINT8
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 5a3457c..63433ba 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -19,11 +19,6 @@ 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):
@@ -1519,14 +1514,19 @@ class TestGtk(unittest.TestCase):
         store.append((0, "foo"))
         store.append((1, "bar"))
         view = Gtk.TreeView()
-        # We can't easily call get_cursor() to make sure this works as
-        # expected as we need to realize and focus the column
+        # FIXME: We can't easily call get_cursor() to make sure this works as
+        # expected as we need to realize and focus the column; the following
+        # will raise a Gtk-CRITICAL which we ignore for now
+        old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING|
+                          GLib.LogLevelFlags.LEVEL_ERROR)
         view.set_cursor(store[1].path)
         view.set_cursor(str(store[1].path))
 
         view.get_cell_area(store[1].path)
         view.get_cell_area(str(store[1].path))
 
+        GLib.log_set_always_fatal(old_mask)
+
     def test_tree_view_column(self):
         cell = Gtk.CellRendererText()
         column = Gtk.TreeViewColumn(title='This is just a test',
diff --git a/tests/test_properties.py b/tests/test_properties.py
index f7f8e25..7ecdf50 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -407,28 +407,34 @@ class TestProperty(unittest.TestCase):
             def __init__(self):
                 GObject.GObject.__init__(self)
 
-        o = C()
-        self.assertEqual(o.prop_int, 1)
+        # we test known-bad values here which cause Gtk-WARNING logs.
+        # Explicitly allow these for this test.
+        old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL)
+        try:
+            o = C()
+            self.assertEqual(o.prop_int, 1)
 
-        o.prop_int = 5
-        self.assertEqual(o.prop_int, 5)
+            o.prop_int = 5
+            self.assertEqual(o.prop_int, 5)
 
-        o.prop_int = 0
-        self.assertEqual(o.prop_int, 5)
+            o.prop_int = 0
+            self.assertEqual(o.prop_int, 5)
 
-        o.prop_int = 101
-        self.assertEqual(o.prop_int, 5)
+            o.prop_int = 101
+            self.assertEqual(o.prop_int, 5)
 
-        self.assertEqual(o.prop_float, 1.1)
+            self.assertEqual(o.prop_float, 1.1)
 
-        o.prop_float = 7.75
-        self.assertEqual(o.prop_float, 7.75)
+            o.prop_float = 7.75
+            self.assertEqual(o.prop_float, 7.75)
 
-        o.prop_float = 0.09
-        self.assertEqual(o.prop_float, 7.75)
+            o.prop_float = 0.09
+            self.assertEqual(o.prop_float, 7.75)
 
-        o.prop_float = 10.51
-        self.assertEqual(o.prop_float, 7.75)
+            o.prop_float = 10.51
+            self.assertEqual(o.prop_float, 7.75)
+        finally:
+            GLib.log_set_always_fatal(old_mask)
 
     def testMultipleInstances(self):
         class C(GObject.GObject):



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