Example #1
0
    def test_cairo_context_full_in(self):
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
        context = cairo.Context(surface)
        Regress.test_cairo_context_full_in(context)

        with pytest.raises(TypeError):
            Regress.test_cairo_context_full_in(object())
Example #2
0
    def test_variant(self):
        v = Everything.test_gvariant_i()
        self.assertEqual(v.get_type_string(), "i")
        self.assertEqual(v.get_int32(), 1)

        v = Everything.test_gvariant_s()
        self.assertEqual(v.get_type_string(), "s")
        self.assertEqual(v.get_string(), "one")

        v = Everything.test_gvariant_v()
        self.assertEqual(v.get_type_string(), "v")
        vi = v.get_variant()
        self.assertEqual(vi.get_type_string(), "s")
        self.assertEqual(vi.get_string(), "contents")

        v = Everything.test_gvariant_as()
        self.assertEqual(v.get_type_string(), "as")
        self.assertEqual(v.get_strv(), ["one", "two", "three"])

        v = Everything.test_gvariant_asv()
        self.assertEqual(v.get_type_string(), "a{sv}")
        self.assertEqual(v.lookup_value("nosuchkey", None), None)
        name = v.lookup_value("name", None)
        self.assertEqual(name.get_string(), "foo")
        timeout = v.lookup_value("timeout", None)
        self.assertEqual(timeout.get_int32(), 10)
Example #3
0
    def test_variant(self):
        v = Everything.test_gvariant_i()
        self.assertEqual(v.get_type_string(), 'i')
        self.assertEqual(v.get_int32(), 1)

        v = Everything.test_gvariant_s()
        self.assertEqual(v.get_type_string(), 's')
        self.assertEqual(v.get_string(), 'one')

        v = Everything.test_gvariant_v()
        self.assertEqual(v.get_type_string(), 'v')
        vi = v.get_variant()
        self.assertEqual(vi.get_type_string(), 's')
        self.assertEqual(vi.get_string(), 'contents')

        v = Everything.test_gvariant_as()
        self.assertEqual(v.get_type_string(), 'as')
        self.assertEqual(v.get_strv(), ['one', 'two', 'three'])

        v = Everything.test_gvariant_asv()
        self.assertEqual(v.get_type_string(), 'a{sv}')
        self.assertEqual(v.lookup_value('nosuchkey', None), None)
        name = v.lookup_value('name', None)
        self.assertEqual(name.get_string(), 'foo')
        timeout = v.lookup_value('timeout', None)
        self.assertEqual(timeout.get_int32(), 10)
Example #4
0
    def test_double(self):
        self.assertEqual(Everything.test_double(GLib.MAXDOUBLE), GLib.MAXDOUBLE)
        self.assertEqual(Everything.test_double(GLib.MINDOUBLE), GLib.MINDOUBLE)

        (two, three) = Everything.test_multi_double_args(2.5)
        self.assertAlmostEqual(two, 5.0)
        self.assertAlmostEqual(three, 7.5)
Example #5
0
    def test_callback_scope_async(self):
        TestCallbacks.called = False
        ud = 'Test Value 44'

        def callback(user_data):
            self.assertEqual(user_data, ud)
            TestCallbacks.called = True
            return 44

        ud_refcount = sys.getrefcount(ud)
        callback_refcount = sys.getrefcount(callback)

        self.assertEqual(Everything.test_callback_async(callback, ud), None)
        # Callback should not have run and the ref count is increased by 1
        self.assertEqual(TestCallbacks.called, False)
        self.assertEqual(sys.getrefcount(callback), callback_refcount + 1)
        self.assertEqual(sys.getrefcount(ud), ud_refcount + 1)

        # test_callback_thaw_async will run the callback previously supplied.
        # references should be auto decremented after this call.
        self.assertEqual(Everything.test_callback_thaw_async(), 44)
        self.assertTrue(TestCallbacks.called)

        # Make sure refcounts are returned to normal
        self.assertEqual(sys.getrefcount(callback), callback_refcount)
        self.assertEqual(sys.getrefcount(ud), ud_refcount)
