summaryrefslogtreecommitdiff
path: root/tests/test_gobject.py
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2012-11-06 21:34:06 -0800
committerSimon Feltman <sfeltman@src.gnome.org>2012-11-07 01:57:10 -0800
commit463f660cd6bb78ae7f2ea7c70c0491e6b4744942 (patch)
treec58030a70c48c730f84b3ea7c56026da7ea16b46 /tests/test_gobject.py
parent3fcd987272a779e5ee9173a2c3a043b4b7475842 (diff)
downloadpygobject-463f660cd6bb78ae7f2ea7c70c0491e6b4744942.tar.gz
Replace GObject notify methods with introspection and python
Replace static context managers for freeze_notify and handler_block with python context managers. Remove notify, freeze_notify, thaw_notify static methods as the introspection versions work fine. https://bugzilla.gnome.org/show_bug.cgi?id=672727
Diffstat (limited to 'tests/test_gobject.py')
-rw-r--r--tests/test_gobject.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 80d0f644..99f471b9 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -271,20 +271,26 @@ class TestContextManagers(unittest.TestCase):
self.assertEqual(self.tracking, [1, 2])
self.assertEqual(self.obj.__grefcount__, 1)
- # Using the context manager the tracking list should not be affected
- # and the GObject reference count should go up.
+ pyref_count = sys.getrefcount(self.obj)
+
+ # Using the context manager the tracking list should not be affected.
+ # The GObject reference count should stay the same and the python
+ # object ref-count should go up.
with self.obj.freeze_notify():
- self.assertEqual(self.obj.__grefcount__, 2)
+ self.assertEqual(self.obj.__grefcount__, 1)
+ self.assertEqual(sys.getrefcount(self.obj), pyref_count + 1)
self.obj.props.prop = 3
self.assertEqual(self.obj.props.prop, 3)
self.assertEqual(self.tracking, [1, 2])
# After the context manager, the prop should have been modified,
- # the tracking list will be modified, and the GObject ref
+ # the tracking list will be modified, and the python object ref
# count goes back down.
+ gc.collect()
self.assertEqual(self.obj.props.prop, 3)
self.assertEqual(self.tracking, [1, 2, 3])
self.assertEqual(self.obj.__grefcount__, 1)
+ self.assertEqual(sys.getrefcount(self.obj), pyref_count)
def test_handler_block_context(self):
# Verify prop tracking list
@@ -295,10 +301,14 @@ class TestContextManagers(unittest.TestCase):
self.assertEqual(self.tracking, [1, 2])
self.assertEqual(self.obj.__grefcount__, 1)
- # Using the context manager the tracking list should not be affected
- # and the GObject reference count should go up.
+ pyref_count = sys.getrefcount(self.obj)
+
+ # Using the context manager the tracking list should not be affected.
+ # The GObject reference count should stay the same and the python
+ # object ref-count should go up.
with self.obj.handler_block(self.handler):
- self.assertEqual(self.obj.__grefcount__, 2)
+ self.assertEqual(self.obj.__grefcount__, 1)
+ self.assertEqual(sys.getrefcount(self.obj), pyref_count + 1)
self.obj.props.prop = 3
self.assertEqual(self.obj.props.prop, 3)
self.assertEqual(self.tracking, [1, 2])
@@ -306,9 +316,11 @@ class TestContextManagers(unittest.TestCase):
# After the context manager, the prop should have been modified
# the tracking list should have stayed the same and the GObject ref
# count goes back down.
+ gc.collect()
self.assertEqual(self.obj.props.prop, 3)
self.assertEqual(self.tracking, [1, 2])
self.assertEqual(self.obj.__grefcount__, 1)
+ self.assertEqual(sys.getrefcount(self.obj), pyref_count)
def test_freeze_notify_context_nested(self):
self.assertEqual(self.tracking, [])