Example #1
0
    def test_boxed_struct_in(self):
        struct = GIMarshallingTests.BoxedStruct()
        struct.long_ = 42

        GIMarshallingTests.boxed_struct_in(struct)

        del struct
Example #2
0
    def test_object_none_out(self):
        object_ = GIMarshallingTests.object_none_out()
        self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
        self.assertEquals(object_.__grefcount__, 2)

        new_object = GIMarshallingTests.object_none_out()
        self.assertTrue(new_object is object_)
Example #3
0
    def test_pointer_struct_in(self):
        struct = GIMarshallingTests.PointerStruct()
        struct.long_ = 42

        GIMarshallingTests.pointer_struct_in(struct)

        del struct
Example #4
0
    def test_array_fixed_int_in(self):
        GIMarshallingTests.array_fixed_int_in(Sequence((-1, 0, 1, 2)))

        self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, Sequence((-1, "0", 1, 2)))

        self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, 42)
        self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, None)
Example #5
0
    def test_gslist_int_none_in(self):
        GIMarshallingTests.gslist_int_none_in(Sequence((-1, 0, 1, 2)))

        self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, Sequence((-1, "0", 1, 2)))

        self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, 42)
        self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, None)
Example #6
0
    def test_ghashtable_int_none_in(self):
        GIMarshallingTests.ghashtable_int_none_in({-1: 1, 0: 0, 1: -1, 2: -2})

        self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, {-1: 1, "0": 0, 1: -1, 2: -2})
        self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, {-1: 1, 0: "0", 1: -1, 2: -2})

        self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, "{-1: 1, 0: 0, 1: -1, 2: -2}")
        self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, None)
Example #7
0
    def test_exception(self):
        with self.assertRaises(GLib.Error) as context:
            GIMarshallingTests.gerror()

        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)
Example #8
0
    def test_exception(self):
        with self.assertRaises(GLib.Error) as context:
            GIMarshallingTests.gerror()

        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)
Example #9
0
    def test_size_in(self):
        number = Number(self.MAX)

        GIMarshallingTests.size_in(number)

        number.value += 1

        self.assertRaises(ValueError, GIMarshallingTests.size_in, number)
        self.assertRaises(ValueError, GIMarshallingTests.size_in, Number(-1))

        self.assertRaises(TypeError, GIMarshallingTests.size_in, "self.MAX")
Example #10
0
    def test_object_none_in(self):
        object_ = GIMarshallingTests.Object(int=42)
        GIMarshallingTests.object_none_in(object_)
        self.assertEquals(object_.__grefcount__, 1)

        object_ = GIMarshallingTests.SubObject(int=42)
        GIMarshallingTests.object_none_in(object_)

        object_ = gobject.GObject()
        self.assertRaises(TypeError, GIMarshallingTests.object_none_in, object_)

        self.assertRaises(TypeError, GIMarshallingTests.object_none_in, None)
Example #11
0
    def test_struct(self):
        s = GIMarshallingTests.NestedStruct()

        # FIXME: segfaults
        # https://bugzilla.gnome.org/show_bug.cgi?id=747002
        # s.simple_struct = None

        self.assertRaises(TypeError, setattr, s, "simple_struct", object())

        sub = GIMarshallingTests.SimpleStruct()
        sub.long_ = 42
        s.simple_struct = sub
        self.assertEqual(s.simple_struct.long_, 42)
Example #12
0
    def test_gi(self):
        res = GIMarshallingTests.init_function([])
        self.assertEqual(repr(res), "(True, argv=[])")

        res = GIMarshallingTests.array_return_etc(5, 9)
        self.assertEqual(repr(res), "([5, 0, 1, 9], sum=14)")

        res = GIMarshallingTests.array_out_etc(-5, 9)
        self.assertEqual(repr(res), "(ints=[-5, 0, 1, 9], sum=4)")

        cb = lambda: (1, 2)
        res = GIMarshallingTests.callback_multiple_out_parameters(cb)
        self.assertEqual(repr(res), "(a=1.0, b=2.0)")
Example #13
0
    def test_gi(self):
        res = GIMarshallingTests.init_function([])
        self.assertEqual(repr(res), "(True, argv=[])")

        res = GIMarshallingTests.array_return_etc(5, 9)
        self.assertEqual(repr(res), "([5, 0, 1, 9], sum=14)")

        res = GIMarshallingTests.array_out_etc(-5, 9)
        self.assertEqual(repr(res), "(ints=[-5, 0, 1, 9], sum=4)")

        cb = lambda: (1, 2)
        res = GIMarshallingTests.callback_multiple_out_parameters(cb)
        self.assertEqual(repr(res), "(a=1.0, b=2.0)")
