def test_gtype(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.gtype, TYPE_NONE)
        self.assertEqual(obj.gtype, TYPE_NONE)

        obj.gtype = TYPE_UINT64
        self.assertEqual(obj.props.gtype, TYPE_UINT64)
        self.assertEqual(obj.gtype, TYPE_UINT64)

        obj.gtype = TYPE_INVALID
        self.assertEqual(obj.props.gtype, TYPE_INVALID)
        self.assertEqual(obj.gtype, TYPE_INVALID)

        # GType parameters do not support defaults in GLib
        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                          default=TYPE_INT)

        # incompatible type
        self.assertRaises(TypeError, setattr, obj, 'gtype', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'gtype', object())

        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                          default='foo')
        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                          default=object())

        # set in constructor
        obj = new(PropertyObject, gtype=TYPE_UINT)
        self.assertEqual(obj.props.gtype, TYPE_UINT)
        self.assertEqual(obj.gtype, TYPE_UINT)
    def test_variant(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.variant, None)
        self.assertEqual(obj.variant, None)

        obj.variant = GLib.Variant('s', 'hello')
        self.assertEqual(obj.variant.print_(True), "'hello'")

        obj.variant = GLib.Variant('b', True)
        self.assertEqual(obj.variant.print_(True), "true")

        obj.props.variant = GLib.Variant('y', 2)
        self.assertEqual(obj.variant.print_(True), "byte 0x02")

        obj.variant = None
        self.assertEqual(obj.variant, None)

        # set in constructor
        obj = new(PropertyObject, variant=GLib.Variant('u', 5))
        self.assertEqual(obj.props.variant.print_(True), 'uint32 5')

        GObject.Property(type=TYPE_VARIANT, default=GLib.Variant('i', 1))

        # incompatible types
        self.assertRaises(TypeError, setattr, obj, 'variant', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'variant', 42)

        self.assertRaises(TypeError, GObject.Property, type=TYPE_VARIANT,
                          default='foo')
        self.assertRaises(TypeError, GObject.Property, type=TYPE_VARIANT,
                          default=object())
Exemple #3
0
    def testGType(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.gtype, TYPE_NONE)
        self.assertEqual(obj.gtype, TYPE_NONE)

        obj.gtype = TYPE_UINT64
        self.assertEqual(obj.props.gtype, TYPE_UINT64)
        self.assertEqual(obj.gtype, TYPE_UINT64)

        obj.gtype = TYPE_INVALID
        self.assertEqual(obj.props.gtype, TYPE_INVALID)
        self.assertEqual(obj.gtype, TYPE_INVALID)

        # GType parameters do not support defaults in GLib
        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                default=TYPE_INT)

        # incompatible type
        self.assertRaises(TypeError, setattr, obj, 'gtype', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'gtype', object())

        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                default='foo')
        self.assertRaises(TypeError, GObject.Property, type=TYPE_GTYPE,
                default=object())

        # set in constructor
        obj = new(PropertyObject, gtype=TYPE_UINT)
        self.assertEqual(obj.props.gtype, TYPE_UINT)
        self.assertEqual(obj.gtype, TYPE_UINT)
    def test_variant(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.variant, None)
        self.assertEqual(obj.variant, None)

        obj.variant = GLib.Variant('s', 'hello')
        self.assertEqual(obj.variant.print_(True), "'hello'")

        obj.variant = GLib.Variant('b', True)
        self.assertEqual(obj.variant.print_(True), "true")

        obj.props.variant = GLib.Variant('y', 2)
        self.assertEqual(obj.variant.print_(True), "byte 0x02")

        obj.variant = None
        self.assertEqual(obj.variant, None)

        # set in constructor
        obj = new(PropertyObject, variant=GLib.Variant('u', 5))
        self.assertEqual(obj.props.variant.print_(True), 'uint32 5')

        GObject.Property(type=TYPE_VARIANT, default=GLib.Variant('i', 1))

        # incompatible types
        self.assertRaises(TypeError, setattr, obj, 'variant', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'variant', 42)

        self.assertRaises(TypeError, GObject.Property, type=TYPE_VARIANT,
                          default='foo')
        self.assertRaises(TypeError, GObject.Property, type=TYPE_VARIANT,
                          default=object())
