[pygobject/gsoc2009: 16/160] Add GType argument support



commit eb47b6f6547ae33212aa7eed8a92cd0da4add623
Author: Simon van der Linden <simon vanderlinden student uclouvain be>
Date:   Fri Jun 26 22:14:37 2009 +0200

    Add GType argument support

 girepository/bank-argument.c |   21 ++++++++++++++++++++-
 tests/test_girepository.py   |   20 +++++---------------
 2 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/girepository/bank-argument.c b/girepository/bank-argument.c
index d58b5cc..75538c4 100644
--- a/girepository/bank-argument.c
+++ b/girepository/bank-argument.c
@@ -277,8 +277,17 @@ pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError
 
             break;
         }
-        case GI_TYPE_TAG_TIME_T:
         case GI_TYPE_TAG_GTYPE:
+        {
+            GType gtype;
+            gtype = pyg_type_from_object(object);
+            if (gtype == 0) {
+                py_type_name_expected = "GType";
+                goto check_error_type;
+            }
+            break;
+        }
+        case GI_TYPE_TAG_TIME_T:
         case GI_TYPE_TAG_FILENAME:
         case GI_TYPE_TAG_GLIST:
         case GI_TYPE_TAG_GSLIST:
@@ -398,6 +407,9 @@ pyg_argument_from_pyobject(PyObject *object, GITypeInfo *type_info)
             arg.v_pointer = NULL;
             break;
         }
+    case GI_TYPE_TAG_GTYPE:
+        arg.v_int = pyg_type_from_object(object);
+        break;
     default:
         g_print("<PyO->GArg> GITypeTag %s is unhandled\n",
                 g_type_tag_to_string(type_tag));
@@ -659,6 +671,13 @@ pyg_argument_to_pyobject(GArgument *arg, GITypeInfo *type_info)
         g_warning("pyg_argument_to_pyobject: use pyarray_to_pyobject instead for arrays");
         obj = Py_None;
         break;
+    case GI_TYPE_TAG_GTYPE:
+    {
+        GType gtype;
+        gtype = arg->v_int;
+        obj = pyg_type_wrapper_new(gtype);
+        break;
+    }
     default:
         g_print("<GArg->PyO> GITypeTag %s is unhandled\n",
                 g_type_tag_to_string(type_tag));
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index 735a23d..e17ed1f 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -218,21 +218,11 @@ class TestGIEverything(unittest.TestCase):
 #        self.assertEquals(now.tm_year, bounced.tm_yday)
 #        self.assertEquals(now.tm_year, bounced.tm_isdst)
 
-# FIXME
-# ======================================================================
-# ERROR: testGType (__main__.TestGIEverything)
-# ----------------------------------------------------------------------
-# Traceback (most recent call last):
-#   File "test_girepository.py", line 169, in testGType
-#     self.assertEqual(gobject.TYPE_INT, Everything.test_gtype(gobject.TYPE_INT))
-#   File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 124, in __call__
-#     self.type_check(name, value, argType)
-#   File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 97, in type_check
-#     raise NotImplementedError('type checking for tag %d' % tag)
-# NotImplementedError: type checking for tag 19
-#	def testGType(self):
-#	    self.assertEqual(gobject.TYPE_INT, Everything.test_gtype(gobject.TYPE_INT))
-#	    self.assertRaises(TypeError, Everything.test_gtype, 'a')
+    def testGType(self):
+        self.assertEqual(gobject.TYPE_INT, Everything.test_gtype(gobject.TYPE_INT))
+        self.assertEqual(Everything.TestObj.__gtype__, Everything.test_gtype(Everything.TestObj))
+        self.assertRaises(TypeError, Everything.test_gtype, 'a')
+
 
 # UTF-8
 



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