Example #14
0
    def test_arg_exceptions(self):
        try:
            GIMarshallingTests.int8_in_max("fdsaf")
        except TypeError as e:
            self.assertTrue("1" in str(e))
            self.assertTrue("'v'" in str(e))
            self.assertTrue("int8_in_max" in str(e))

        try:
            GIMarshallingTests.int8_in_max(10000)
        except OverflowError as e:
            self.assertTrue("1" in str(e))
            self.assertTrue("'v'" in str(e))
            self.assertTrue("int8_in_max" in str(e))
Example #15
0
    def test_int8_in(self):
        max = Number(self.MAX)
        min = Number(self.MIN)

        GIMarshallingTests.int8_in_max(max)
        GIMarshallingTests.int8_in_min(min)

        max.value += 1
        min.value -= 1

        self.assertRaises(ValueError, GIMarshallingTests.int8_in_max, max)
        self.assertRaises(ValueError, GIMarshallingTests.int8_in_min, min)

        self.assertRaises(TypeError, GIMarshallingTests.int8_in_max, "self.MAX")
Example #16
0
    def test_arg_exceptions(self):
        try:
            GIMarshallingTests.int8_in_max("fdsaf")
        except TypeError as e:
            self.assertTrue("1" in str(e))
            self.assertTrue("'v'" in str(e))
            self.assertTrue("int8_in_max" in str(e))

        try:
            GIMarshallingTests.int8_in_max(10000)
        except OverflowError as e:
            self.assertTrue("1" in str(e))
            self.assertTrue("'v'" in str(e))
            self.assertTrue("int8_in_max" in str(e))
Example #17
0
    def test_float(self):
        self.assertEqual(self.get_prop(self.obj, 'some-float'), 0)
        self.set_prop(self.obj, 'some-float', GLib.MAXFLOAT)
        self.assertEqual(self.get_prop(self.obj, 'some-float'), GLib.MAXFLOAT)

        obj = GIMarshallingTests.PropertiesObject(some_float=42.42)
        self.assertAlmostEqual(self.get_prop(obj, 'some-float'), 42.42, places=4)

        obj = GIMarshallingTests.PropertiesObject(some_float=42)
        self.assertAlmostEqual(self.get_prop(obj, 'some-float'), 42.0, places=4)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-float', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-float', None)

        self.assertAlmostEqual(self.get_prop(obj, 'some-float'), 42.0, places=4)
Example #18
0
    def test_object_none_inout(self):
        object_ = GIMarshallingTests.Object(int=42)
        new_object = GIMarshallingTests.object_none_inout(object_)

        self.assertTrue(isinstance(new_object, GIMarshallingTests.Object))

        self.assertFalse(object_ is new_object)

        self.assertEquals(object_.__grefcount__, 1)
        self.assertEquals(new_object.__grefcount__, 2)

        new_new_object = GIMarshallingTests.object_none_inout(object_)
        self.assertTrue(new_new_object is new_object)

        GIMarshallingTests.object_none_inout(GIMarshallingTests.SubObject(int=42))
Example #19
0
    def test_double(self):
        self.assertEqual(self.get_prop(self.obj, 'some-double'), 0)
        self.set_prop(self.obj, 'some-double', GLib.MAXDOUBLE)
        self.assertEqual(self.get_prop(self.obj, 'some-double'), GLib.MAXDOUBLE)

        obj = GIMarshallingTests.PropertiesObject(some_double=42.42)
        self.assertAlmostEqual(self.get_prop(obj, 'some-double'), 42.42)

        obj = GIMarshallingTests.PropertiesObject(some_double=42)
        self.assertAlmostEqual(self.get_prop(obj, 'some-double'), 42.0)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-double', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-double', None)

        self.assertAlmostEqual(self.get_prop(obj, 'some-double'), 42.0)