Exemple #5
0
    def test_strings(self):
        obj = new(PropertyObject)

        # Should work with actual GStrv objects as well as
        # Python string lists
        class GStrv(list):
            __gtype__ = GObject.TYPE_STRV

        self.assertEqual(obj.props.strings, GStrv([]))
        self.assertEqual(obj.strings, GStrv([]))
        self.assertEqual(obj.props.strings, [])
        self.assertEqual(obj.strings, [])

        obj.strings = ['hello', 'world']
        self.assertEqual(obj.props.strings, ['hello', 'world'])
        self.assertEqual(obj.strings, ['hello', 'world'])

        obj.strings = GStrv(['hello', 'world'])
        self.assertEqual(obj.props.strings, GStrv(['hello', 'world']))
        self.assertEqual(obj.strings, GStrv(['hello', 'world']))

        obj.strings = []
        self.assertEqual(obj.strings, [])
        obj.strings = GStrv([])
        self.assertEqual(obj.strings, GStrv([]))

        p = GObject.Property(type=TYPE_STRV, default=['hello', '1'])
        self.assertEqual(p.default, ['hello', '1'])
        self.assertEqual(p.type, TYPE_STRV)
        p = GObject.Property(type=TYPE_STRV, default=GStrv(['hello', '1']))
        self.assertEqual(p.default, ['hello', '1'])
        self.assertEqual(p.type, TYPE_STRV)

        # set in constructor
        obj = new(PropertyObject, strings=['hello', 'world'])
        self.assertEqual(obj.props.strings, ['hello', 'world'])
        self.assertEqual(obj.strings, ['hello', 'world'])

        # wrong types
        self.assertRaises(TypeError, setattr, obj, 'strings', 1)
        self.assertRaises(TypeError, setattr, obj, 'strings', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'strings', ['foo', 1])

        self.assertRaises(TypeError,
                          GObject.Property,
                          type=TYPE_STRV,
                          default=1)
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=TYPE_STRV,
                          default='foo')
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=TYPE_STRV,
                          default=['hello', 1])
Exemple #6
0
    def test_variant_default(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.variant_def.print_(True), '42')
        self.assertEqual(obj.variant_def.print_(True), '42')

        obj.props.variant_def = GLib.Variant('y', 2)
        self.assertEqual(obj.variant_def.print_(True), "byte 0x02")

        # set in constructor
        obj = new(PropertyObject, variant_def=GLib.Variant('u', 5))
        self.assertEqual(obj.props.variant_def.print_(True), 'uint32 5')
    def test_variant_default(self):
        obj = new(PropertyObject)

        self.assertEqual(obj.props.variant_def.print_(True), '42')
        self.assertEqual(obj.variant_def.print_(True), '42')

        obj.props.variant_def = GLib.Variant('y', 2)
        self.assertEqual(obj.variant_def.print_(True), "byte 0x02")

        # set in constructor
        obj = new(PropertyObject, variant_def=GLib.Variant('u', 5))
        self.assertEqual(obj.props.variant_def.print_(True), 'uint32 5')
Exemple #8
0
    def testStrings(self):
        obj = new(PropertyObject)

        # Should work with actual GStrv objects as well as
        # Python string lists
        class GStrv(list):
            __gtype__ = GObject.TYPE_STRV

        self.assertEqual(obj.props.strings, GStrv([]))
        self.assertEqual(obj.strings, GStrv([]))
        self.assertEqual(obj.props.strings, [])
        self.assertEqual(obj.strings, [])

        obj.strings = ['hello', 'world']
        self.assertEqual(obj.props.strings, ['hello', 'world'])
        self.assertEqual(obj.strings, ['hello', 'world'])

        obj.strings = GStrv(['hello', 'world'])
        self.assertEqual(obj.props.strings, GStrv(['hello', 'world']))
        self.assertEqual(obj.strings, GStrv(['hello', 'world']))

        obj.strings = []
        self.assertEqual(obj.strings, [])
        obj.strings = GStrv([])
        self.assertEqual(obj.strings, GStrv([]))

        p = GObject.Property(type=TYPE_STRV, default=['hello', '1'])
        self.assertEqual(p.default, ['hello', '1'])
        self.assertEqual(p.type, TYPE_STRV)
        p = GObject.Property(type=TYPE_STRV, default=GStrv(['hello', '1']))
        self.assertEqual(p.default, ['hello', '1'])
        self.assertEqual(p.type, TYPE_STRV)

        # set in constructor
        obj = new(PropertyObject, strings=['hello', 'world'])
        self.assertEqual(obj.props.strings, ['hello', 'world'])
        self.assertEqual(obj.strings, ['hello', 'world'])

        # wrong types
        self.assertRaises(TypeError, setattr, obj, 'strings', 1)
        self.assertRaises(TypeError, setattr, obj, 'strings', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'strings', ['foo', 1])

        self.assertRaises(TypeError, GObject.Property, type=TYPE_STRV,
                default=1)
        self.assertRaises(TypeError, GObject.Property, type=TYPE_STRV,
                default='foo')
        self.assertRaises(TypeError, GObject.Property, type=TYPE_STRV,
                default=['hello', 1])
