summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/QtGui/bug_1006.py50
1 files changed, 45 insertions, 5 deletions
diff --git a/tests/QtGui/bug_1006.py b/tests/QtGui/bug_1006.py
index 33afdfb..bb08bbf 100644
--- a/tests/QtGui/bug_1006.py
+++ b/tests/QtGui/bug_1006.py
@@ -1,7 +1,9 @@
import unittest
import weakref
+import sys
+
from PySide.QtCore import Qt
-from PySide.QtGui import QDialog, QLabel, QGridLayout
+from PySide.QtGui import QDialog, QLabel, QGridLayout, QHBoxLayout, QWidget
from helper import TimedQApplication
@@ -16,13 +18,15 @@ class LabelWindow(QDialog):
self._destroyCalled = False
- def replace(self):
+ def replace(self, unit):
old_item = self.test_layout.itemAtPosition(0, 0)
- ref = weakref.ref(old_item, self._destroyed)
old_label = old_item.widget()
- del old_item
+ ref = weakref.ref(old_item, self._destroyed)
self.test_layout.removeWidget(old_label)
+ unit.assertRaises(RuntimeError, old_item.widget)
+ del old_item
+
label = QLabel("Label New")
old_label.deleteLater()
label.setAlignment(Qt.AlignCenter)
@@ -35,9 +39,45 @@ class TestBug1006 (TimedQApplication):
def testLayoutItemLifeTime(self):
window = LabelWindow(None)
- window.replace()
+ window.replace(self)
self.assertTrue(window._destroyCalled)
self.app.exec_()
+ def testParentLayout(self):
+ def createLayout():
+ label = QLabel()
+ layout = QHBoxLayout()
+ layout.addWidget(label)
+
+ widget = QWidget()
+ widget.setLayout(layout)
+ return (layout, widget)
+ (layout, widget) = createLayout()
+ item = layout.itemAt(0)
+ self.assertTrue(isinstance(item.widget(), QWidget))
+
+ def testRemoveOrphanWidget(self):
+ widget = QLabel()
+ layout = QHBoxLayout()
+ layout.addWidget(widget)
+ self.assertEqual(sys.getrefcount(widget), 3)
+
+ layout.removeWidget(widget)
+ widget.setObjectName("MyWidget")
+ self.assertEqual(sys.getrefcount(widget), 2)
+
+ def testRemoveChildWidget(self):
+ parent = QLabel()
+ widget = QLabel(parent)
+ self.assertEqual(sys.getrefcount(widget), 3)
+
+ layout = QHBoxLayout()
+ layout.addWidget(widget)
+ self.assertEqual(sys.getrefcount(widget), 3)
+
+ layout.removeWidget(widget)
+ widget.setObjectName("MyWidget")
+ self.assertEqual(sys.getrefcount(widget), 3)
+
if __name__ == "__main__":
unittest.main()