Example #20
0
    def test_corner_cases(self):
        self.assertRaises(
            TypeError, GIMarshallingTests.glist_int_none_in, [object()])

        self.assertRaises(tests.GIOverflowError,
            GIMarshallingTests.glist_int_none_in, [GObject.G_MAXUINT64])

        class SomeInt(object):
            def __init__(self, val):
                self.val = val

            def __int__(self):
                return self.val

        GIMarshallingTests.glist_int_none_in([SomeInt(-1), 0, 1, 2])
Example #21
0
    def test_pointer_struct_out(self):
        struct = GIMarshallingTests.pointer_struct_out()

        self.assertTrue(isinstance(struct, GIMarshallingTests.PointerStruct))
        self.assertEquals(42, struct.long_)

        del struct
Example #22
0
    def test_array_fixed_out_struct(self):
        struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()

        self.assertEquals(7, struct1.long_)
        self.assertEquals(6, struct1.int8)
        self.assertEquals(6, struct2.long_)
        self.assertEquals(7, struct2.int8)
Example #23
0
    def test_simple_struct_in(self):
        struct = GIMarshallingTests.SimpleStruct()
        struct.long_ = 6
        struct.int8 = 7

        GIMarshallingTests.simple_struct_in(struct)

        del struct

        struct = GIMarshallingTests.NestedStruct()

        self.assertRaises(TypeError, GIMarshallingTests.simple_struct_in, struct)

        del struct

        self.assertRaises(TypeError, GIMarshallingTests.simple_struct_in, None)
Example #24
0
    def test_container_sub_exceptions(self):
        class Foo(list):
            def __len__(self):
                return 2**33

        try:
            GIMarshallingTests.array_in(Foo([1, 2, 3, 4]))
        except OverflowError as e:
            self.assertTrue("not in range" in str(e))
            self.assertTrue("array_in" in str(e))

        try:
            GIMarshallingTests.array_in(["foo"])
        except TypeError as e:
            self.assertTrue("not a number" in str(e))
            self.assertTrue("array_in" in str(e))
Example #25
0
    def test_boolean(self):
        self.assertEqual(self.get_prop(self.obj, 'some-boolean'), False)
        self.set_prop(self.obj, 'some-boolean', True)
        self.assertEqual(self.get_prop(self.obj, 'some-boolean'), True)

        obj = GIMarshallingTests.PropertiesObject(some_boolean=True)
        self.assertEqual(self.get_prop(obj, 'some-boolean'), True)
Example #26
0
    def test_boxed_struct_out(self):
        struct = GIMarshallingTests.boxed_struct_out()

        self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
        self.assertEquals(42, struct.long_)

        del struct
Example #27
0
    def test_uchar(self):
        self.assertEqual(self.get_prop(self.obj, 'some-uchar'), 0)
        self.set_prop(self.obj, 'some-uchar', GLib.MAXUINT8)
        self.assertEqual(self.get_prop(self.obj, 'some-uchar'), GLib.MAXUINT8)

        obj = GIMarshallingTests.PropertiesObject(some_uchar=42)
        self.assertEqual(self.get_prop(obj, 'some-uchar'), 42)
Example #28
0
    def test_container_sub_exceptions(self):
        class Foo(list):
            def __len__(self):
                return 2**33

        try:
            GIMarshallingTests.array_in(Foo([1,2,3,4]))
        except OverflowError as e:
            self.assertTrue("not in range" in str(e))
            self.assertTrue("array_in" in str(e))

        try:
            GIMarshallingTests.array_in(["foo"])
        except TypeError as e:
            self.assertTrue("not a number" in str(e))
            self.assertTrue("array_in" in str(e))
Example #29
0
    def test_uint64(self):
        self.assertEqual(self.get_prop(self.obj, 'some-uint64'), 0)
        self.set_prop(self.obj, 'some-uint64', GLib.MAXUINT64)
        self.assertEqual(self.get_prop(self.obj, 'some-uint64'), GLib.MAXUINT64)

        obj = GIMarshallingTests.PropertiesObject(some_uint64=4200000000000000)
        self.assertEqual(self.get_prop(obj, 'some-uint64'), 4200000000000000)
Example #30
0
    def test_corner_cases(self):
        self.assertRaises(TypeError, GIMarshallingTests.glist_int_none_in,
                          [object()])

        self.assertRaises(tests.GIOverflowError,
                          GIMarshallingTests.glist_int_none_in,
                          [GObject.G_MAXUINT64])

        class SomeInt(object):
            def __init__(self, val):
                self.val = val

            def __int__(self):
                return self.val

        GIMarshallingTests.glist_int_none_in([SomeInt(-1), 0, 1, 2])