Exemple #9
0
 def testNormal(self):
     obj = new(PropertyObject, normal="123")
     self.assertEqual(obj.props.normal, "123")
     obj.set_property('normal', '456')
     self.assertEqual(obj.props.normal, "456")
     obj.props.normal = '789'
     self.assertEqual(obj.props.normal, "789")
Exemple #10
0
    def testEnum(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)
        obj.enum = Gio.SocketType.DATAGRAM
        self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM)
        self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM)
        obj.props.enum = Gio.SocketType.STREAM
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)
        obj.props.enum = 2
        self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM)
        self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM)
        obj.enum = 1
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)

        self.assertRaises(TypeError, setattr, obj, 'enum', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'enum', object())

        self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType)
        self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType,
                          default=Gio.SocketProtocol.TCP)
        self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType,
                          default=object())
        self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType,
                          default=1)
Exemple #11
0
 def testConstructOnly(self):
     obj = new(PropertyObject, construct_only="123")
     self.assertEqual(obj.props.construct_only, "123")
     self.assertRaises(TypeError,
                       setattr, obj.props, 'construct_only', '456')
     self.assertRaises(TypeError,
                       obj.set_property, 'construct-only', '456')
Exemple #12
0
 def testIntToStr(self):
     obj = new(PropertyObject, construct_only=1)
     self.assertEqual(obj.props.construct_only, '1')
     obj.set_property('construct', '2')
     self.assertEqual(obj.props.construct, '2')
     obj.props.normal = 3
     self.assertEqual(obj.props.normal, '3')
Exemple #13
0
 def testUTF8(self):
     obj = new(PropertyObject, construct_only=UNICODE_UTF8)
     self.assertEqual(obj.props.construct_only, TEST_UTF8)
     obj.set_property('construct', UNICODE_UTF8)
     self.assertEqual(obj.props.construct, TEST_UTF8)
     obj.props.normal = UNICODE_UTF8
     self.assertEqual(obj.props.normal, TEST_UTF8)
Exemple #14
0
 def testConstruct(self):
     obj = new(PropertyObject, construct="123")
     self.assertEqual(obj.props.construct, "123")
     obj.set_property('construct', '456')
     self.assertEqual(obj.props.construct, "456")
     obj.props.construct = '789'
     self.assertEqual(obj.props.construct, "789")
 def test_construct_only(self):
     obj = new(PropertyObject, construct_only="123")
     self.assertEqual(obj.props.construct_only, "123")
     self.assertRaises(TypeError,
                       setattr, obj.props, 'construct_only', '456')
     self.assertRaises(TypeError,
                       obj.set_property, 'construct-only', '456')
Exemple #16
0
    def test_enum(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)
        obj.enum = Gio.SocketType.DATAGRAM
        self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM)
        self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM)
        obj.props.enum = Gio.SocketType.STREAM
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)
        obj.props.enum = 2
        self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM)
        self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM)
        obj.enum = 1
        self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
        self.assertEqual(obj.enum, Gio.SocketType.STREAM)

        self.assertRaises(TypeError, setattr, obj, 'enum', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'enum', object())

        self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType)
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=Gio.SocketType,
                          default=Gio.SocketProtocol.TCP)
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=Gio.SocketType,
                          default=object())
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=Gio.SocketType,
                          default=1)
Exemple #17
0
    def test_flags(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.flags, GIMarshallingTests.Flags.VALUE1)
        self.assertEqual(obj.flags, GIMarshallingTests.Flags.VALUE1)

        obj.flags = GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3
        self.assertEqual(
            obj.props.flags,
            GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3)
        self.assertEqual(
            obj.flags,
            GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3)

        self.assertRaises(TypeError, setattr, obj, 'flags', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'flags', object())
        self.assertRaises(TypeError, setattr, obj, 'flags', None)

        self.assertRaises(TypeError,
                          GObject.Property,
                          type=GIMarshallingTests.Flags,
                          default='foo')
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=GIMarshallingTests.Flags,
                          default=object())
        self.assertRaises(TypeError,
                          GObject.Property,
                          type=GIMarshallingTests.Flags,
                          default=None)
