Raise a error when try to modify a read-only property.
Add get function as mandatory in QProperty constructor.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
1162a844bd
commit
6bd528978c
3 changed files with 22 additions and 6 deletions
|
|
@ -16,6 +16,16 @@ class MySize(QSize):
|
|||
class ExtQObject(QObject):
|
||||
registeredproperty = QProperty(int)
|
||||
|
||||
class MyObject(QObject):
|
||||
'''Test Property'''
|
||||
|
||||
def readPP(self):
|
||||
return 42
|
||||
|
||||
def trySetPP(self):
|
||||
self.pp = 0
|
||||
|
||||
pp = QProperty(int, readPP)
|
||||
|
||||
class PropertyCase(unittest.TestCase):
|
||||
'''Test case for QObject properties'''
|
||||
|
|
@ -115,6 +125,11 @@ class PropertyWithConstructorCase(unittest.TestCase):
|
|||
obj = QTimer(objectName='dummy')
|
||||
self.assertEqual(obj.objectName(), 'dummy')
|
||||
|
||||
def testPythonProperty(self):
|
||||
o = MyObject()
|
||||
self.assertEqual(o.pp, 42)
|
||||
o.pp = 0
|
||||
self.assertRaises(AttributeError, o.trySetPP)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue