[pygobject] tests: Ensure that the fatal mask is always reset



commit 1b5c9b3d1499b3bc59afb297672abc671e175546
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Nov 7 12:05:24 2012 +0100

    tests: Ensure that the fatal mask is always reset
    
    On test case failures the fatal mask might be left in a wrong state, so ensure
    with "finally" that it is reset on failed tests as well, to avoid hiding other
    failures.

 tests/test_gi.py            |   11 ++++++-----
 tests/test_overrides_gtk.py |   33 +++++++++++++++++++--------------
 tests/test_pygtkcompat.py   |    6 ++++--
 tests/test_signal.py        |    6 ++++--
 4 files changed, 33 insertions(+), 23 deletions(-)
---
diff --git a/tests/test_gi.py b/tests/test_gi.py
index ac2418b..27c507d 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2202,11 +2202,12 @@ class TestPropertiesObject(unittest.TestCase):
         # 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)
+        try:
+            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)
+        finally:
+            GLib.log_set_always_fatal(old_mask)
 
         obj = GIMarshallingTests.PropertiesObject(some_char=-42)
         self.assertEqual(obj.props.some_char, -42)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index c39f793..6148479 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1309,13 +1309,14 @@ class TestTreeView(unittest.TestCase):
         # 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))
+        try:
+            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)
+            view.get_cell_area(store[1].path)
+            view.get_cell_area(str(store[1].path))
+        finally:
+            GLib.log_set_always_fatal(old_mask)
 
     def test_tree_view_column(self):
         cell = Gtk.CellRendererText()
@@ -1346,10 +1347,12 @@ class TestTreeView(unittest.TestCase):
         # might cause a Pango warning, do not break on this
         old_mask = GLib.log_set_always_fatal(
             GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
-        # causes the widget to get realized and cellN.props.text receive a
-        # value, otherwise it will be None.
-        tree.get_preferred_size()
-        GLib.log_set_always_fatal(old_mask)
+        try:
+            # causes the widget to get realized and cellN.props.text receive a
+            # value, otherwise it will be None.
+            tree.get_preferred_size()
+        finally:
+            GLib.log_set_always_fatal(old_mask)
 
         self.assertEqual(tree.get_column(0).get_title(), 'Head1')
         self.assertEqual(tree.get_column(1).get_title(), 'Head2')
@@ -1381,10 +1384,12 @@ class TestTreeView(unittest.TestCase):
         # might cause a Pango warning, do not break on this
         old_mask = GLib.log_set_always_fatal(
             GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
-        # This will make cell.props.text receive a value, otherwise it
-        # will be None.
-        treeview.get_preferred_size()
-        GLib.log_set_always_fatal(old_mask)
+        try:
+            # This will make cell.props.text receive a value, otherwise it
+            # will be None.
+            treeview.get_preferred_size()
+        finally:
+            GLib.log_set_always_fatal(old_mask)
 
         self.assertTrue(cell.props.text in directors)
 
diff --git a/tests/test_pygtkcompat.py b/tests/test_pygtkcompat.py
index 9b58af0..c6fde25 100644
--- a/tests/test_pygtkcompat.py
+++ b/tests/test_pygtkcompat.py
@@ -102,8 +102,10 @@ class TestGTKCompat(unittest.TestCase):
         # might cause a Pango warning, do not break on this
         old_mask = GLib.log_set_always_fatal(
             GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
-        combo = gtk.ComboBoxEntry(model=liststore)
-        GLib.log_set_always_fatal(old_mask)
+        try:
+            combo = gtk.ComboBoxEntry(model=liststore)
+        finally:
+            GLib.log_set_always_fatal(old_mask)
         combo.set_text_column(1)
         combo.set_active(0)
         self.assertEqual(combo.get_text_column(), 1)
diff --git a/tests/test_signal.py b/tests/test_signal.py
index fb2cb24..fc8c835 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -77,8 +77,10 @@ class TestGSignalsError(unittest.TestCase):
         # do not stumble over the warning thrown by GLib
         old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL |
                                              GLib.LogLevelFlags.LEVEL_ERROR)
-        self.assertRaises(TypeError, foo)
-        GLib.log_set_always_fatal(old_mask)
+        try:
+            self.assertRaises(TypeError, foo)
+        finally:
+            GLib.log_set_always_fatal(old_mask)
         gc.collect()
 
 



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