Example #31
0
    def test_coerce_from_instance(self):
        obj = GIMarshallingTests.PropertiesObject()
        prop = GObject.ObjectClass.find_property(obj, 'some-int')

        self.assertIsInstance(prop, GObject.GParamSpec)
        self.assertEqual(prop.name, 'some-int')
        self.assertEqual(prop.value_type, GObject.TYPE_INT)
        self.assertEqual(prop.owner_type, obj.__gtype__)
Example #32
0
    def test_simple_struct_out(self):
        struct = GIMarshallingTests.simple_struct_out()

        self.assertTrue(isinstance(struct, GIMarshallingTests.SimpleStruct))
        self.assertEquals(6, struct.long_)
        self.assertEquals(7, struct.int8)

        del struct
Example #33
0
    def test_return(self):
        # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
        error = GIMarshallingTests.gerror_return()

        self.assertIsInstance(error, GLib.Error)
        self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
        self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
        self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
Example #34
0
    def test_return(self):
        # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
        error = GIMarshallingTests.gerror_return()

        self.assertIsInstance(error, GLib.Error)
        self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
        self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
        self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
Example #35
0
    def test_boxed_struct(self):
        self.assertEqual(self.get_prop(self.obj, 'some-boxed-struct'), None)

        class GStrv(list):
            __gtype__ = GObject.TYPE_STRV

        struct1 = GIMarshallingTests.BoxedStruct()
        struct1.long_ = 1

        self.set_prop(self.obj, 'some-boxed-struct', struct1)
        self.assertEqual(self.get_prop(self.obj, 'some-boxed-struct').long_, 1)
        self.assertEqual(self.obj.some_boxed_struct.long_, 1)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-boxed-struct', 1)
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-boxed-struct', 'foo')

        obj = GIMarshallingTests.PropertiesObject(some_boxed_struct=struct1)
        self.assertEqual(self.get_prop(obj, 'some-boxed-struct').long_, 1)
Example #36
0
    def test_out_transfer_none(self):
        # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
        error, debug = GIMarshallingTests.gerror_out_transfer_none()

        self.assertIsInstance(error, GLib.Error)
        self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
        self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
        self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
        self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug)
Example #37
0
    def test_out_transfer_none(self):
        # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
        error, debug = GIMarshallingTests.gerror_out_transfer_none()

        self.assertIsInstance(error, GLib.Error)
        self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
        self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
        self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
        self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug)
Example #38
0
    def test_boxed_struct_inout(self):
        in_struct = GIMarshallingTests.BoxedStruct()
        in_struct.long_ = 42

        out_struct = GIMarshallingTests.boxed_struct_inout(in_struct)

        self.assertTrue(isinstance(out_struct, GIMarshallingTests.BoxedStruct))
        self.assertEquals(0, out_struct.long_)

        del in_struct
        del out_struct
Example #39
0
    def test_strv(self):
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), [])
        self.set_prop(self.obj, 'some-strv', ['hello', 'world'])
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 1)
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', [1, 2])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', ['foo', 1])

        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        obj = GIMarshallingTests.PropertiesObject(some_strv=['hello', 'world'])
        self.assertEqual(self.get_prop(obj, 'some-strv'), ['hello', 'world'])

        # unicode on py2
        obj = GIMarshallingTests.PropertiesObject(some_strv=[_unicode('foo')])
        self.assertEqual(self.get_prop(obj, 'some-strv'), [_unicode('foo')])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv',
                          [_unicode('foo'), 1])
Example #40
0
    def test_int(self):
        self.assertEqual(self.get_prop(self.obj, 'some_int'), 0)
        self.set_prop(self.obj, 'some-int', GLib.MAXINT)
        self.assertEqual(self.get_prop(self.obj, 'some_int'), GLib.MAXINT)

        obj = GIMarshallingTests.PropertiesObject(some_int=-42)
        self.assertEqual(self.get_prop(obj, 'some-int'), -42)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-int', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-int', None)

        self.assertEqual(self.get_prop(obj, 'some-int'), -42)
Example #41
0
    def test_utf8(self):
        s = GIMarshallingTests.BoxedStruct()
        s.string_ = "hello"
        self.assertEqual(s.string_, "hello")

        s.string_ = u"hello"
        self.assertEqual(s.string_, u"hello")

        s.string_ = None
        self.assertEqual(s.string_, None)

        self.assertRaises(TypeError, setattr, s, "string_", 42)
