Exemplo n.º 1
0
    def test_property_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'PropertiesObject')
        prop = find_child_info(info, 'get_properties', 'some-object')

        flags = GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT
        self.assertEqual(prop.get_flags(), flags)
        self.assertEqual(prop.get_type().get_tag(), GIRepository.TypeTag.INTERFACE)
        self.assertEqual(prop.get_type().get_interface(),
                         repo.find_by_name('GObject', 'Object'))
        self.assertEqual(prop.get_ownership_transfer(), GIRepository.Transfer.NOTHING)
Exemplo n.º 2
0
 def test_base_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertEqual(info.__name__, 'Object')
     self.assertEqual(info.get_name(), 'Object')
     self.assertEqual(info.__module__, 'gi.repository.GIMarshallingTests')
     self.assertEqual(info.get_name_unescaped(), 'Object')
     self.assertEqual(info.get_namespace(), 'GIMarshallingTests')
     self.assertEqual(info.get_container(), None)
     info2 = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertFalse(info is info2)
     self.assertEqual(info, info2)
     self.assertTrue(info.equal(info2))
Exemplo n.º 3
0
 def test_object_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertEqual(info.get_parent(), repo.find_by_name('GObject', 'Object'))
     self.assertTrue(isinstance(info.get_methods(), collections.Iterable))
     self.assertTrue(isinstance(info.get_fields(), collections.Iterable))
     self.assertTrue(isinstance(info.get_interfaces(), collections.Iterable))
     self.assertTrue(isinstance(info.get_constants(), collections.Iterable))
     self.assertTrue(isinstance(info.get_vfuncs(), collections.Iterable))
     self.assertTrue(isinstance(info.get_properties(), collections.Iterable))
     self.assertFalse(info.get_abstract())
     self.assertEqual(info.get_class_struct(), repo.find_by_name('GIMarshallingTests', 'ObjectClass'))
     self.assertEqual(info.get_type_name(), 'GIMarshallingTestsObject')
     self.assertEqual(info.get_type_init(), 'gi_marshalling_tests_object_get_type')
     self.assertFalse(info.get_fundamental())
     self.assertEqual(info.get_parent(), repo.find_by_name('GObject', 'Object'))
Exemplo n.º 4
0
 def test_base_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertEqual(info.__name__, 'Object')
     self.assertEqual(info.get_name(), 'Object')
     self.assertEqual(info.__module__, 'gi.repository.GIMarshallingTests')
     self.assertEqual(info.get_name_unescaped(), 'Object')
     self.assertEqual(info.get_namespace(), 'GIMarshallingTests')
     self.assertEqual(info.get_container(), None)
     info2 = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertFalse(info is info2)
     self.assertEqual(info, info2)
     self.assertTrue(info.equal(info2))
     assert isinstance(info.is_deprecated(), bool)
     assert isinstance(info.get_type(), int)
     assert info.get_attribute("nopenope") is None
Exemplo n.º 5
0
 def test_base_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertEqual(info.__name__, 'Object')
     self.assertEqual(info.get_name(), 'Object')
     self.assertEqual(info.__module__, 'gi.repository.GIMarshallingTests')
     self.assertEqual(info.get_name_unescaped(), 'Object')
     self.assertEqual(info.get_namespace(), 'GIMarshallingTests')
     self.assertEqual(info.get_container(), None)
     info2 = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertFalse(info is info2)
     self.assertEqual(info, info2)
     self.assertTrue(info.equal(info2))
     assert isinstance(info.is_deprecated(), bool)
     assert isinstance(info.get_type(), int)
     assert info.get_attribute("nopenope") is None
Exemplo n.º 6
0
 def test_union_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Union')
     self.assertTrue(isinstance(info, GIRepository.UnionInfo))
     self.assertTrue(isinstance(info.get_fields(), abc.Iterable))
     self.assertTrue(isinstance(info.get_methods(), abc.Iterable))
     self.assertTrue(isinstance(info.get_size(), int))
     self.assertTrue(isinstance(info.get_alignment(), int))
Exemplo n.º 7
0
    def test_struct_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'InterfaceIface')
        self.assertTrue(isinstance(info, GIRepository.StructInfo))
        self.assertTrue(isinstance(info.get_fields(), abc.Iterable))
        self.assertTrue(isinstance(info.get_methods(), abc.Iterable))
        self.assertTrue(isinstance(info.get_size(), int))
        self.assertTrue(isinstance(info.get_alignment(), int))
        self.assertTrue(info.is_gtype_struct())
        self.assertFalse(info.is_foreign())

        info = repo.find_by_name('GIMarshallingTests', 'SimpleStruct')
        assert info.find_method("nope") is None
        assert isinstance(info.find_method("method"), GIRepository.FunctionInfo)

        assert info.find_field("nope") is None
        assert isinstance(info.find_field("int8"), GIRepository.FieldInfo)
