aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtGui/qlistwidget_test.py
blob: 16c919bdcde8ba72a7db350366c33dd20c8f3c6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

import unittest

import sys
from PySide import QtGui, QtCore
from helper import UsesQApplication

class QListWidgetTest(UsesQApplication):

    def populateList(self, lst):
        o = QtCore.QObject()
        o.setObjectName("obj")

        item = QtGui.QListWidgetItem("item0")
        item.setData(QtCore.Qt.UserRole, o)
        #item._data = o
        self.assert_(sys.getrefcount(o), 3)
        self.assert_(sys.getrefcount(item), 2)
        lst.addItem(item)
        self.assert_(sys.getrefcount(item), 3)

    def checkCurrentItem(self, lst):
        item = lst.currentItem()
        self.assert_(sys.getrefcount(item), 3)

    def checkItemData(self, lst):
        item = lst.currentItem()
        o = item.data(QtCore.Qt.UserRole)
        self.assert_(sys.getrefcount(o), 4)
        self.assertEqual(o, item._data)
        self.assert_(sys.getrefcount(o), 2)

    def testConstructorWithParent(self):
        lst = QtGui.QListWidget()
        self.populateList(lst)
        self.checkCurrentItem(lst)
        i = lst.item(0)
        self.assert_(sys.getrefcount(i), 3)

        del lst
        self.assert_(sys.getrefcount(i), 2)
        del i

    def testIt(self):
        lst = QtGui.QListWidget()
        lst.show()
        slot = lambda : lst.removeItemWidget(lst.currentItem())
        lst.addItem(QtGui.QListWidgetItem("foo"))
        QtCore.QTimer.singleShot(0, slot)
        QtCore.QTimer.singleShot(0, lst.close)
        self.app.exec_()
        self.assertEqual(lst.count(), 1)

if __name__ == '__main__':
    unittest.main()