[pygobject] tests: Use assertRaises as a context manager for GError test



commit 0a4f13a571cb9bd110f435f8b23ed942e3b007b0
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun May 11 16:04:55 2014 -0700

    tests: Use assertRaises as a context manager for GError test
    
    Simplify tests/test_error.py:TestMarshalling.test_exception so that
    it no longer needs to pull exception information out of sys.exc_info.

 tests/test_error.py |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
---
diff --git a/tests/test_error.py b/tests/test_error.py
index f392248..baccef5 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -22,7 +22,6 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 # USA
 
-import sys
 import unittest
 
 from gi.repository import GLib
@@ -104,14 +103,13 @@ class TestMarshalling(unittest.TestCase):
         self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
 
     def test_exception(self):
-        self.assertRaises(GLib.Error, GIMarshallingTests.gerror)
-        try:
+        with self.assertRaises(GLib.Error) as context:
             GIMarshallingTests.gerror()
-        except Exception:
-            etype, e = sys.exc_info()[:2]
-            self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
-            self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
-            self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
+
+        e = context.exception
+        self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
+        self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
+        self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
 
 
 if __name__ == '__main__':


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