Example #6
0
    def test_callback_scope_notified_with_destroy(self):
        TestCallbacks.called = 0
        ud = 'Test scope notified data 33'

        def callback(user_data):
            self.assertEqual(user_data, ud)
            TestCallbacks.called += 1
            return 33

        value_refcount = sys.getrefcount(ud)
        callback_refcount = sys.getrefcount(callback)

        # Callback is immediately called.
        for i in range(100):
            res = Everything.test_callback_destroy_notify(callback, ud)
            self.assertEqual(res, 33)

        self.assertEqual(TestCallbacks.called, 100)
        self.assertEqual(sys.getrefcount(callback), callback_refcount + 100)
        self.assertEqual(sys.getrefcount(ud), value_refcount + 100)

        # thaw will call the callback again, this time resources should be freed
        self.assertEqual(Everything.test_callback_thaw_notifications(), 33 * 100)
        self.assertEqual(TestCallbacks.called, 200)
        self.assertEqual(sys.getrefcount(callback), callback_refcount)
        self.assertEqual(sys.getrefcount(ud), value_refcount)
Example #7
0
    def test_callback(self):
        TestCallbacks.called = False
        def callback():
            TestCallbacks.called = True

        Everything.test_simple_callback(callback)
        self.assertTrue(TestCallbacks.called)
Example #8
0
    def test_cairo_context(self):
        context = Everything.test_cairo_context_full_return()
        self.assertTrue(isinstance(context, cairo.Context))

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
        context = cairo.Context(surface)
        Everything.test_cairo_context_none_in(context)
Example #9
0
    def test_callback_null_gerror(self):
        def callback(error):
            self.assertEqual(error, None)
            TestCallbacks.called = True

        TestCallbacks.called = False
        Everything.test_null_gerror_callback(callback)
        self.assertTrue(TestCallbacks.called)
Example #10
0
    def test_unichar(self):
        self.assertEqual("c", Everything.test_unichar("c"))

        if sys.version_info < (3, 0):
            self.assertEqual(UNICHAR, Everything.test_unichar(PY2_UNICODE_UNICHAR))
        self.assertEqual(UNICHAR, Everything.test_unichar(UNICHAR))
        self.assertRaises(TypeError, Everything.test_unichar, "")
        self.assertRaises(TypeError, Everything.test_unichar, "morethanonechar")
Example #11
0
    def test_array_fixed_size(self):
        # fixed length of 5
        self.assertEqual(Everything.test_array_fixed_size_int_in([1, 2, -10, 5, 3]), 1)
        self.assertRaises(ValueError, Everything.test_array_fixed_size_int_in, [1, 2, 3, 4])
        self.assertRaises(ValueError, Everything.test_array_fixed_size_int_in, [1, 2, 3, 4, 5, 6])

        self.assertEqual(Everything.test_array_fixed_size_int_out(), [0, 1, 2, 3, 4])
        self.assertEqual(Everything.test_array_fixed_size_int_return(), [0, 1, 2, 3, 4])
Example #12
0
    def test_callback_scope_call(self):
        TestCallbacks.called = 0
        def callback():
            TestCallbacks.called += 1
            return 0

        Everything.test_multi_callback(callback)
        self.assertEquals(TestCallbacks.called, 2)
Example #13
0
    def test_short(self):
        self.assertEqual(Everything.test_short(GLib.MAXSHORT), GLib.MAXSHORT)
        self.assertEqual(Everything.test_short(GLib.MINSHORT), GLib.MINSHORT)
        self.assertRaises(OverflowError, Everything.test_short, GLib.MAXSHORT + 1)

        self.assertEqual(Everything.test_ushort(GLib.MAXUSHORT), GLib.MAXUSHORT)
        self.assertEqual(Everything.test_ushort(0), 0)
        self.assertRaises(OverflowError, Everything.test_ushort, -1)
        self.assertRaises(OverflowError, Everything.test_ushort, GLib.MAXUSHORT + 1)
Example #14
0
    def test_int(self):
        self.assertEqual(Everything.test_int(GLib.MAXINT), GLib.MAXINT)
        self.assertEqual(Everything.test_int(GLib.MININT), GLib.MININT)
        self.assertRaises(OverflowError, Everything.test_int, GLib.MAXINT + 1)

        self.assertEqual(Everything.test_uint(GLib.MAXUINT), GLib.MAXUINT)
        self.assertEqual(Everything.test_uint(0), 0)
        self.assertRaises(OverflowError, Everything.test_uint, -1)
        self.assertRaises(OverflowError, Everything.test_uint, GLib.MAXUINT + 1)
