blob: 372018cb37a8df15c0a509f0adfe72b3a15f979e (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import unittest
import sys
from PySide import QtGui
from PySide import QtCore
from helper import UsesQApplication
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.createToolbar()
def createToolbar(self):
pointerButton = QtGui.QToolButton()
pointerToolbar = self.addToolBar("Pointer type")
pointerToolbar.addWidget(pointerButton)
class MyButton(QtGui.QPushButton):
def __init__(self, parent=None):
QtGui.QPushButton.__init__(self)
self._called = False
def myCallback(self):
self._called = True
class TestMainWindow(UsesQApplication):
def testCreateToolbar(self):
w = MainWindow()
w.show()
QtCore.QTimer.singleShot(1000, self.app.quit)
self.app.exec_()
def testRefCountToNull(self):
w = QtGui.QMainWindow()
c = QtGui.QWidget()
self.assertEqual(sys.getrefcount(c), 2)
w.setCentralWidget(c)
self.assertEqual(sys.getrefcount(c), 3)
w.setCentralWidget(None)
self.assertEqual(sys.getrefcount(c), 2)
def testRefCountToAnother(self):
w = QtGui.QMainWindow()
c = QtGui.QWidget()
self.assertEqual(sys.getrefcount(c), 2)
w.setCentralWidget(c)
self.assertEqual(sys.getrefcount(c), 3)
c2 = QtGui.QWidget()
w.setCentralWidget(c2)
self.assertEqual(sys.getrefcount(c), 2)
self.assertEqual(sys.getrefcount(c2), 3)
def testSignalDisconect(self):
w = QtGui.QMainWindow()
b = MyButton("button")
b.clicked.connect(b.myCallback)
w.setCentralWidget(b)
b = MyButton("button")
b.clicked.connect(b.myCallback)
w.setCentralWidget(b)
b.click()
self.assertEqual(b._called, True)
if __name__ == '__main__':
unittest.main()
|