[pygobject] test_mainloop code cleanup



commit 3fb13cc05a281970c3a624c2dd152996031b482c
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Oct 22 11:36:49 2012 +0200

    test_mainloop code cleanup
    
    Ensure that sys.excepthook is always restored, even if the test fails. Use the
    assert{True,False,Equal} unittest API instead of simple asserts for more useful
    failure messages.

 tests/test_mainloop.py |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 4c7794a..408a123 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -41,23 +41,24 @@ class TestMainLoop(unittest.TestCase):
         os.close(pipe_w)
 
         def excepthook(type, value, traceback):
-            assert type is Exception
-            assert value.args[0] == "deadbabe"
+            self.assertTrue(type is Exception)
+            self.assertEqual(value.args[0], "deadbabe")
         sys.excepthook = excepthook
-
-        got_exception = False
         try:
-            loop.run()
-        except:
-            got_exception = True
+            got_exception = False
+            try:
+                loop.run()
+            except:
+                got_exception = True
+        finally:
+            sys.excepthook = sys.__excepthook__
 
         #
         # The exception should be handled (by printing it)
         # immediately on return from child_died() rather
         # than here. See bug #303573
         #
-        sys.excepthook = sys.__excepthook__
-        assert not got_exception
+        self.assertFalse(got_exception)
 
     def test_concurrency(self):
         def on_usr1(signum, frame):



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