pygobject r1030 - in trunk: . gobject tests
- From: marklee svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r1030 - in trunk: . gobject tests
- Date: Sun, 22 Mar 2009 22:11:09 +0000 (UTC)
Author: marklee
Date: Sun Mar 22 22:11:09 2009
New Revision: 1030
URL: http://svn.gnome.org/viewvc/pygobject?rev=1030&view=rev
Log:
Bug 559001 â Allow setting pytype wrapper class
initial patch by: John Ehresman <jpe wingware com>
* gobject/pygtype.c (_wrap_g_type_wrapper__set_pytype): New function.
* tests/test_gtype.py (GTypeTest.assertPyType),
(GTypeTest.setInvalidPyType), (GTypeTest.testPyType),
(GTypeTest.testInvalidPyType): Two new testcases to test the above,
with accompanying helper methods.
Modified:
trunk/ChangeLog
trunk/gobject/pygtype.c
trunk/tests/test_gtype.py
Modified: trunk/gobject/pygtype.c
==============================================================================
--- trunk/gobject/pygtype.c (original)
+++ trunk/gobject/pygtype.c Sun Mar 22 22:11:09 2009
@@ -83,6 +83,26 @@
return py_type;
}
+static int
+_wrap_g_type_wrapper__set_pytype(PyGTypeWrapper *self, PyObject* value, void *closure)
+{
+ PyObject *py_type;
+
+ py_type = g_type_get_qdata(self->type, pygobject_class_key);
+ Py_CLEAR(py_type);
+ if (value == Py_None)
+ g_type_set_qdata(self->type, pygobject_class_key, NULL);
+ else if (PyType_Check(value)) {
+ Py_INCREF(value);
+ g_type_set_qdata(self->type, pygobject_class_key, value);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Value must be None or a type object");
+ return -1;
+ }
+
+ return 0;
+}
+
static PyObject *
_wrap_g_type_wrapper__get_name(PyGTypeWrapper *self, void *closure)
{
@@ -143,7 +163,7 @@
}
static PyGetSetDef _PyGTypeWrapper_getsets[] = {
- { "pytype", (getter)_wrap_g_type_wrapper__get_pytype, (setter)0 },
+ { "pytype", (getter)_wrap_g_type_wrapper__get_pytype, (setter)_wrap_g_type_wrapper__set_pytype },
{ "name", (getter)_wrap_g_type_wrapper__get_name, (setter)0 },
{ "fundamental", (getter)_wrap_g_type_wrapper__get_fundamental, (setter)0 },
{ "parent", (getter)_wrap_g_type_wrapper__get_parent, (setter)0 },
Modified: trunk/tests/test_gtype.py
==============================================================================
--- trunk/tests/test_gtype.py (original)
+++ trunk/tests/test_gtype.py Sun Mar 22 22:11:09 2009
@@ -28,6 +28,15 @@
'got %r while %r was expected' %
(val, expected))
+ def assertPyType(self, val, pytype):
+ val.pytype = pytype
+ self.assertEqual(val.pytype, pytype,
+ 'got %r while %r was expected' % (val.pytype, pytype))
+
+ def setInvalidPyType(self):
+ val = GType(gobject.TYPE_INT)
+ val.pytype = 1
+
def testBool(self):
self.checkType(gobject.TYPE_BOOLEAN, 'gboolean', bool)
@@ -64,6 +73,16 @@
def testObject(self):
self.checkType(gobject.TYPE_OBJECT, 'PyObject')
+ def testPyType(self):
+ val = GType(gobject.TYPE_INT)
+ self.assertEqual(val.pytype, None,
+ 'got %r while %r was expected' % (val.pytype, None))
+ for t in [int, None, float]:
+ self.assertPyType(val, t)
+
+ def testInvalidPyType(self):
+ self.assertRaises(TypeError, self.setInvalidPyType)
+
def testValue(self):
array = [1, "foo", True]
for i in array:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]