[pygobject: 1/2] pygi-info: wrap g_struct_info_find_method() and g_struct_info_find_field()



commit b2f8a612ded5c093c5d1fb998c1aa0b1ed8d24fb
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed Dec 12 22:14:42 2018 +0100

    pygi-info: wrap g_struct_info_find_method() and g_struct_info_find_field()
    
    Because why not.

 gi/pygi-info.c           | 14 ++++++++++++++
 tests/test_repository.py |  7 +++++++
 2 files changed, 21 insertions(+)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 4fca825a..e9456f82 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1307,9 +1307,23 @@ _wrap_g_struct_info_is_foreign (PyGIBaseInfo *self)
     return pygi_gboolean_to_py (g_struct_info_is_foreign (self->info));
 }
 
+static PyObject *
+_wrap_g_struct_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
+{
+    return _get_child_info_by_name (self, py_name, g_struct_info_find_method);
+}
+
+static PyObject *
+_wrap_g_struct_info_find_field (PyGIBaseInfo *self, PyObject *py_name)
+{
+    return _get_child_info_by_name (self, py_name, g_struct_info_find_field);
+}
+
 static PyMethodDef _PyGIStructInfo_methods[] = {
     { "get_fields", (PyCFunction) _wrap_g_struct_info_get_fields, METH_NOARGS },
+    { "find_field", (PyCFunction) _wrap_g_struct_info_find_field, METH_O },
     { "get_methods", (PyCFunction) _wrap_g_struct_info_get_methods, METH_NOARGS },
+    { "find_method", (PyCFunction) _wrap_g_struct_info_find_method, METH_O },
     { "get_size", (PyCFunction) _wrap_g_struct_info_get_size, METH_NOARGS },
     { "get_alignment", (PyCFunction) _wrap_g_struct_info_get_alignment, METH_NOARGS },
     { "is_gtype_struct", (PyCFunction) _wrap_g_struct_info_is_gtype_struct, METH_NOARGS },
diff --git a/tests/test_repository.py b/tests/test_repository.py
index de2e5c95..18613167 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -189,6 +189,13 @@ class Test(unittest.TestCase):
         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)
+
     def test_enum_info(self):
         info = repo.find_by_name('GIMarshallingTests', 'Enum')
         self.assertTrue(isinstance(info, GIRepository.EnumInfo))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]