Example #42
0
    def test_ulong(self):
        self.assertEqual(self.get_prop(self.obj, 'some_ulong'), 0)
        self.set_prop(self.obj, 'some-ulong', GLib.MAXULONG)
        self.assertEqual(self.get_prop(self.obj, 'some_ulong'), GLib.MAXULONG)

        obj = GIMarshallingTests.PropertiesObject(some_ulong=42)
        self.assertEqual(self.get_prop(obj, 'some-ulong'), 42)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-ulong', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-ulong', None)

        self.assertEqual(self.get_prop(obj, 'some-ulong'), 42)
Example #43
0
    def test_props_accessor_dir(self):
        # Test class
        props = dir(GIMarshallingTests.PropertiesObject.props)
        self.assertTrue('some_float' in props)
        self.assertTrue('some_double' in props)
        self.assertTrue('some_variant' in props)

        # Test instance
        obj = GIMarshallingTests.PropertiesObject()
        props = dir(obj.props)
        self.assertTrue('some_float' in props)
        self.assertTrue('some_double' in props)
        self.assertTrue('some_variant' in props)
Example #44
0
    def test_simple_struct_inout(self):
        in_struct = GIMarshallingTests.SimpleStruct()
        in_struct.long_ = 6
        in_struct.int8 = 7

        out_struct = GIMarshallingTests.simple_struct_inout(in_struct)

        self.assertTrue(isinstance(out_struct, GIMarshallingTests.SimpleStruct))
        self.assertEquals(7, out_struct.long_)
        self.assertEquals(6, out_struct.int8)

        del in_struct
        del out_struct
Example #45
0
    def test_held_object_ref_count_getter(self):
        holder = GIMarshallingTests.PropertiesObject()
        held = GObject.Object()

        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 1)

        self.set_prop(holder, 'some-object', held)
        self.assertEqual(holder.__grefcount__, 1)

        initial_ref_count = held.__grefcount__
        self.get_prop(holder, 'some-object')
        gc.collect()
        self.assertEqual(held.__grefcount__, initial_ref_count)
Example #46
0
    def test_props_getter_holding_object_ref_count(self):
        holder = GIMarshallingTests.PropertiesObject()
        held = GObject.Object()

        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 1)

        holder.set_property('some-object', held)
        self.assertEqual(holder.__grefcount__, 1)

        initial_ref_count = held.__grefcount__
        holder.props.some_object
        gc.collect()
        self.assertEqual(held.__grefcount__, initial_ref_count)
Example #47
0
    def test_held_object_ref_count_setter(self):
        holder = GIMarshallingTests.PropertiesObject()
        held = GObject.Object()

        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 1)

        # Setting property should only increase ref count by 1
        self.set_prop(holder, 'some-object', held)
        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 2)

        # Clearing should pull it back down
        self.set_prop(holder, 'some-object', None)
        self.assertEqual(held.__grefcount__, 1)
Example #48
0
    def test_props_setter_holding_object_ref_count(self):
        holder = GIMarshallingTests.PropertiesObject()
        held = GObject.Object()

        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 1)

        # Setting property should only increase ref count by 1
        holder.props.some_object = held
        self.assertEqual(holder.__grefcount__, 1)
        self.assertEqual(held.__grefcount__, 2)

        # Clearing should pull it back down
        holder.props.some_object = None
        self.assertEqual(held.__grefcount__, 1)
Example #49
0
    def test_long(self):
        s = GIMarshallingTests.SimpleStruct()
        s.long_ = GLib.MAXLONG
        self.assertEqual(s.long_, GLib.MAXLONG)

        self.assertRaises(TypeError, setattr, s, "long_", b"a")
        self.assertRaises(TypeError, setattr, s, "long_", None)
        self.assertRaises(OverflowError, setattr, s, "long_", GLib.MAXLONG + 1)
        self.assertRaises(OverflowError, setattr, s, "long_", GLib.MINLONG - 1)

        s.long_ = 3.6
        self.assertEqual(s.long_, 3)

        s.long_ = Number(GLib.MINLONG)
        self.assertEqual(s.long_, GLib.MINLONG)
