pygobject r752 - in trunk: . gobject tests
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r752 - in trunk: . gobject tests
- Date: Fri, 21 Mar 2008 18:06:57 +0000 (GMT)
Author: johan
Date: Fri Mar 21 18:06:56 2008
New Revision: 752
URL: http://svn.gnome.org/viewvc/pygobject?rev=752&view=rev
Log:
2008-03-21 Johan Dahlin <johan gnome org>
* gobject/__init__.py:
* tests/test_properties.py:
Allow gobject.property work with subclasses. Add tests.
(#523352, Tomeu Vizoso)
Modified:
trunk/ChangeLog
trunk/gobject/__init__.py
trunk/tests/test_properties.py
Modified: trunk/gobject/__init__.py
==============================================================================
--- trunk/gobject/__init__.py (original)
+++ trunk/gobject/__init__.py Fri Mar 21 18:06:56 2008
@@ -57,15 +57,16 @@
cls.__gproperties__ = gproperties
- if (hasattr(cls, 'do_get_property') or
- hasattr(cls, 'do_set_property')):
+ if ('do_get_property' in cls.__dict__ or
+ 'do_set_property' in cls.__dict__):
for prop in props:
if (prop.getter != prop._default_getter or
prop.setter != prop._default_setter):
raise TypeError(
"GObject subclass %r defines do_get/set_property"
" and it also uses a property which a custom setter"
- " or getter. This is not allowed" % (cls,))
+ " or getter. This is not allowed" % (
+ cls.__name__,))
def obj_get_property(self, pspec):
name = pspec.name.replace('-', '_')
@@ -92,7 +93,6 @@
return
type_register(cls, namespace.get('__gtype_name__'))
-
_gobject._install_metaclass(GObjectMeta)
del _gobject
Modified: trunk/tests/test_properties.py
==============================================================================
--- trunk/tests/test_properties.py (original)
+++ trunk/tests/test_properties.py Fri Mar 21 18:06:56 2008
@@ -327,6 +327,41 @@
b.prop1 = 20
self.assertEquals(b.prop1, 20)
+ def testPropertySubclassCustomSetter(self):
+ # test for #523352
+ class A(GObject):
+ def get_first(self):
+ return 'first'
+ first = gobject.property(type=str, getter=get_first)
+
+ class B(A):
+ def get_second(self):
+ return 'second'
+ second = gobject.property(type=str, getter=get_second)
+
+ a = A()
+ self.assertEquals(a.first, 'first')
+ self.assertRaises(TypeError, setattr, a, 'first', 'foo')
+
+ b = B()
+ self.assertEquals(b.first, 'first')
+ self.assertRaises(TypeError, setattr, b, 'first', 'foo')
+ self.assertEquals(b.second, 'second')
+ self.assertRaises(TypeError, setattr, b, 'second', 'foo')
+
+ def testPropertySubclassCustomSetterError(self):
+ try:
+ class A(GObject):
+ def get_first(self):
+ return 'first'
+ first = gobject.property(type=str, getter=get_first)
+
+ def do_get_property(self, pspec):
+ pass
+ except TypeError:
+ pass
+ else:
+ raise AssertionError
if __name__ == '__main__':
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]