Example #15
0
    def test_long(self):
        self.assertEqual(Everything.test_long(GLib.MAXLONG), GLib.MAXLONG)
        self.assertEqual(Everything.test_long(GLib.MINLONG), GLib.MINLONG)
        self.assertRaises(OverflowError, Everything.test_long, GLib.MAXLONG + 1)

        self.assertEqual(Everything.test_ulong(GLib.MAXULONG), GLib.MAXULONG)
        self.assertEqual(Everything.test_ulong(0), 0)
        self.assertRaises(OverflowError, Everything.test_ulong, -1)
        self.assertRaises(OverflowError, Everything.test_ulong, GLib.MAXULONG + 1)
Example #16
0
    def test_size(self):
        self.assertEqual(Everything.test_ssize(GLib.MAXSSIZE), GLib.MAXSSIZE)
        self.assertEqual(Everything.test_ssize(GLib.MINSSIZE), GLib.MINSSIZE)
        self.assertRaises(OverflowError, Everything.test_ssize, GLib.MAXSSIZE + 1)

        self.assertEqual(Everything.test_size(GLib.MAXSIZE), GLib.MAXSIZE)
        self.assertEqual(Everything.test_size(0), 0)
        self.assertRaises(OverflowError, Everything.test_size, -1)
        self.assertRaises(OverflowError, Everything.test_size, GLib.MAXSIZE + 1)
Example #17
0
    def test_cairo_path_none_in(self):
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
        context = cairo.Context(surface)
        path = context.copy_path()
        Regress.test_cairo_path_none_in(path)
        surface.finish()

        with pytest.raises(TypeError):
            Regress.test_cairo_path_none_in(object())
Example #18
0
    def test_int16(self):
        self.assertEqual(Everything.test_int16(GLib.MAXINT16), GLib.MAXINT16)
        self.assertEqual(Everything.test_int16(GLib.MININT16), GLib.MININT16)
        self.assertRaises(OverflowError, Everything.test_int16, GLib.MAXINT16 + 1)

        self.assertEqual(Everything.test_uint16(GLib.MAXUINT16), GLib.MAXUINT16)
        self.assertEqual(Everything.test_uint16(0), 0)
        self.assertRaises(OverflowError, Everything.test_uint16, -1)
        self.assertRaises(OverflowError, Everything.test_uint16, GLib.MAXUINT16 + 1)
Example #19
0
    def test_int64(self):
        self.assertEqual(Everything.test_int64(GLib.MAXINT64), GLib.MAXINT64)
        self.assertEqual(Everything.test_int64(GLib.MININT64), GLib.MININT64)
        self.assertRaises(OverflowError, Everything.test_int64, GLib.MAXINT64 + 1)

        self.assertEqual(Everything.test_uint64(GLib.MAXUINT64), GLib.MAXUINT64)
        self.assertEqual(Everything.test_uint64(0), 0)
        self.assertRaises(OverflowError, Everything.test_uint64, -1)
        self.assertRaises(OverflowError, Everything.test_uint64, GLib.MAXUINT64 + 1)
Example #20
0
    def test_int32(self):
        self.assertEqual(Everything.test_int32(GLib.MAXINT32), GLib.MAXINT32)
        self.assertEqual(Everything.test_int32(GLib.MININT32), GLib.MININT32)
        self.assertRaises(OverflowError, Everything.test_int32, GLib.MAXINT32 + 1)

        self.assertEqual(Everything.test_uint32(GLib.MAXUINT32), GLib.MAXUINT32)
        self.assertEqual(Everything.test_uint32(0), 0)
        self.assertRaises(OverflowError, Everything.test_uint32, -1)
        self.assertRaises(OverflowError, Everything.test_uint32, GLib.MAXUINT32 + 1)
Example #21
0
    def test_callback_destroy_notify(self):
        def callback(user_data):
            TestCallbacks.called = True
            return 42

        TestCallbacks.called = False
        self.assertEqual(Everything.test_callback_destroy_notify(callback, 42), 42)
        self.assertTrue(TestCallbacks.called)
        self.assertEqual(Everything.test_callback_thaw_notifications(), 42)
Example #22
0
    def test_int8(self):
        self.assertEqual(Everything.test_int8(GLib.MAXINT8), GLib.MAXINT8)
        self.assertEqual(Everything.test_int8(GLib.MININT8), GLib.MININT8)
        self.assertRaises(OverflowError, Everything.test_int8, GLib.MAXINT8 + 1)

        self.assertEqual(Everything.test_uint8(GLib.MAXUINT8), GLib.MAXUINT8)
        self.assertEqual(Everything.test_uint8(0), 0)
        self.assertRaises(OverflowError, Everything.test_uint8, -1)
        self.assertRaises(OverflowError, Everything.test_uint8, GLib.MAXUINT8 + 1)
