diff options
author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-08-27 13:10:39 +0000 |
---|---|---|
committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-08-27 13:10:39 +0000 |
commit | 078439f05b12ed4756e87f0e8c1c6ff1e93da880 (patch) | |
tree | 1df614371ddd683f2977b5130c0e1f8831a62792 | |
parent | 4c8bec8e5e7506ff386f234494e247ed5bc01026 (diff) | |
download | pygobject-078439f05b12ed4756e87f0e8c1c6ff1e93da880.tar.gz pygobject-078439f05b12ed4756e87f0e8c1c6ff1e93da880.tar.xz pygobject-078439f05b12ed4756e87f0e8c1c6ff1e93da880.zip |
Bug 470230 – check for default value in boolean type is wrong
svn path=/trunk/; revision=698
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | gobject/propertyhelper.py | 4 | ||||
-rw-r--r-- | tests/test_properties.py | 14 |
3 files changed, 22 insertions, 4 deletions
@@ -1,3 +1,11 @@ +2007-08-27 Marco Giusti <marco.giusti@gmail.com> + + reviewed by: Gustavo J. A. M. Carneiro + + * gobject/propertyhelper.py: + * tests/test_properties.py: + Bug 470230 – check for default value in boolean type is wrong. + 2007-08-27 Gustavo J. A. M. Carneiro <gjc@gnome.org> * tests/Makefile.am, diff --git a/gobject/propertyhelper.py b/gobject/propertyhelper.py index c382c83..cc987ec 100644 --- a/gobject/propertyhelper.py +++ b/gobject/propertyhelper.py @@ -203,9 +203,7 @@ class property(object): def _check_default(self): ptype = self.type default = self.default - if (ptype == TYPE_BOOLEAN and - (default is not True or - default is not False)): + if (ptype == TYPE_BOOLEAN and (default not in (True, False))): raise TypeError( "default must be True or False, not %r" % (default,)) elif ptype == TYPE_PYOBJECT: diff --git a/tests/test_properties.py b/tests/test_properties.py index a82c1fb..2b9e1a1 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -233,13 +233,22 @@ class TestProperty(unittest.TestCase): self.assertRaises(TypeError, gobject.property, type='str') self.assertRaises(TypeError, gobject.property, nick=False) self.assertRaises(TypeError, gobject.property, blurb=False) - self.assertRaises(TypeError, gobject.property, type=bool, default=0) + # this never fail while bool is a subclass of int + # >>> bool.__bases__ + # (<type 'int'>,) + # self.assertRaises(TypeError, gobject.property, type=bool, default=0) + self.assertRaises(TypeError, gobject.property, type=bool, default='ciao mamma') + self.assertRaises(TypeError, gobject.property, type=bool) self.assertRaises(TypeError, gobject.property, type=GEnum) self.assertRaises(TypeError, gobject.property, type=GEnum, default=0) self.assertRaises(TypeError, gobject.property, type=object, default=0) self.assertRaises(TypeError, gobject.property, type=complex) self.assertRaises(TypeError, gobject.property, flags=-10) + def testDefaults(self): + p1 = gobject.property(type=bool, default=True) + p2 = gobject.property(type=bool, default=False) + def testNameWithUnderscore(self): class C(gobject.GObject): prop_name = gobject.property(type=int) @@ -304,3 +313,6 @@ class TestProperty(unittest.TestCase): pobj1 = pobj2.obj self.assertEqual(hash(pobj1), obj1_hash) + +if __name__ == '__main__': + unittest.main() |