From 0a4f13a571cb9bd110f435f8b23ed942e3b007b0 Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Sun, 11 May 2014 16:04:55 -0700 Subject: 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 file changed, 6 insertions(+), 8 deletions(-) (limited to 'tests/test_error.py') diff --git a/tests/test_error.py b/tests/test_error.py index f3922488..baccef5c 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__': -- cgit v1.2.1