Example #23
0
    def test_callback_gerror(self):
        def callback(error):
            self.assertEqual(error.message, 'regression test error')
            self.assertTrue('g-io' in error.domain)
            self.assertEqual(error.code, Gio.IOErrorEnum.NOT_SUPPORTED)
            TestCallbacks.called = True

        TestCallbacks.called = False
        Everything.test_gerror_callback(callback)
        self.assertTrue(TestCallbacks.called)
Example #24
0
    def test_callback_async(self):
        TestCallbacks.called = False
        def callback(foo):
            TestCallbacks.called = True
            return foo

        Everything.test_callback_async(callback, 44);
        i = Everything.test_callback_thaw_async();
        self.assertEquals(44, i);
        self.assertTrue(TestCallbacks.called)
Example #25
0
    def test_ptrarray(self):
        # transfer container
        result = Everything.test_garray_container_return()
        self.assertEqual(result, ['regress'])
        result = None

        # transfer full
        result = Everything.test_garray_full_return()
        self.assertEqual(result, ['regress'])
        result = None
Example #26
0
    def test_callback_owned_gerror(self):
        def callback(error):
            self.assertEqual(error.message, 'regression test owned error')
            self.assertTrue('g-io' in error.domain)
            self.assertEqual(error.code, Gio.IOErrorEnum.PERMISSION_DENIED)
            TestCallbacks.called = True

        TestCallbacks.called = False
        Everything.test_owned_gerror_callback(callback)
        self.assertTrue(TestCallbacks.called)
Example #27
0
 def test_hash_in_with_gvalue_strv(self):
     data = {'integer': 12,
             'boolean': True,
             'string': 'some text',
             'strings': GObject.Value(GObject.TYPE_STRV, ['first', 'second', 'third']),
             'flags': Everything.TestFlags.FLAG1 | Everything.TestFlags.FLAG3,
             'enum': Everything.TestEnum.VALUE2,
            }
     Everything.test_ghash_gvalue_in(data)
     data = None
Example #28
0
 def test_hash_in_with_gvalue_strv(self):
     data = {
         "integer": 12,
         "boolean": True,
         "string": "some text",
         "strings": GObject.Value(GObject.TYPE_STRV, ["first", "second", "third"]),
         "flags": Everything.TestFlags.FLAG1 | Everything.TestFlags.FLAG3,
         "enum": Everything.TestEnum.VALUE2,
     }
     Everything.test_ghash_gvalue_in(data)
     data = None
Example #29
0
    def test_callback_hashtable(self):
        def callback(data):
            self.assertEqual(data, mydict)
            mydict['new'] = 42
            TestCallbacks.called = True

        mydict = {'foo': 1, 'bar': 2}
        TestCallbacks.called = False
        Everything.test_hash_table_callback(mydict, callback)
        self.assertTrue(TestCallbacks.called)
        self.assertEqual(mydict, {'foo': 1, 'bar': 2, 'new': 42})
Example #30
0
    def test_callback_hashtable(self):
        def callback(data):
            self.assertEqual(data, mydict)
            mydict["new"] = 42
            TestCallbacks.called = True

        mydict = {"foo": 1, "bar": 2}
        TestCallbacks.called = False
        Everything.test_hash_table_callback(mydict, callback)
        self.assertTrue(TestCallbacks.called)
        self.assertEqual(mydict, {"foo": 1, "bar": 2, "new": 42})
Example #31
0
    def test_hash_in_with_typed_strv(self):
        class GStrv(list):
            __gtype__ = GObject.TYPE_STRV

        data = {
            'integer': 12,
            'boolean': True,
            'string': 'some text',
            'strings': GStrv(['first', 'second', 'third']),
            'flags': Everything.TestFlags.FLAG1 | Everything.TestFlags.FLAG3,
            'enum': Everything.TestEnum.VALUE2,
        }
        Everything.test_ghash_gvalue_in(data)
        data = None