Example #50
0
    def test_struct(self):
        # Test that the constructor has been overridden.
        struct = GIMarshallingTests.OverridesStruct(42)

        self.assertTrue(isinstance(struct, GIMarshallingTests.OverridesStruct))

        # Test that the method has been overridden.
        self.assertEquals(6, struct.method())

        del struct

        # Test that the overrides wrapper has been registered.
        struct = GIMarshallingTests.overrides_struct_return()

        self.assertTrue(isinstance(struct, GIMarshallingTests.OverridesStruct))

        del struct
Example #51
0
    def test_object(self):
        # Test that the constructor has been overridden.
        object_ = GIMarshallingTests.OverridesObject(42)

        self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))

        # Test that the alternate constructor has been overridden.
        object_ = GIMarshallingTests.OverridesObject.new(42)

        self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))

        # Test that the method has been overridden.
        self.assertEquals(6, object_.method())

        # Test that the overrides wrapper has been registered.
        object_ = GIMarshallingTests.overrides_object_return()

        self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
Example #52
0
    def test_variant(self):
        self.assertEqual(self.get_prop(self.obj, 'some-variant'), None)

        self.set_prop(self.obj, 'some-variant', GLib.Variant('o', '/myobj'))
        self.assertEqual(self.get_prop(self.obj, 'some-variant').get_type_string(), 'o')
        self.assertEqual(self.get_prop(self.obj, 'some-variant').print_(False), "'/myobj'")

        self.set_prop(self.obj, 'some-variant', None)
        self.assertEqual(self.get_prop(self.obj, 'some-variant'), None)

        obj = GIMarshallingTests.PropertiesObject(some_variant=GLib.Variant('b', True))
        self.assertEqual(self.get_prop(obj, 'some-variant').get_type_string(), 'b')
        self.assertEqual(self.get_prop(obj, 'some-variant').get_boolean(), True)

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-variant', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-variant', 23)

        self.assertEqual(self.get_prop(obj, 'some-variant').get_type_string(), 'b')
        self.assertEqual(self.get_prop(obj, 'some-variant').get_boolean(), True)
def test_value_object():
    v = GObject.Value(GIMarshallingTests.Object)
    assert v.g_type.is_a(GObject.TYPE_OBJECT)

    for getter, setter in [(v.get_value, v.set_value),
                           (v.get_object, v.set_object)]:
        assert getter() is None

        setter(None)
        assert getter() is None

        obj = GIMarshallingTests.Object()
        setter(obj)
        assert getter() is obj

        with pytest.raises(TypeError):
            setter(object())

        v.reset()
Example #54
0
    def tests_compare_two_gerrors_in_gvalue(self):
        error = GLib.Error.new_literal(1, "error", 1)
        error1 = GLib.Error.new_literal(1, "error", 1)

        GIMarshallingTests.compare_two_gerrors_in_gvalue(error, error1)
Example #55
0
 def test_flags_inout(self):
     flags = GIMarshallingTests.flags_inout(GIMarshallingTests.Flags.VALUE2)
     self.assertTrue(isinstance(flags, GIMarshallingTests.Flags))
     self.assertEquals(flags, GIMarshallingTests.Flags.VALUE1)
Example #56
0
 def test_enum_inout(self):
     enum = GIMarshallingTests.enum_inout(GIMarshallingTests.Enum.VALUE3)
     self.assertTrue(isinstance(enum, GIMarshallingTests.Enum))
     self.assertEquals(enum, GIMarshallingTests.Enum.VALUE1)
Example #57
0
    def test_flags_in(self):
        GIMarshallingTests.flags_in(GIMarshallingTests.Flags.VALUE2)
        GIMarshallingTests.flags_in_zero(Number(0))

        self.assertRaises(TypeError, GIMarshallingTests.flags_in, 1 << 1)
        self.assertRaises(TypeError, GIMarshallingTests.flags_in, "GIMarshallingTests.Flags.VALUE2")
Example #58
0
 def test_error_message(self):
     try:
         GIMarshallingTests.gerror()
     except GLib.GError as e:
         self.assertTrue("gi-marshalling-tests-gerror-message" in str(e))
Example #59
0
 def test_set_object_property_to_invalid_type(self):
     obj = GIMarshallingTests.PropertiesObject()
     self.assertRaises(TypeError, self.set_prop, obj, 'some-object', 'not_an_object')
Example #60
0
 def setUp(self):
     self.obj = GIMarshallingTests.PropertiesObject()