Exemple #18
0
 def test_utf8(self):
     obj = new(PropertyObject, construct_only=UNICODE_UTF8)
     self.assertEqual(obj.props.construct_only, TEST_UTF8)
     obj.set_property('construct', UNICODE_UTF8)
     self.assertEqual(obj.props.construct, TEST_UTF8)
     obj.props.normal = UNICODE_UTF8
     self.assertEqual(obj.props.normal, TEST_UTF8)
Exemple #19
0
 def test_int_to_str(self):
     obj = new(PropertyObject, construct_only=1)
     self.assertEqual(obj.props.construct_only, '1')
     obj.set_property('construct', '2')
     self.assertEqual(obj.props.construct, '2')
     obj.props.normal = 3
     self.assertEqual(obj.props.normal, '3')
Exemple #20
0
 def test_construct(self):
     obj = new(PropertyObject, construct="123")
     self.assertEqual(obj.props.construct, "123")
     obj.set_property('construct', '456')
     self.assertEqual(obj.props.construct, "456")
     obj.props.construct = '789'
     self.assertEqual(obj.props.construct, "789")
Exemple #21
0
 def test_normal(self):
     obj = new(PropertyObject, normal="123")
     self.assertEqual(obj.props.normal, "123")
     obj.set_property('normal', '456')
     self.assertEqual(obj.props.normal, "456")
     obj.props.normal = '789'
     self.assertEqual(obj.props.normal, "789")
Exemple #22
0
    def test_interface(self):
        obj = new(PropertyObject)

        file = Gio.File.new_for_path('/some/path')
        obj.props.interface = file
        self.assertEqual(obj.props.interface.get_path(), '/some/path')
        self.assertEqual(obj.interface.get_path(), '/some/path')

        self.assertRaises(TypeError, setattr, obj, 'interface', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'interface', object())
    def test_interface(self):
        obj = new(PropertyObject)

        file = Gio.File.new_for_path('/some/path')
        obj.props.interface = file
        self.assertEqual(obj.props.interface.get_path(), '/some/path')
        self.assertEqual(obj.interface.get_path(), '/some/path')

        self.assertRaises(TypeError, setattr, obj, 'interface', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'interface', object())
Exemple #24
0
    def testUint64(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.uint64, 0)
        obj.props.uint64 = _long(1)
        self.assertEqual(obj.props.uint64, _long(1))
        obj.props.uint64 = 1
        self.assertEqual(obj.props.uint64, _long(1))

        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", _long(-1))
        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1)
Exemple #25
0
    def test_boxed(self):
        obj = new(PropertyObject)

        regex = GLib.Regex.new('[a-z]*', 0, 0)
        obj.props.boxed = regex
        self.assertEqual(obj.props.boxed.get_pattern(), '[a-z]*')
        self.assertEqual(obj.boxed.get_pattern(), '[a-z]*')

        self.assertRaises(TypeError, setattr, obj, 'boxed', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'boxed', object())
Exemple #26
0
    def textBoxed(self):
        obj = new(PropertyObject)

        regex = GLib.Regex.new('[a-z]*', 0, 0)
        obj.props.boxed = regex
        self.assertEqual(obj.props.boxed.get_pattern(), '[a-z]*')
        self.assertEqual(obj.boxed.get_patttern(), '[a-z]*')

        self.assertRaises(TypeError, setattr, obj, 'boxed', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'boxed', object())
    def test_uint64(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.uint64, 0)
        obj.props.uint64 = _long(1)
        self.assertEqual(obj.props.uint64, _long(1))
        obj.props.uint64 = 1
        self.assertEqual(obj.props.uint64, _long(1))

        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", _long(-1))
        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1)
Exemple #28
0
    def testFlags(self):
        obj = new(PropertyObject)
        self.assertEqual(obj.props.flags, GIMarshallingTests.Flags.VALUE1)
        self.assertEqual(obj.flags, GIMarshallingTests.Flags.VALUE1)

        obj.flags = GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3
        self.assertEqual(obj.props.flags, GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3)
        self.assertEqual(obj.flags, GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE3)

        self.assertRaises(TypeError, setattr, obj, 'flags', 'foo')
        self.assertRaises(TypeError, setattr, obj, 'flags', object())
        self.assertRaises(TypeError, setattr, obj, 'flags', None)

        self.assertRaises(TypeError, GObject.Property,
                type=GIMarshallingTests.Flags, default='foo')
        self.assertRaises(TypeError, GObject.Property,
                type=GIMarshallingTests.Flags, default=object())
        self.assertRaises(TypeError, GObject.Property,
                type=GIMarshallingTests.Flags, default=None)