Exemplo n.º 8
0
 def test_enum_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Enum')
     self.assertTrue(isinstance(info, GIRepository.EnumInfo))
     self.assertTrue(isinstance(info.get_values(), collections.Iterable))
     self.assertTrue(isinstance(info.get_methods(), collections.Iterable))
     self.assertFalse(info.is_flags())
     self.assertTrue(info.get_storage_type() > 0)  # might be platform dependent
Exemplo n.º 9
0
    def test_interface_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'Interface')
        self.assertTrue(isinstance(info.get_methods(), collections.Iterable))
        self.assertTrue(isinstance(info.get_vfuncs(), collections.Iterable))
        self.assertTrue(isinstance(info.get_constants(), collections.Iterable))
        self.assertTrue(isinstance(info.get_prerequisites(), collections.Iterable))
        self.assertTrue(isinstance(info.get_properties(), collections.Iterable))
        self.assertTrue(isinstance(info.get_signals(), collections.Iterable))

        method = info.find_method('test_int8_in')
        vfunc = info.find_vfunc('test_int8_in')
        self.assertEqual(method.get_name(), 'test_int8_in')
        self.assertEqual(vfunc.get_invoker(), method)
        self.assertEqual(method.get_vfunc(), vfunc)

        iface = info.get_iface_struct()
        self.assertEqual(iface, repo.find_by_name('GIMarshallingTests', 'InterfaceIface'))
Exemplo n.º 10
0
    def test_type_info(self):
        func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct')
        arg_info, = func_info.get_arguments()
        type_info = arg_info.get_type()

        self.assertTrue(type_info.is_pointer())
        self.assertEqual(type_info.get_tag(), GIRepository.TypeTag.ARRAY)
        self.assertEqual(type_info.get_tag_as_string(), 'array')
        self.assertEqual(type_info.get_param_type(0).get_tag(),
                         GIRepository.TypeTag.INTERFACE)
        self.assertEqual(type_info.get_param_type(0).get_interface(),
                         repo.find_by_name('GIMarshallingTests', 'SimpleStruct'))
        self.assertEqual(type_info.get_interface(), None)
        self.assertEqual(type_info.get_array_length(), -1)
        self.assertEqual(type_info.get_array_fixed_size(), 2)
        self.assertFalse(type_info.is_zero_terminated())
        self.assertEqual(type_info.get_array_type(), GIRepository.ArrayType.C)
Exemplo n.º 11
0
 def test_callable_info(self):
     func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct')
     self.assertTrue(hasattr(func_info, 'invoke'))
     self.assertTrue(isinstance(func_info.get_arguments(), collections.Iterable))
     self.assertEqual(func_info.get_caller_owns(), GIRepository.Transfer.NOTHING)
     self.assertFalse(func_info.may_return_null())
     self.assertEqual(func_info.get_return_type().get_tag(), GIRepository.TypeTag.VOID)
     self.assertRaises(AttributeError, func_info.get_return_attribute, '_not_an_attr')
Exemplo n.º 12
0
 def test_object_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     self.assertEqual(info.get_parent(), repo.find_by_name('GObject', 'Object'))
     self.assertTrue(isinstance(info.get_methods(), abc.Iterable))
     self.assertTrue(isinstance(info.get_fields(), abc.Iterable))
     self.assertTrue(isinstance(info.get_interfaces(), abc.Iterable))
     self.assertTrue(isinstance(info.get_constants(), abc.Iterable))
     self.assertTrue(isinstance(info.get_vfuncs(), abc.Iterable))
     self.assertTrue(isinstance(info.get_properties(), abc.Iterable))
     self.assertFalse(info.get_abstract())
     self.assertEqual(info.get_class_struct(), repo.find_by_name('GIMarshallingTests', 'ObjectClass'))
     self.assertEqual(info.get_type_name(), 'GIMarshallingTestsObject')
     self.assertEqual(info.get_type_init(), 'gi_marshalling_tests_object_get_type')
     self.assertFalse(info.get_fundamental())
     self.assertEqual(info.get_parent(), repo.find_by_name('GObject', 'Object'))
     assert info.find_vfunc("nopenope") is None
     vfunc = info.find_vfunc("method_int8_out")
     assert isinstance(vfunc, GIRepository.VFuncInfo)
Exemplo n.º 13
0
 def test_fundamental_object_info(self):
     repo.require('Regress')
     info = repo.find_by_name('Regress', 'TestFundamentalObject')
     self.assertTrue(info.get_abstract())
     self.assertTrue(info.get_fundamental())
     self.assertEqual(info.get_ref_function(), 'regress_test_fundamental_object_ref')
     self.assertEqual(info.get_unref_function(), 'regress_test_fundamental_object_unref')
     self.assertEqual(info.get_get_value_function(), 'regress_test_value_get_fundamental_object')
     self.assertEqual(info.get_set_value_function(), 'regress_test_value_set_fundamental_object')
