def test_variant_wrong_return_type(self):
        def callback(variant):
            return "no_variant"

        with capture_exceptions() as exc:
            # 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(len(exc), 1)
        self.assertEqual(exc[0].type, TypeError)
        self.assertTrue("return value" in str(exc[0].value), exc[0].value)
    def test_variant_wrong_return_type(self):
        def callback(variant):
            return 'no_variant'

        with capture_exceptions() as exc:
            # 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(len(exc), 1)
        self.assertEqual(exc[0].type, TypeError)
        self.assertTrue('return value' in str(exc[0].value), exc[0].value)
    def test_callback_exception(self):
        """
        This test ensures that we get errors from callbacks correctly
        and in particular that we do not segv when callbacks fail
        """
        def callback():
            x = 1 / 0
            self.fail('unexpected surviving zero divsion:' + str(x))

        # note that we do NOT expect the ZeroDivisionError to be propagated
        # through from the callback, as it crosses the Python<->C boundary
        # twice. (See GNOME #616279)
        with capture_exceptions() as exc:
            Everything.test_simple_callback(callback)
        self.assertTrue(exc)
        self.assertEqual(exc[0].type, ZeroDivisionError)
    def test_callback_exception(self):
        """
        This test ensures that we get errors from callbacks correctly
        and in particular that we do not segv when callbacks fail
        """

        def callback():
            x = 1 / 0
            self.fail("unexpected surviving zero divsion:" + str(x))

        # note that we do NOT expect the ZeroDivisionError to be propagated
        # through from the callback, as it crosses the Python<->C boundary
        # twice. (See GNOME #616279)
        with capture_exceptions() as exc:
            Everything.test_simple_callback(callback)
        self.assertTrue(exc)
        self.assertEqual(exc[0].type, ZeroDivisionError)