diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2014-05-11 16:04:55 -0700 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2014-05-11 16:04:55 -0700 |
commit | 0a4f13a571cb9bd110f435f8b23ed942e3b007b0 (patch) | |
tree | 6154a8e810b8b20b4574ef83b8ad53d1b85159ba /tests/test_error.py | |
parent | bc7b0b69f651a118a053106fcae2d7c0f2173430 (diff) | |
download | pygobject-0a4f13a571cb9bd110f435f8b23ed942e3b007b0.tar.gz |
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.
Diffstat (limited to 'tests/test_error.py')
-rw-r--r-- | 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 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__': |