Exemplo n.º 14
0
 def test_registered_type_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Object')
     # Call these from the class because GIObjectInfo overrides them
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_g_type(info),
                      GObject.type_from_name('GIMarshallingTestsObject'))
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_type_name(info),
                      'GIMarshallingTestsObject')
     self.assertEqual(GIRepository.RegisteredTypeInfo.get_type_init(info),
                      'gi_marshalling_tests_object_get_type')
Exemplo n.º 15
0
 def test_struct_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'InterfaceIface')
     self.assertTrue(isinstance(info, GIRepository.StructInfo))
     self.assertTrue(isinstance(info.get_fields(), collections.Iterable))
     self.assertTrue(isinstance(info.get_methods(), collections.Iterable))
     self.assertTrue(isinstance(info.get_size(), int))
     self.assertTrue(isinstance(info.get_alignment(), int))
     self.assertTrue(info.is_gtype_struct())
     self.assertFalse(info.is_foreign())
Exemplo n.º 16
0
 def test_enum_double_registration_error(self):
     # a warning is printed for double registration and pygobject will
     # also raise a RuntimeError.
     GIMarshallingTests.Enum  # cause enum registration
     info = repo.find_by_name('GIMarshallingTests', 'Enum')
     with capture_glib_warnings(allow_warnings=True):
         self.assertRaises(RuntimeError,
                           GIRepository.enum_register_new_gtype_and_add,
                           info)
Exemplo n.º 17
0
    def test_field_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'InterfaceIface')
        field = find_child_info(info, 'get_fields', 'test_int8_in')
        self.assertEqual(field.get_name(), 'test_int8_in')
        self.assertTrue(field.get_flags() & GIRepository.FieldInfoFlags.IS_READABLE)
        self.assertFalse(field.get_flags() & GIRepository.FieldInfoFlags.IS_WRITABLE)
        self.assertEqual(field.get_type().get_tag(), GIRepository.TypeTag.INTERFACE)

        # don't test actual values because that might fail with architecture differences
        self.assertTrue(isinstance(field.get_size(), int))
        self.assertTrue(isinstance(field.get_offset(), int))
Exemplo n.º 18
0
 def test_enum_double_registration_error(self):
     # a warning is printed for double registration and pygobject will
     # also raise a RuntimeError.
     GIMarshallingTests.Enum  # cause enum registration
     info = repo.find_by_name('GIMarshallingTests', 'Enum')
     old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_ERROR)
     try:
         self.assertRaises(RuntimeError,
                           GIRepository.enum_register_new_gtype_and_add,
                           info)
     finally:
         GLib.log_set_always_fatal(old_mask)
Exemplo n.º 19
0
 def test_enum_double_registration_error(self):
     # a warning is printed for double registration and pygobject will
     # also raise a RuntimeError.
     GIMarshallingTests.Enum  # cause enum registration
     info = repo.find_by_name('GIMarshallingTests', 'Enum')
     old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_ERROR)
     try:
         self.assertRaises(RuntimeError,
                           GIRepository.enum_register_new_gtype_and_add,
                           info)
     finally:
         GLib.log_set_always_fatal(old_mask)
Exemplo n.º 20
0
    def test_vfunc_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'Object')
        invoker = find_child_info(info, 'get_methods', 'vfunc_return_value_only')
        vfunc = find_child_info(info, 'get_vfuncs', 'vfunc_return_value_only')

        self.assertTrue(isinstance(vfunc, GIRepository.CallableInfo))
        self.assertTrue(isinstance(vfunc, GIRepository.VFuncInfo))
        self.assertEqual(vfunc.get_name(), 'vfunc_return_value_only')
        self.assertEqual(vfunc.get_invoker(), invoker)
        self.assertEqual(invoker, info.find_method('vfunc_return_value_only'))
        self.assertEqual(vfunc.get_flags(), 0)
        self.assertEqual(vfunc.get_offset(), 0xFFFF)  # unknown offset
        self.assertEqual(vfunc.get_signal(), None)
Exemplo n.º 21
0
    def test_notify_signal_info_with_obj(self):
        repo.require('Regress')
        info = repo.find_by_name('Regress', 'TestObj')
        sig_info = find_child_info(info, 'get_signals', 'sig-with-array-prop')

        sig_flags = GObject.SignalFlags.RUN_LAST

        self.assertTrue(sig_info is not None)
        self.assertTrue(isinstance(sig_info, GIRepository.CallableInfo))
        self.assertTrue(isinstance(sig_info, GIRepository.SignalInfo))
        self.assertEqual(sig_info.get_name(), 'sig-with-array-prop')
        self.assertEqual(sig_info.get_class_closure(), None)
        self.assertFalse(sig_info.true_stops_emit())
        self.assertEqual(sig_info.get_flags(), sig_flags)
