summaryrefslogtreecommitdiffstats
path: root/tests/test_properties.py
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2005-07-08 15:00:54 +0000
committerJohan Dahlin <johan@src.gnome.org>2005-07-08 15:00:54 +0000
commit264ff959e8c3925ecb0b9756c1b6f807ef7115aa (patch)
tree2c008174de4c24c405de5aa2bf983115b35a76ac /tests/test_properties.py
parent6a1807bcce49bf88eb786a78478e7780801c7a36 (diff)
downloadpygobject-264ff959e8c3925ecb0b9756c1b6f807ef7115aa.tar.gz
pygobject-264ff959e8c3925ecb0b9756c1b6f807ef7115aa.tar.xz
pygobject-264ff959e8c3925ecb0b9756c1b6f807ef7115aa.zip
And unittest..
Diffstat (limited to 'tests/test_properties.py')
-rw-r--r--tests/test_properties.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_properties.py b/tests/test_properties.py
new file mode 100644
index 0000000..db620ea
--- /dev/null
+++ b/tests/test_properties.py
@@ -0,0 +1,54 @@
+
+import unittest
+
+from common import testhelper
+from gobject import GObject, GType, PARAM_READWRITE
+
+class PropertyObject(GObject):
+ __gproperties__ = {
+ 'property': (str, 'blurb', 'description',
+ 'default',
+ PARAM_READWRITE),
+ }
+ def __init__(self):
+ GObject.__init__(self)
+ self._value = 'default'
+
+ def do_get_property(self, pspec):
+ if pspec.name != 'property':
+ raise AssertionError
+ return self._value
+
+ def do_set_property(self, pspec, value):
+ if pspec.name != 'property':
+ raise AssertionError
+ self._value = value
+
+class TestProperties(unittest.TestCase):
+ def testGetSet(self):
+ obj = PropertyObject()
+ obj.props.property = "value"
+ self.assertEqual(obj.props.property, "value")
+
+ def testListWithInstance(self):
+ obj = PropertyObject()
+ self.failUnless(hasattr(obj.props, "property"))
+
+ def testListWithoutInstance(self):
+ self.failUnless(hasattr(PropertyObject.props, "property"))
+
+ def testSetNoInstance(self):
+ def set(obj):
+ obj.props.property = "foobar"
+
+ self.assertRaises(TypeError, set, PropertyObject)
+
+ def testIterator(self):
+ for obj in (PropertyObject.props, PropertyObject().props):
+ for pspec in obj:
+ gtype = GType(pspec)
+ self.assertEqual(gtype.parent.name, 'GParam')
+ self.assertEqual(pspec.name, 'property')
+
+ self.assertEqual(len(obj), 1)
+ self.assertEqual(list(obj), [pspec])