[pygobject] test_everything: Add test for callback returning wrong type



commit 0c0fb8ef88a2c61cf95cd1cb96f6d5f296cad5fc
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Nov 14 09:27:42 2012 +0100

    test_everything: Add test for callback returning wrong type
    
    This covers the "expected a GVariant, got something else" check in
    pyg_value_from_pyobject().

 tests/test_everything.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 26798f2..f1f14b7 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -914,6 +914,22 @@ class TestClosures(unittest.TestCase):
         self.assertRaises(TypeError, Everything.test_closure_variant, callback, 'foo')
         self.assertFalse(self.called)
 
+    def test_variant_wrong_return_type(self):
+        def callback(variant):
+            return 'no_variant'
+
+        # reset last error
+        sys.last_type = None
+
+        # this does not directly raise an exception (see
+        # https://bugzilla.gnome.org/show_bug.cgi?id=616279)
+        result = Everything.test_closure_variant(callback, GLib.Variant('i', 42))
+        # ... but the result shouldn't be a string
+        self.assertEqual(result, None)
+        # and the error should be shown
+        self.assertEqual(sys.last_type, TypeError)
+        self.assertTrue('return value' in str(sys.last_value), sys.last_value)
+
 
 @unittest.skipUnless(has_cairo, 'built without cairo support')
 class TestProperties(unittest.TestCase):



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