[pygobject] tests: Ignore warnings for GtkAlignment



commit c3d3cd2f798cbae7f66d8e57e191b5f9569a713b
Author: Simon Feltman <sfeltman src gnome org>
Date:   Fri Jul 25 17:49:57 2014 -0700

    tests: Ignore warnings for GtkAlignment
    
    This was causing unittests to bail. Even though this is deprecated,
    we still need to test its usage in the context of pygtkcompat.

 tests/compat_test_pygtk.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/tests/compat_test_pygtk.py b/tests/compat_test_pygtk.py
index 10be6a3..f0126c3 100644
--- a/tests/compat_test_pygtk.py
+++ b/tests/compat_test_pygtk.py
@@ -2,6 +2,7 @@
 # vim: tabstop=4 shiftwidth=4 expandtab
 
 import unittest
+import contextlib
 
 from gi.repository import GLib
 
@@ -26,6 +27,15 @@ except ImportError:
     Gtk = None
 
 
+ contextlib contextmanager
+def ignore_glib_warnings():
+    """Temporarily change GLib logging to not bail on warnings."""
+    old_mask = GLib.log_set_always_fatal(
+        GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
+    yield
+    GLib.log_set_always_fatal(old_mask)
+
+
 @unittest.skipUnless(Gtk, 'Gtk not available')
 class TestATKCompat(unittest.TestCase):
     def test_object(self):
@@ -69,7 +79,10 @@ class TestGTKCompat(unittest.TestCase):
                                    gtk.gdk.Color))
 
     def test_alignment(self):
-        a = gtk.Alignment()
+        # Creation of pygtk.Alignment causes hard warnings, ignore this in testing.
+        with ignore_glib_warnings():
+            a = gtk.Alignment()
+
         self.assertEqual(a.props.xalign, 0.0)
         self.assertEqual(a.props.yalign, 0.0)
         self.assertEqual(a.props.xscale, 0.0)


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