Exemple #1
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)
    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)