From 4090ef81efcada5bd6f882e1c91cd3a699c9c034 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Fri, 9 Jul 2010 10:31:37 -0300 Subject: Restore missing function on QStandardItemModel. Created unit test. Fixes bug: #257. Reviewer: Marcelo Lira Luciano Wolf --- tests/QtGui/qstandarditemmodel_test.py | 41 ++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/QtGui/qstandarditemmodel_test.py b/tests/QtGui/qstandarditemmodel_test.py index d83d856da..6ab86dd04 100644 --- a/tests/QtGui/qstandarditemmodel_test.py +++ b/tests/QtGui/qstandarditemmodel_test.py @@ -1,7 +1,7 @@ import unittest +import sys -from PySide.QtGui import * -from PySide.QtCore import * +from PySide.QtGui import QStandardItemModel, QWidget, QStandardItem from helper import UsesQApplication @@ -21,6 +21,43 @@ class QStandardItemModelTest(UsesQApplication): # bug #227 self.model.insertRow(0) + +class QStandardItemModelRef(UsesQApplication): + def testRefCount(self): + model = QStandardItemModel(5, 5) + items = [] + for r in range(5): + row = [] + for c in range(5): + row.append(QStandardItem("%d,%d" % (r,c)) ) + self.assertEqual(sys.getrefcount(row[c]), 2) + + model.insertRow(r, row) + + for c in range(5): + ref_after = sys.getrefcount(row[c]) + # check if the ref count was incremented after insertRow + self.assertEqual(ref_after, 3) + + items.append(row) + row = None + + for r in range(3): + my_row = model.takeRow(0) + my_row = None + for c in range(5): + # only rest 1 reference + self.assertEqual(sys.getrefcount(items[r][c]), 2) + + my_i = model.item(0,0) + # ref(my_i) + parent_ref + items list ref + self.assertEqual(sys.getrefcount(my_i), 4) + + model.clear() + # ref(my_i) + self.assertEqual(sys.getrefcount(my_i), 3) + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3