[pygobject] fix passing in type names as a GType and add gtype unit tests
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] fix passing in type names as a GType and add gtype unit tests
- Date: Mon, 26 Jul 2010 10:25:00 +0000 (UTC)
commit 1162e436273ff8e9e4e24bd8ba74615fd4624753
Author: John (J5) Palmieri <johnp redhat com>
Date: Thu Jun 24 10:07:12 2010 -0400
fix passing in type names as a GType and add gtype unit tests
* a simple call to pyg_type_from_object covers all the bases
* added unit tests to check for correct GType value passing
* fixed up tree override tests to also check different ways of passing GTypes
https://bugzilla.gnome.org/show_bug.cgi?id=622605
gi/pygi-argument.c | 8 +-------
tests/test_everything.py | 27 +++++++++++++++++++++++++++
tests/test_overrides.py | 6 ++----
3 files changed, 30 insertions(+), 11 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 1b2e0d2..ed1c5ff 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -253,13 +253,7 @@ check_number_release:
{
gint is_instance;
- is_instance = PyObject_IsInstance (object, (PyObject *) &PyGTypeWrapper_Type);
- if (is_instance < 0) {
- retval = -1;
- break;
- }
-
- if (!is_instance && (!PyType_Check (object) || pyg_type_from_object (object) == 0)) {
+ if (pyg_type_from_object (object) == 0) {
PyErr_Format (PyExc_TypeError, "Must be gobject.GType, not %s",
object->ob_type->tp_name);
retval = 0;
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 4e68b65..66aa889 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -93,6 +93,33 @@ class TestEverything(unittest.TestCase):
except TypeError, e:
self.assertEquals(e.args, ("test_int8() takes exactly 1 argument(s) (0 given)",))
+ def test_gtypes(self):
+ gchararray_gtype = GObject.type_from_name('gchararray')
+ gtype = Everything.test_gtype(str)
+ self.assertEquals(gchararray_gtype, gtype)
+ gtype = Everything.test_gtype('gchararray')
+ self.assertEquals(gchararray_gtype, gtype)
+ gobject_gtype = GObject.GObject.__gtype__
+ gtype = Everything.test_gtype(GObject.GObject)
+ self.assertEquals(gobject_gtype, gtype)
+ gtype = Everything.test_gtype('GObject')
+ self.assertEquals(gobject_gtype, gtype)
+ self.assertRaises(TypeError, Everything.test_gtype, 'invalidgtype')
+
+ class NotARegisteredClass(object):
+ pass
+
+ self.assertRaises(TypeError, Everything.test_gtype, NotARegisteredClass)
+
+ class ARegisteredClass(GObject.GObject):
+ __gtype_name__ = 'EverythingTestsARegisteredClass'
+
+ gtype = Everything.test_gtype('EverythingTestsARegisteredClass')
+ self.assertEquals(ARegisteredClass.__gtype__, gtype)
+ gtype = Everything.test_gtype(ARegisteredClass)
+ self.assertEquals(ARegisteredClass.__gtype__, gtype)
+ self.assertRaises(TypeError, Everything.test_gtype, 'ARegisteredClass')
+
class TestNullableArgs(unittest.TestCase):
def test_in_nullable_hash(self):
Everything.test_ghash_null_in(None)
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 0a66587..87eca5d 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -176,8 +176,7 @@ class TestGtk(unittest.TestCase):
self.tester.assertEquals(string_value, self.string_value)
# check TreeStore
- # FIXME: we should be able to pass strings like 'TestClass'
- tree_store = Gtk.TreeStore(int, str, TestClass)
+ tree_store = Gtk.TreeStore(int, 'gchararray', TestClass)
parent = None
for i in xrange(100):
label = 'this is child #%d' % i
@@ -205,8 +204,7 @@ class TestGtk(unittest.TestCase):
self.assertEquals(i, 99)
# check ListStore
- # FIXME: we should be able to pass strings like 'TestClass'
- list_store = Gtk.ListStore(int, str, TestClass)
+ list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest')
for i in xrange(100):
label = 'this is row #%d' % i
testobj = TestClass(self, i, label)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]