[pygobject] Add some tests for the number of python refs held at creation time



commit a59e2d58bdb3f31a4f415dbe14b7d9988ac28ce3
Author: Steve Frécinaux <code istique net>
Date:   Fri Jan 21 15:54:43 2011 +0100

    Add some tests for the number of python refs held at creation time
    
    https://bugzilla.gnome.org/show_bug.cgi?id=640184

 tests/test_gobject.py |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 9dfe166..19cc564 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -3,6 +3,7 @@
 import unittest
 
 import gobject
+import sys
 import testhelper
 
 
@@ -159,3 +160,23 @@ class TestReferenceCounting(unittest.TestCase):
 
         obj.release()
         self.assertEquals(obj.__grefcount__, 1)
+
+class A(gobject.GObject):
+    def __init__(self):
+        super(A, self).__init__()
+
+class TestPythonReferenceCounting(unittest.TestCase):
+    # Newly created instances should alwayshave two references: one for
+    # the GC, and one for the bound variable in the local scope.
+
+    def testNewInstanceHasTwoRefs(self):
+        obj = gobject.GObject()
+        self.assertEquals(sys.getrefcount(obj), 2)
+
+    def testNewInstanceHasTwoRefsUsingGObjectNew(self):
+        obj = gobject.new(gobject.GObject)
+        self.assertEquals(sys.getrefcount(obj), 2)
+
+    def testNewSubclassInstanceHasTwoRefs(self):
+        obj = A()
+        self.assertEquals(sys.getrefcount(obj), 2)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]