Exemplo n.º 22
0
    def test_callable_can_throw_gerror(self):
        info = repo.find_by_name('GIMarshallingTests', 'Object')
        invoker = find_child_info(info, 'get_methods', 'vfunc_meth_with_error')
        vfunc = find_child_info(info, 'get_vfuncs', 'vfunc_meth_with_err')

        self.assertTrue(invoker.can_throw_gerror())
        self.assertTrue(vfunc.can_throw_gerror())

        # Test that args do not include the GError**
        self.assertEqual(len(invoker.get_arguments()), 1)
        self.assertEqual(len(vfunc.get_arguments()), 1)

        # Sanity check method that does not throw.
        invoker_no_throws = find_child_info(info, 'get_methods', 'method_int8_in')
        self.assertFalse(invoker_no_throws.can_throw_gerror())
Exemplo n.º 23
0
    def test_signal_info(self):
        repo.require('Regress')
        info = repo.find_by_name('Regress', 'TestObj')
        sig_info = find_child_info(info, 'get_signals', 'test')

        sig_flags = GObject.SignalFlags.RUN_LAST | \
            GObject.SignalFlags.NO_RECURSE | GObject.SignalFlags.NO_HOOKS

        self.assertTrue(sig_info is not None)
        self.assertTrue(isinstance(sig_info, GIRepository.CallableInfo))
        self.assertTrue(isinstance(sig_info, GIRepository.SignalInfo))
        self.assertEqual(sig_info.get_name(), 'test')
        self.assertEqual(sig_info.get_class_closure(), None)
        self.assertFalse(sig_info.true_stops_emit())
        self.assertEqual(sig_info.get_flags(), sig_flags)
Exemplo n.º 24
0
    def test_arg_info(self):
        func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct')
        args = func_info.get_arguments()
        self.assertTrue(len(args), 1)

        arg = args[0]
        self.assertEqual(arg.get_container(), func_info)
        self.assertEqual(arg.get_direction(), GIRepository.Direction.OUT)
        self.assertEqual(arg.get_name(), 'structs')
        self.assertEqual(arg.get_namespace(), 'GIMarshallingTests')
        self.assertFalse(arg.is_caller_allocates())
        self.assertFalse(arg.is_optional())
        self.assertFalse(arg.is_return_value())
        self.assertFalse(arg.may_be_null())
        self.assertEqual(arg.get_destroy(), -1)
        self.assertEqual(arg.get_ownership_transfer(), GIRepository.Transfer.NOTHING)
        self.assertEqual(arg.get_scope(), GIRepository.ScopeType.INVALID)
        self.assertEqual(arg.get_type().get_tag(), GIRepository.TypeTag.ARRAY)
Exemplo n.º 25
0
    def test_method_info(self):
        info = repo.find_by_name('GIMarshallingTests', 'Object')
        method = find_child_info(info, 'get_methods', 'vfunc_return_value_only')

        self.assertTrue(isinstance(method, GIRepository.CallableInfo))
        self.assertTrue(isinstance(method, GIRepository.FunctionInfo))
        self.assertTrue(method in info.get_methods())
        self.assertEqual(method.get_name(), 'vfunc_return_value_only')
        self.assertFalse(method.is_constructor())
        self.assertEqual(method.get_symbol(), 'gi_marshalling_tests_object_vfunc_return_value_only')
        self.assertTrue(method.is_method())

        flags = method.get_flags()
        self.assertTrue(flags & GIRepository.FunctionInfoFlags.IS_METHOD)
        self.assertFalse(flags & GIRepository.FunctionInfoFlags.IS_CONSTRUCTOR)
        self.assertFalse(flags & GIRepository.FunctionInfoFlags.IS_GETTER)
        self.assertFalse(flags & GIRepository.FunctionInfoFlags.IS_SETTER)
        self.assertFalse(flags & GIRepository.FunctionInfoFlags.WRAPS_VFUNC)
        self.assertFalse(flags & GIRepository.FunctionInfoFlags.THROWS)
Exemplo n.º 26
0
 def test_union_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Union')
     self.assertTrue(isinstance(info, GIRepository.UnionInfo))
     self.assertTrue(isinstance(info.get_fields(), collections.Iterable))
     self.assertTrue(isinstance(info.get_methods(), collections.Iterable))
Exemplo n.º 27
0
 def test_union_info(self):
     info = repo.find_by_name('GIMarshallingTests', 'Union')
     self.assertTrue(isinstance(info, GIRepository.UnionInfo))
     self.assertTrue(isinstance(info.get_fields(), collections.Iterable))
     self.assertTrue(isinstance(info.get_methods(), collections.Iterable))