Example #32
0
    def test_int32(self):
        self.assertEqual(Everything.test_int32(GObject.G_MAXINT32),
                         GObject.G_MAXINT32)
        self.assertEqual(Everything.test_int32(GObject.G_MININT32),
                         GObject.G_MININT32)
        self.assertRaises(tests.GIOverflowError, Everything.test_int32,
                          GObject.G_MAXINT32 + 1)

        self.assertEqual(Everything.test_uint32(GObject.G_MAXUINT32),
                         GObject.G_MAXUINT32)
        self.assertEqual(Everything.test_uint32(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint32, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint32,
                          GObject.G_MAXUINT32 + 1)
Example #33
0
    def test_int16(self):
        self.assertEqual(Everything.test_int16(GObject.G_MAXINT16),
                         GObject.G_MAXINT16)
        self.assertEqual(Everything.test_int16(GObject.G_MININT16),
                         GObject.G_MININT16)
        self.assertRaises(tests.GIOverflowError, Everything.test_int16,
                          GObject.G_MAXINT16 + 1)

        self.assertEqual(Everything.test_uint16(GObject.G_MAXUINT16),
                         GObject.G_MAXUINT16)
        self.assertEqual(Everything.test_uint16(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint16, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint16,
                          GObject.G_MAXUINT16 + 1)
Example #34
0
    def test_int64(self):
        self.assertEqual(Everything.test_int64(GObject.G_MAXINT64),
                         GObject.G_MAXINT64)
        self.assertEqual(Everything.test_int64(GObject.G_MININT64),
                         GObject.G_MININT64)
        self.assertRaises(tests.GIOverflowError, Everything.test_int64,
                          GObject.G_MAXINT64 + 1)

        self.assertEqual(Everything.test_uint64(GObject.G_MAXUINT64),
                         GObject.G_MAXUINT64)
        self.assertEqual(Everything.test_uint64(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint64, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint64,
                          GObject.G_MAXUINT64 + 1)
Example #35
0
    def test_short(self):
        self.assertEqual(Everything.test_short(GObject.G_MAXSHORT),
                         GObject.G_MAXSHORT)
        self.assertEqual(Everything.test_short(GObject.G_MINSHORT),
                         GObject.G_MINSHORT)
        self.assertRaises(tests.GIOverflowError, Everything.test_short,
                          GObject.G_MAXSHORT + 1)

        self.assertEqual(Everything.test_ushort(GObject.G_MAXUSHORT),
                         GObject.G_MAXUSHORT)
        self.assertEqual(Everything.test_ushort(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_ushort, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_ushort,
                          GObject.G_MAXUSHORT + 1)
Example #36
0
    def test_long(self):
        self.assertEqual(Everything.test_long(GObject.G_MAXLONG),
                         GObject.G_MAXLONG)
        self.assertEqual(Everything.test_long(GObject.G_MINLONG),
                         GObject.G_MINLONG)
        self.assertRaises(tests.GIOverflowError, Everything.test_long,
                          GObject.G_MAXLONG + 1)

        self.assertEqual(Everything.test_ulong(GObject.G_MAXULONG),
                         GObject.G_MAXULONG)
        self.assertEqual(Everything.test_ulong(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_ulong, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_ulong,
                          GObject.G_MAXULONG + 1)
Example #37
0
    def test_size(self):
        self.assertEqual(Everything.test_ssize(GObject.G_MAXSSIZE),
                         GObject.G_MAXSSIZE)
        self.assertEqual(Everything.test_ssize(GObject.G_MINSSIZE),
                         GObject.G_MINSSIZE)
        self.assertRaises(tests.GIOverflowError, Everything.test_ssize,
                          GObject.G_MAXSSIZE + 1)

        self.assertEqual(Everything.test_size(GObject.G_MAXSIZE),
                         GObject.G_MAXSIZE)
        self.assertEqual(Everything.test_size(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_size, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_size,
                          GObject.G_MAXSIZE + 1)
Example #38
0
    def test_int8(self):
        self.assertEqual(Everything.test_int8(GObject.G_MAXINT8),
                         GObject.G_MAXINT8)
        self.assertEqual(Everything.test_int8(GObject.G_MININT8),
                         GObject.G_MININT8)
        self.assertRaises(tests.GIOverflowError, Everything.test_int8,
                          GObject.G_MAXINT8 + 1)

        self.assertEqual(Everything.test_uint8(GObject.G_MAXUINT8),
                         GObject.G_MAXUINT8)
        self.assertEqual(Everything.test_uint8(0), 0)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint8, -1)
        self.assertRaises(tests.GIOverflowError, Everything.test_uint8,
                          GObject.G_MAXUINT8 + 1)
Example #39
0
    def test_gslist(self):
        self.assertEqual(Everything.test_gslist_nothing_return(), ['1', '2', '3'])
        self.assertEqual(Everything.test_gslist_nothing_return2(), ['1', '2', '3'])
        self.assertEqual(Everything.test_gslist_container_return(), ['1', '2', '3'])
        self.assertEqual(Everything.test_gslist_everything_return(), ['1', '2', '3'])

        Everything.test_gslist_nothing_in(['1', '2', '3'])
        Everything.test_gslist_nothing_in2(['1', '2', '3'])
Example #40
0
    def test_basic(self):
        object_ = Everything.TestObj()

        self.assertEqual(object_.props.int, 0)
        object_.props.int = 42
        self.assertTrue(isinstance(object_.props.int, int))
        self.assertEqual(object_.props.int, 42)

        self.assertEqual(object_.props.float, 0.0)
        object_.props.float = 42.42
        self.assertTrue(isinstance(object_.props.float, float))
        self.assertAlmostEqual(object_.props.float, 42.42, places=5)

        self.assertEqual(object_.props.double, 0.0)
        object_.props.double = 42.42
        self.assertTrue(isinstance(object_.props.double, float))
        self.assertAlmostEqual(object_.props.double, 42.42, places=5)

        self.assertEqual(object_.props.string, None)
        object_.props.string = 'mec'
        self.assertTrue(isinstance(object_.props.string, str))
        self.assertEqual(object_.props.string, 'mec')

        self.assertEqual(object_.props.gtype, GObject.TYPE_INVALID)
        object_.props.gtype = int
        self.assertEqual(object_.props.gtype, GObject.TYPE_INT)
Example #41
0
    def test_hash_table(self):
        object_ = Everything.TestObj()
        self.assertEquals(object_.props.hash_table, None)

        object_.props.hash_table = {'mec': 56}
        self.assertTrue(isinstance(object_.props.hash_table, dict))
        self.assertEquals(list(object_.props.hash_table.items())[0], ('mec', 56))
Example #42
0
    def test_list(self):
        object_ = Everything.TestObj()
        self.assertEquals(object_.props.list, [])

        object_.props.list = ['1', '2', '3']
        self.assertTrue(isinstance(object_.props.list, list))
        self.assertEquals(object_.props.list, ['1', '2', '3'])
Example #43
0
    def testCallbackUserdataRefCount(self):
        TestCallbacks.called = False
        def callback(userdata):
            TestCallbacks.called = True
            return 1

        ud = "Test User Data"

        start_ref_count = getrefcount(ud)
        for i in range(100):
            Everything.test_callback_destroy_notify(callback, ud)
            
        Everything.test_callback_thaw_notifications()
        end_ref_count = getrefcount(ud)

        self.assertEquals(start_ref_count, end_ref_count)
Example #44
0
    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)
Example #45
0
    def test_gtype(self):
        s = Regress.TestStructE()

        s.some_type = Regress.TestObj
        self.assertEqual(s.some_type, Regress.TestObj.__gtype__)

        self.assertRaises(TypeError, setattr, s, "some_type", 42)
Example #46
0
 def test_obj_skip_return_val(self):
     obj = Everything.TestObj()
     ret = obj.skip_return_val(50, 42.0, 60, 2, 3)
     self.assertEqual(len(ret), 3)
     self.assertEqual(ret[0], 51)
     self.assertEqual(ret[1], 61)
     self.assertEqual(ret[2], 32)
Example #47
0
    def test_obj_skip_return_val_no_out(self):
        obj = Everything.TestObj()
        # raises an error for 0, succeeds for any other value
        self.assertRaises(GLib.GError, obj.skip_return_val_no_out, 0)

        ret = obj.skip_return_val_no_out(1)
        self.assertEqual(ret, None)
Example #48
0
    def test_annotated_glist(self):
        obj = Regress.TestObj()
        self.assertEqual(self.get_prop(obj, 'list'), [])

        self.set_prop(obj, 'list', ['1', '2', '3'])
        self.assertTrue(isinstance(self.get_prop(obj, 'list'), list))
        self.assertEqual(self.get_prop(obj, 'list'), ['1', '2', '3'])
Example #49
0
 def test_boxed_c_equality(self):
     boxed = Everything.TestBoxedC()
     # TestBoxedC uses refcounting, so we know that
     # the pointer is the same when copied
     copy = boxed.copy()
     self.assertEqual(boxed, copy)
     self.assertNotEqual(id(boxed), id(copy))
Example #50
0
 def test_hash_in_with_gvalue_strv(self):
     data = {
         'integer':
         12,
         'boolean':
         True,
         'string':
         'some text',
         'strings':
         GObject.Value(GObject.TYPE_STRV, ['first', 'second', 'third']),
         'flags':
         Everything.TestFlags.FLAG1 | Everything.TestFlags.FLAG3,
         'enum':
         Everything.TestEnum.VALUE2,
     }
     Everything.test_ghash_gvalue_in(data)
     data = None
Example #51
0
    def test_boxed_b_constructor(self):
        with warnings.catch_warnings(record=True) as warn:
            warnings.simplefilter('always')
            boxed = Everything.TestBoxedB(42, 47)
            self.assertTrue(issubclass(warn[0].category, TypeError))

        self.assertEqual(boxed.some_int8, 0)
        self.assertEqual(boxed.some_long, 0)
Example #52
0
    def test_hash_table(self):
        obj = Regress.TestObj()
        self.assertEqual(self.get_prop(obj, 'hash-table'), None)

        self.set_prop(obj, 'hash-table', {'mec': 56})
        self.assertTrue(isinstance(self.get_prop(obj, 'hash-table'), dict))
        self.assertEqual(list(self.get_prop(obj, 'hash-table').items())[0],
                         ('mec', 56))
Example #53
0
    def testReturnValueCallback(self):
        TestCallbacks.called = False
        def callback():
            TestCallbacks.called = True
            return 44

        self.assertEquals(Everything.test_callback(callback), 44)
        self.assertTrue(TestCallbacks.called)
Example #54
0
    def test_hash_in(self):
        # specifying a simple string array for "strings" does not work due to
        # https://bugzilla.gnome.org/show_bug.cgi?id=666636
        # workaround by explicitly building a GStrv object
        class GStrv(list):
            __gtype__ = GObject.TYPE_STRV

        data = {
            'integer': 12,
            'boolean': True,
            'string': 'some text',
            'strings': GStrv(['first', 'second', 'third']),
            'flags': Everything.TestFlags.FLAG1 | Everything.TestFlags.FLAG3,
            'enum': Everything.TestEnum.VALUE2,
        }
        Everything.test_ghash_gvalue_in(data)
        data = None
Example #55
0
    def testDoubleCallbackException(self):
        """
        This test ensures that we get errors from callbacks correctly
        and in particular that we do not segv when callbacks fail
        """
        def badcallback():
            x = 1 / 0

        def callback():
            Everything.test_boolean(True)
            Everything.test_boolean(False)
            Everything.test_simple_callback(badcallback())

        try:
            Everything.test_simple_callback(callback)
        except ZeroDivisionError:
            pass
Example #56
0
    def test_floating(self):
        e = Everything.TestFloating()
        self.assertEqual(e.__grefcount__, 1)

        e = GObject.new(Everything.TestFloating)
        self.assertEqual(e.__grefcount__, 1)

        e = Everything.TestFloating.new()
        self.assertEqual(e.__grefcount__, 1)
Example #57
0
    def test_int_arg(self):
        def callback(num):
            self.called = True
            return num + 1

        self.called = False
        result = Everything.test_closure_one_arg(callback, 42)
        self.assertTrue(self.called)
        self.assertEqual(result, 43)
Example #58
0
    def test_no_arg(self):
        def callback():
            self.called = True
            return 42

        self.called = False
        result = Everything.test_closure(callback)
        self.assertTrue(self.called)
        self.assertEqual(result, 42)
Example #59
0
    def test_double_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 badcallback():
            x = 1 / 0
            self.fail('unexpected surviving zero divsion:' + str(x))

        def callback():
            Everything.test_boolean(True)
            Everything.test_boolean(False)
            Everything.test_simple_callback(badcallback())

        # 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)
        Everything.test_simple_callback(callback)
Example #60
0
    def test_object_param_signal(self):
        obj = Everything.TestObj()

        def callback(obj, obj_param):
            self.assertEqual(obj_param.props.int, 3)
            self.assertGreater(obj_param.__grefcount__, 1)

        obj.connect('sig-with-obj', callback)
        obj.emit_sig_with_obj()