Created new unittest model.
Separete unittest for module.
Only run unittest for compiled modules.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
471486732b
commit
ab918abc1e
211 changed files with 241 additions and 79 deletions
58
tests/QtGui/CMakeLists.txt
Normal file
58
tests/QtGui/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
PYSIDE_TEST(add_action_test.py)
|
||||
PYSIDE_TEST(customproxywidget_test.py)
|
||||
PYSIDE_TEST(float_to_int_implicit_conversion_test.py)
|
||||
PYSIDE_TEST(grandparent_method_test.py)
|
||||
PYSIDE_TEST(hashabletype_test.py)
|
||||
PYSIDE_TEST(keep_reference_test.py)
|
||||
PYSIDE_TEST(missing_symbols_test.py)
|
||||
PYSIDE_TEST(paint_event_test.py)
|
||||
PYSIDE_TEST(parent_method_test.py)
|
||||
PYSIDE_TEST(python_properties_test.py)
|
||||
PYSIDE_TEST(qapplication_exit_segfault_test.py)
|
||||
PYSIDE_TEST(qapplication_singleton_test.py)
|
||||
PYSIDE_TEST(qapp_test.py)
|
||||
PYSIDE_TEST(qbrush_test.py)
|
||||
PYSIDE_TEST(qcolor_test.py)
|
||||
PYSIDE_TEST(qdatastream_gui_operators_test.py)
|
||||
PYSIDE_TEST(qfontdialog_test.py)
|
||||
PYSIDE_TEST(qfontmetrics_test.py)
|
||||
PYSIDE_TEST(qgraphicsitem_isblocked_test.py)
|
||||
PYSIDE_TEST(qgraphicsitem_test.py)
|
||||
PYSIDE_TEST(qgraphicsproxywidget_test.py)
|
||||
PYSIDE_TEST(qgraphicsscene_test.py)
|
||||
PYSIDE_TEST(qinputdialog_get_test.py)
|
||||
PYSIDE_TEST(qitemselection_test.py)
|
||||
PYSIDE_TEST(qlayout_ref_test.py)
|
||||
PYSIDE_TEST(qlayout_test.py)
|
||||
PYSIDE_TEST(qlcdnumber_test.py)
|
||||
PYSIDE_TEST(qlistwidgetitem_test.py)
|
||||
PYSIDE_TEST(qmainwindow_test.py)
|
||||
PYSIDE_TEST(qmatrix_test.py)
|
||||
PYSIDE_TEST(qmenuadd_test.py)
|
||||
PYSIDE_TEST(qmenu_test.py)
|
||||
PYSIDE_TEST(qobject_mi_test.py)
|
||||
PYSIDE_TEST(qpainter_test.py)
|
||||
PYSIDE_TEST(qpen_test.py)
|
||||
PYSIDE_TEST(qpixmap_test.py)
|
||||
PYSIDE_TEST(qpushbutton_test.py)
|
||||
PYSIDE_TEST(qradialgradient_test.py)
|
||||
PYSIDE_TEST(qregion_test.py)
|
||||
PYSIDE_TEST(qshortcut_test.py)
|
||||
PYSIDE_TEST(qstandarditemmodel_test.py)
|
||||
PYSIDE_TEST(qstring_qkeysequence_test.py)
|
||||
PYSIDE_TEST(qstyle_test.py)
|
||||
PYSIDE_TEST(qtableview_test.py)
|
||||
PYSIDE_TEST(qtabwidget_test.py)
|
||||
PYSIDE_TEST(qtextedit_test.py)
|
||||
PYSIDE_TEST(qtoolbar_test.py)
|
||||
PYSIDE_TEST(qtoolbox_test.py)
|
||||
PYSIDE_TEST(qvariant_test.py)
|
||||
PYSIDE_TEST(qwidget_setlayout_test.py)
|
||||
PYSIDE_TEST(qwidget_test.py TRUE) #Bug 237
|
||||
PYSIDE_TEST(reference_count_test.py)
|
||||
PYSIDE_TEST(standardpixmap_test.py)
|
||||
PYSIDE_TEST(timed_app_test.py)
|
||||
PYSIDE_TEST(virtual_protected_inheritance_test.py)
|
||||
PYSIDE_TEST(virtual_pure_override.py)
|
||||
PYSIDE_TEST(wrong_return_test.py)
|
||||
PYSIDE_TEST(x11_symbols.py)
|
||||
44
tests/QtGui/add_action_test.py
Normal file
44
tests/QtGui/add_action_test.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
'''Tests for QMenuBar.addAction(identifier, callback) calls'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import SLOT
|
||||
from PySide.QtGui import QMenuBar, QAction, QPushButton
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
|
||||
class AddActionTest(UsesQApplication):
|
||||
'''QMenuBar addAction'''
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
del self.called
|
||||
except AttributeError:
|
||||
pass
|
||||
super(AddActionTest, self).tearDown()
|
||||
|
||||
def _callback(self):
|
||||
self.called = True
|
||||
|
||||
def testBasic(self):
|
||||
'''QMenuBar.addAction(id, callback)'''
|
||||
menubar = QMenuBar()
|
||||
action = menubar.addAction("Accounts", self._callback)
|
||||
action.activate(QAction.Trigger)
|
||||
self.assert_(self.called)
|
||||
|
||||
def testWithCppSlot(self):
|
||||
'''QMenuBar.addAction(id, object, slot)'''
|
||||
menubar = QMenuBar()
|
||||
widget = QPushButton()
|
||||
widget.setCheckable(True)
|
||||
widget.setChecked(False)
|
||||
action = menubar.addAction("Accounts", widget, SLOT("toggle()"))
|
||||
action.activate(QAction.Trigger)
|
||||
self.assert_(widget.isChecked())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
33
tests/QtGui/customproxywidget_test.py
Executable file
33
tests/QtGui/customproxywidget_test.py
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
import unittest
|
||||
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtCore import Qt, QTimer
|
||||
from PySide.QtGui import QLabel, QPainter
|
||||
from PySide.QtGui import QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsProxyWidget
|
||||
|
||||
class CustomProxy(QGraphicsProxyWidget):
|
||||
def __init__(self, parent=None, wFlags=0):
|
||||
QGraphicsProxyWidget.__init__(self, parent, wFlags)
|
||||
|
||||
class CustomProxyWidgetTest(UsesQApplication):
|
||||
def testCustomProxyWidget(self):
|
||||
scene = QGraphicsScene()
|
||||
|
||||
proxy = CustomProxy(None, Qt.Window)
|
||||
widget = QLabel('Widget')
|
||||
proxy.setWidget(widget)
|
||||
proxy.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
|
||||
scene.addItem(proxy)
|
||||
scene.setSceneRect(scene.itemsBoundingRect())
|
||||
|
||||
view = QGraphicsView(scene)
|
||||
view.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform)
|
||||
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
|
||||
view.show()
|
||||
|
||||
timer = QTimer.singleShot(100, self.app.quit)
|
||||
self.app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
32
tests/QtGui/float_to_int_implicit_conversion_test.py
Normal file
32
tests/QtGui/float_to_int_implicit_conversion_test.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
'''Test cases for QImage'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QImage, qRgb
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class SetPixelFloat(UsesQApplication):
|
||||
'''Test case for calling setPixel with float as argument'''
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(SetPixelFloat, self).setUp()
|
||||
self.color = qRgb(255, 0, 0)
|
||||
self.image = QImage(200, 200, QImage.Format_RGB32)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.color
|
||||
del self.image
|
||||
super(SetPixelFloat, self).tearDown()
|
||||
|
||||
def testFloat(self):
|
||||
#QImage.setPixel(float, float, color) - Implicit conversion
|
||||
self.image.setPixel(3.14, 4.2, self.color)
|
||||
self.assertEqual(self.image.pixel(3.14, 4.2), self.color)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
23
tests/QtGui/grandparent_method_test.py
Normal file
23
tests/QtGui/grandparent_method_test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
'''Tests for calling methods further than the direct parent'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QPushButton, QWidget
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class Dummy(QPushButton):
|
||||
|
||||
def show(self):
|
||||
QWidget.show(self)
|
||||
self.called = True
|
||||
|
||||
class GrandParentMethod(UsesQApplication):
|
||||
def testMethod(self):
|
||||
obj = Dummy()
|
||||
obj.show()
|
||||
self.assert_(obj.called)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
18
tests/QtGui/hashabletype_test.py
Normal file
18
tests/QtGui/hashabletype_test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'''Test cases for __hash__'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QTreeWidgetItem
|
||||
from helper import UsesQApplication
|
||||
|
||||
class HashableTest(UsesQApplication):
|
||||
|
||||
def testQTreeWidgetItemHash(self):
|
||||
h = {}
|
||||
obj = QTreeWidgetItem()
|
||||
h[obj] = 2
|
||||
self.assert_(h.get(obj), 2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
75
tests/QtGui/keep_reference_test.py
Executable file
75
tests/QtGui/keep_reference_test.py
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import unittest
|
||||
|
||||
from sys import getrefcount
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtCore import QAbstractTableModel, QVariant
|
||||
from PySide.QtGui import QTableView
|
||||
|
||||
class TestModel(QAbstractTableModel):
|
||||
def __init__(self, parent=None):
|
||||
QAbstractTableModel.__init__(self, parent)
|
||||
def rowCount(self, parent):
|
||||
return 0
|
||||
def columnCount(self, parent):
|
||||
return 0
|
||||
def data(self, index, role):
|
||||
return QVariant()
|
||||
|
||||
class KeepReferenceTest(UsesQApplication):
|
||||
|
||||
def testModelWithoutParent(self):
|
||||
view = QTableView()
|
||||
model = TestModel()
|
||||
view.setModel(model)
|
||||
samemodel = view.model()
|
||||
self.assertEqual(model, samemodel)
|
||||
|
||||
def testModelWithParent(self):
|
||||
view = QTableView()
|
||||
model = TestModel(self.app)
|
||||
view.setModel(model)
|
||||
samemodel = view.model()
|
||||
self.assertEqual(model, samemodel)
|
||||
|
||||
def testReferenceCounting(self):
|
||||
'''Tests reference count of model object referred by view objects.'''
|
||||
model1 = TestModel()
|
||||
refcount1 = getrefcount(model1)
|
||||
view1 = QTableView()
|
||||
view1.setModel(model1)
|
||||
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
|
||||
|
||||
view2 = QTableView()
|
||||
view2.setModel(model1)
|
||||
self.assertEqual(getrefcount(view2.model()), refcount1 + 2)
|
||||
|
||||
model2 = TestModel()
|
||||
view2.setModel(model2)
|
||||
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
|
||||
|
||||
def testReferenceCountingWhenDeletingReferrer(self):
|
||||
'''Tests reference count of model object referred by deceased view object.'''
|
||||
model = TestModel()
|
||||
refcount1 = getrefcount(model)
|
||||
view = QTableView()
|
||||
view.setModel(model)
|
||||
self.assertEqual(getrefcount(view.model()), refcount1 + 1)
|
||||
|
||||
del view
|
||||
self.assertEqual(getrefcount(model), refcount1)
|
||||
|
||||
def testReferreedObjectSurvivalAfterContextEnd(self):
|
||||
'''Model object assigned to a view object must survive after getting out of context.'''
|
||||
def createModelAndSetToView(view):
|
||||
model = TestModel()
|
||||
model.setObjectName('created model')
|
||||
view.setModel(model)
|
||||
view = QTableView()
|
||||
createModelAndSetToView(view)
|
||||
model = view.model()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
29
tests/QtGui/missing_symbols_test.py
Normal file
29
tests/QtGui/missing_symbols_test.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
'''(Very) Simple test case for missing names from QtGui'''
|
||||
|
||||
import unittest
|
||||
from PySide import QtGui
|
||||
|
||||
class MissingClasses(unittest.TestCase):
|
||||
def testQDrag(self): # Bug 222
|
||||
getattr(QtGui, 'QDrag')
|
||||
|
||||
def testQDropEvent(self): # Bug 255
|
||||
getattr(QtGui, 'QDropEvent')
|
||||
|
||||
class MissingMembers(unittest.TestCase):
|
||||
|
||||
def testQFontMetricsSize(self): # Bug 223
|
||||
QtGui.QFontMetrics.size
|
||||
|
||||
def testQLayoutSetSpacing(self): # Bug 231
|
||||
QtGui.QLayout.setSpacing
|
||||
|
||||
def testQImageLoad(self): # Bug 257
|
||||
QtGui.QImage.load
|
||||
|
||||
def testQStandardItemModelinsertRow(self): # Bug 227
|
||||
QtGui.QStandardItemModel.insertRow
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
71
tests/QtGui/paint_event_test.py
Normal file
71
tests/QtGui/paint_event_test.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
'''Test paint event override in python'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QTimerEvent
|
||||
from PySide.QtGui import QApplication, QWidget
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class MyWidget(QWidget):
|
||||
'''Sample widget'''
|
||||
|
||||
def __init__(self, app=None):
|
||||
#Creates a new widget
|
||||
if app is None:
|
||||
app = QApplication([])
|
||||
|
||||
super(MyWidget, self).__init__()
|
||||
self.app = app
|
||||
self.runs = 0
|
||||
self.max_runs = 5
|
||||
self.paint_event_called = False
|
||||
|
||||
def timerEvent(self, event):
|
||||
#Timer event method
|
||||
self.runs += 1
|
||||
|
||||
if self.runs == self.max_runs:
|
||||
self.app.quit()
|
||||
|
||||
if not isinstance(event, QTimerEvent):
|
||||
raise TypeError('Invalid event type. Must be QTimerEvent')
|
||||
|
||||
def paintEvent(self, event):
|
||||
#Empty paint event method
|
||||
# XXX: should be using super here, but somehow PyQt4
|
||||
# complains about paintEvent not present in super
|
||||
QWidget.paintEvent(self, event)
|
||||
self.paint_event_called = True
|
||||
|
||||
|
||||
class PaintEventOverride(UsesQApplication):
|
||||
'''Test case for overriding QWidget.paintEvent'''
|
||||
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(PaintEventOverride, self).setUp()
|
||||
self.widget = MyWidget(self.app)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.widget
|
||||
super(PaintEventOverride, self).tearDown()
|
||||
|
||||
def testPaintEvent(self):
|
||||
#Test QWidget.paintEvent override
|
||||
timer_id = self.widget.startTimer(100)
|
||||
self.widget.show()
|
||||
self.app.exec_()
|
||||
|
||||
self.widget.killTimer(timer_id)
|
||||
|
||||
self.assert_(self.widget.paint_event_called)
|
||||
self.assertEqual(self.widget.runs, 5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
25
tests/QtGui/parent_method_test.py
Normal file
25
tests/QtGui/parent_method_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QObject, QTimer, QThread
|
||||
from PySide.QtGui import *
|
||||
|
||||
class Foo(QTableView):
|
||||
def __init__(self, parent=None):
|
||||
QTableView.__init__(self, parent)
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class TestParentType(UsesQApplication):
|
||||
|
||||
def testParentType(self):
|
||||
# Test the problem with calling QObject.parent from a QWidget
|
||||
# when the parent is a python class derived from a QWidget-derived
|
||||
# class. The method was returning the last C++ class in the hierarchy
|
||||
parent = Foo()
|
||||
w2 = QWidget(parent)
|
||||
self.assert_(isinstance(w2.parentWidget(), Foo))
|
||||
self.assert_(isinstance(w2.parent(), Foo))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
15
tests/QtGui/python_properties_test.py
Normal file
15
tests/QtGui/python_properties_test.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import unittest
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
class Properties(unittest.TestCase):
|
||||
|
||||
def testStaticProperty(self):
|
||||
self.assertEqual(QtGui.QGraphicsItem.UserType, 65536)
|
||||
|
||||
def testInstanceProperty(self):
|
||||
p = QtGui.QStyleOptionViewItemV3()
|
||||
self.assert_(isinstance(p.locale, QtCore.QLocale))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
17
tests/QtGui/qapp_test.py
Normal file
17
tests/QtGui/qapp_test.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
''' Test the presence of qApp Macro'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
class QAppPresence(unittest.TestCase):
|
||||
|
||||
def testQApp(self):
|
||||
#QtGui.qApp variable is instance of QApplication
|
||||
self.assert_(isinstance(QtGui.qApp, QtGui.QApplication))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QtGui.QApplication([])
|
||||
unittest.main()
|
||||
17
tests/QtGui/qapplication_exit_segfault_test.py
Normal file
17
tests/QtGui/qapplication_exit_segfault_test.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide.QtGui import QApplication, QPushButton, QWidget, QSpinBox
|
||||
|
||||
class QApplicationDelete(unittest.TestCase):
|
||||
'''Test for segfault when deleting a QApplication before a QWidget'''
|
||||
|
||||
def testQPushButton(self):
|
||||
#QApplication deleted before QPushButton
|
||||
a = QApplication([])
|
||||
b = QPushButton('aaaa')
|
||||
del a
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
12
tests/QtGui/qapplication_singleton_test.py
Normal file
12
tests/QtGui/qapplication_singleton_test.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QApplication
|
||||
|
||||
class TestSingleton(unittest.TestCase):
|
||||
def testBasic(self):
|
||||
a = QApplication([])
|
||||
self.assertRaises(RuntimeError, QApplication, [])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
24
tests/QtGui/qbrush_test.py
Normal file
24
tests/QtGui/qbrush_test.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
'''Test cases for QBrush'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import Qt
|
||||
from PySide.QtGui import QApplication, QColor, QBrush
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class Constructor(UsesQApplication):
|
||||
'''Test case for constructor of QBrush'''
|
||||
|
||||
def testQColor(self):
|
||||
#QBrush(QColor) constructor
|
||||
color = QColor('black')
|
||||
obj = QBrush(color)
|
||||
self.assertEqual(obj.color(), color)
|
||||
|
||||
obj = QBrush(Qt.blue)
|
||||
self.assertEqual(obj.color(), Qt.blue)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
68
tests/QtGui/qcolor_test.py
Normal file
68
tests/QtGui/qcolor_test.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
import unittest
|
||||
import colorsys
|
||||
|
||||
from PySide.QtCore import Qt
|
||||
from PySide.QtGui import QColor
|
||||
|
||||
|
||||
class QColorGetTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.color = QColor(20, 40, 60, 80)
|
||||
|
||||
def testGetRgb(self):
|
||||
self.assertEqual(self.color.getRgb(), (20, 40, 60, 80))
|
||||
|
||||
def testGetRgbF(self):
|
||||
self.assertEqual(self.color.getRgbF(), (20.0/255, 40.0/255, 60.0/255, 80.0/255))
|
||||
|
||||
def testGetHsl(self):
|
||||
self.assertEqual(self.color.getHsl(), (210, 128, 40, self.color.alpha()))
|
||||
|
||||
def testGetHslF(self):
|
||||
hls = colorsys.rgb_to_hls(20.0/255, 40.0/255, 60.0/255)
|
||||
hsla = hls[0], hls[2], hls[1], self.color.alphaF()
|
||||
for x, y in zip(self.color.getHslF(), hsla): # Due to rounding problems
|
||||
self.assert_(x - y < 1/100000.0)
|
||||
|
||||
def testGetHsv(self):
|
||||
hsv = colorsys.rgb_to_hsv(20.0/255, 40.0/255, 60.0/255)
|
||||
hsva = int(hsv[0]*360.0), int(hsv[1]*255), int(hsv[2]*256), self.color.alpha()
|
||||
self.assertEqual(self.color.getHsv(), hsva)
|
||||
|
||||
def testGetHsvF(self):
|
||||
hsv = colorsys.rgb_to_hsv(20.0/255, 40.0/255, 60.0/255)
|
||||
hsva = hsv[0], hsv[1], hsv[2], self.color.alphaF()
|
||||
self.assertEqual(self.color.getHsvF(), hsva)
|
||||
|
||||
def testGetCmyk(self): # not supported by colorsys
|
||||
self.assertEqual(self.color.getCmyk(), (170, 85, 0, 195, 80))
|
||||
|
||||
def testGetCmykF(self): # not supported by colorsys
|
||||
for x, y in zip(self.color.getCmykF(), (170/255.0, 85/255.0, 0, 195/255.0, 80/255.0)):
|
||||
self.assert_(x - y < 1/10000.0)
|
||||
|
||||
|
||||
class QColorQRgbConstructor(unittest.TestCase):
|
||||
'''QColor(QRgb) constructor'''
|
||||
# Affected by bug #170 - QColor(QVariant) coming before QColor(uint)
|
||||
# in overload sorting
|
||||
|
||||
def testBasic(self):
|
||||
'''QColor(QRgb)'''
|
||||
color = QColor(255, 0, 0)
|
||||
#QRgb format #AARRGGBB
|
||||
rgb = 0x00FF0000
|
||||
self.assertEqual(QColor(rgb), color)
|
||||
|
||||
|
||||
class QColorEqualGlobalColor(unittest.TestCase):
|
||||
|
||||
def testEqualGlobalColor(self):
|
||||
'''QColor == Qt::GlobalColor'''
|
||||
self.assertEqual(QColor(255, 0, 0), Qt.red)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
35
tests/QtGui/qdatastream_gui_operators_test.py
Normal file
35
tests/QtGui/qdatastream_gui_operators_test.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide.QtCore import QDataStream, QByteArray, QIODevice, Qt
|
||||
from PySide.QtGui import QPixmap, QColor
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QPixmapQDatastream(UsesQApplication):
|
||||
'''QDataStream <<>> QPixmap'''
|
||||
|
||||
def setUp(self):
|
||||
super(QPixmapQDatastream, self).setUp()
|
||||
self.source_pixmap = QPixmap(100, 100)
|
||||
self.source_pixmap.fill(Qt.red)
|
||||
self.output_pixmap = QPixmap()
|
||||
self.buffer = QByteArray()
|
||||
self.read_stream = QDataStream(self.buffer, QIODevice.ReadOnly)
|
||||
self.write_stream = QDataStream(self.buffer, QIODevice.WriteOnly)
|
||||
|
||||
def testStream(self):
|
||||
self.write_stream << self.source_pixmap
|
||||
|
||||
self.read_stream >> self.output_pixmap
|
||||
|
||||
image = self.output_pixmap.toImage()
|
||||
pixel = image.pixel(10,10)
|
||||
self.assertEqual(pixel, QColor(Qt.red).rgba())
|
||||
self.assertEqual(self.source_pixmap.toImage(), self.output_pixmap.toImage())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
22
tests/QtGui/qfontdialog_test.py
Normal file
22
tests/QtGui/qfontdialog_test.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide import QtGui
|
||||
from PySide import QtCore
|
||||
|
||||
from helper import TimedQApplication
|
||||
|
||||
class TestFontDialog(TimedQApplication):
|
||||
|
||||
def testGetFont(self):
|
||||
QtGui.QFontDialog.getFont()
|
||||
|
||||
def testGetFontQDialog(self):
|
||||
QtGui.QFontDialog.getFont(QtGui.QFont("FreeSans",10))
|
||||
|
||||
def testGetFontQDialogQString(self):
|
||||
QtGui.QFontDialog.getFont(QtGui.QFont("FreeSans",10), None, "Select font")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
189
tests/QtGui/qfontmetrics_test.py
Normal file
189
tests/QtGui/qfontmetrics_test.py
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
|
||||
'''Tests for inject codes and modifications on QFontMetrics
|
||||
and QFontMetricsF'''
|
||||
|
||||
import unittest
|
||||
from PySide.QtGui import QFont, QFontMetrics, QFontMetricsF
|
||||
from PySide.QtCore import QRect, QRectF, Qt, QSize, QSizeF
|
||||
from helper import UsesQApplication
|
||||
|
||||
|
||||
class QFontMetricsTest(UsesQApplication):
|
||||
'''Base class for QFontMetrics tests'''
|
||||
|
||||
def setUp(self):
|
||||
super(QFontMetricsTest, self).setUp()
|
||||
self.font = QFont()
|
||||
self.metrics = QFontMetrics(self.font)
|
||||
|
||||
def tearDown(self):
|
||||
del self.metrics
|
||||
del self.font
|
||||
super(QFontMetricsTest, self).tearDown()
|
||||
|
||||
|
||||
class BoundingRectTest(QFontMetricsTest):
|
||||
'''Tests for QFontMetrics.boundingRect inject code'''
|
||||
|
||||
def testIntDefault(self):
|
||||
'''QFontMetrics.boundingRect(int, int, int, int, ...) - default args'''
|
||||
rect = self.metrics.boundingRect(0, 0, 0, 0,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT')
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testIntWithArg(self):
|
||||
'''QFontMetrics.boundingRect(int, int, int, int, ...) - single arg'''
|
||||
rect = self.metrics.boundingRect(0, 0, 0, 0,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 2)
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testIntWithFull(self):
|
||||
'''QFontMetrics.boundingRect(int, int, int, int, ...) - all argss'''
|
||||
rect = self.metrics.boundingRect(0, 0, 0, 0,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, [1, 2, 3, 4, 5])
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testIntTypeError(self):
|
||||
'''QFontMetrics.boundingRect(int, int, int, int, ...) - type error'''
|
||||
self.assertRaises(TypeError, self.metrics.boundingRect, 0, 0, 0, 0,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, ['aaaa', 'ase'])
|
||||
|
||||
def testQRectDefault(self):
|
||||
'''QFontMetrics.boundingRect(QRect, ...) - default args'''
|
||||
arg = QRect(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT')
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testQRectWithArg(self):
|
||||
'''QFontMetrics.boundingRect(QRect, ...) - only tabstops'''
|
||||
arg = QRect(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 2)
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testQRectWithFull(self):
|
||||
'''QFontMetrics.boundingRect(QRect, ...) - all arguments'''
|
||||
arg = QRect(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20,
|
||||
[1, 2, 3, 4, 5])
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testQRectTypeError(self):
|
||||
'''QFontMetrics.boundingRect(QRect, ...) - type error'''
|
||||
arg = QRect(0, 0, 100, 200)
|
||||
self.assertRaises(TypeError, self.metrics.boundingRect, arg,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, ['aaaa', 'ase'])
|
||||
|
||||
|
||||
class SizeTest(QFontMetricsTest):
|
||||
'''Tests for QFontMetrics.size inject code'''
|
||||
|
||||
def testDefault(self):
|
||||
'''QFontMetrics.size - default arguments'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT')
|
||||
self.assert_(isinstance(size, QSize))
|
||||
|
||||
def testWithTabStops(self):
|
||||
'''QFontMetrics.size - only tabstops'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT', 2)
|
||||
self.assert_(isinstance(size, QSize))
|
||||
|
||||
def testFull(self):
|
||||
'''QFontMetrics.size - all arguments'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT', 2, [1, 2, 3, 4])
|
||||
self.assert_(isinstance(size, QSize))
|
||||
|
||||
def testTypeError(self):
|
||||
'''QFontMetrics.size - type error'''
|
||||
self.assertRaises(TypeError, self.metrics.size,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, ['aaaa', 'ase'])
|
||||
|
||||
|
||||
class QFontMetricsFTest(UsesQApplication):
|
||||
'''Base class for QFontMetrics tests'''
|
||||
|
||||
def setUp(self):
|
||||
super(QFontMetricsFTest, self).setUp()
|
||||
self.font = QFont()
|
||||
self.metrics = QFontMetricsF(self.font)
|
||||
|
||||
def tearDown(self):
|
||||
del self.metrics
|
||||
del self.font
|
||||
super(QFontMetricsFTest, self).tearDown()
|
||||
|
||||
|
||||
class FBoundingRectTest(QFontMetricsFTest):
|
||||
'''Tests for QFontMetricsF.boundingRect inject code'''
|
||||
|
||||
def testQRectDefault(self):
|
||||
'''QFontMetricsF.boundingRect(QRectF, ...) - default args'''
|
||||
arg = QRectF(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT')
|
||||
self.assert_(isinstance(rect, QRectF))
|
||||
|
||||
def testQRectWithArg(self):
|
||||
'''QFontMetricsF.boundingRect(QRectF, ...) - only tabstops'''
|
||||
arg = QRectF(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 2)
|
||||
self.assert_(isinstance(rect, QRectF))
|
||||
|
||||
def testQRectWithFull(self):
|
||||
'''QFontMetricsF.boundingRect(QRectF, ...) - all arguments'''
|
||||
arg = QRectF(0, 0, 100, 200)
|
||||
rect = self.metrics.boundingRect(arg, Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20,
|
||||
[1, 2, 3, 4, 5])
|
||||
self.assert_(isinstance(rect, QRectF))
|
||||
|
||||
def testQRectTypeError(self):
|
||||
'''QFontMetricsF.boundingRect(QRectF, ...) - type error'''
|
||||
arg = QRectF(0, 0, 100, 200)
|
||||
self.assertRaises(TypeError, self.metrics.boundingRect, arg,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, ['aaaa', 'ase'])
|
||||
|
||||
|
||||
class FSizeTest(QFontMetricsFTest):
|
||||
'''Tests for QFontMetricsF.size inject code'''
|
||||
|
||||
def testDefault(self):
|
||||
'''QFontMetricsF.size - default arguments'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT')
|
||||
self.assert_(isinstance(size, QSizeF))
|
||||
|
||||
def testWithTabStops(self):
|
||||
'''QFontMetricsF.size - only tabstops'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT', 2)
|
||||
self.assert_(isinstance(size, QSizeF))
|
||||
|
||||
def testFull(self):
|
||||
'''QFontMetricsF.size - all arguments'''
|
||||
size = self.metrics.size(Qt.TextExpandTabs | Qt.TextSingleLine,
|
||||
'PySide by INdT', 2, [1, 2, 3, 4])
|
||||
self.assert_(isinstance(size, QSizeF))
|
||||
|
||||
def testTypeError(self):
|
||||
'''QFontMetricsF.size - type error'''
|
||||
self.assertRaises(TypeError, self.metrics.size,
|
||||
Qt.TextExpandTabs | Qt.AlignLeft,
|
||||
'PySide by INdT', 20, ['aaaa', 'ase'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
29
tests/QtGui/qgraphicsitem_isblocked_test.py
Executable file
29
tests/QtGui/qgraphicsitem_isblocked_test.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide import QtCore
|
||||
from PySide import QtGui
|
||||
from helper import UsesQApplication
|
||||
|
||||
class Item(QtGui.QGraphicsItem):
|
||||
|
||||
def __init__(self):
|
||||
QtGui.QGraphicsItem.__init__(self)
|
||||
|
||||
def boundingRect(self):
|
||||
return QtCore.QRectF(0, 0, 100, 100)
|
||||
|
||||
def paint(self, painter, option, widget):
|
||||
painter.setBrush(QtGui.QColor(255, 255, 255))
|
||||
painter.drawRect(0, 0, 100, 100)
|
||||
|
||||
|
||||
class QGraphicsViewIsBlockedTest(UsesQApplication):
|
||||
|
||||
def testIsBlockedByModalPanel(self):
|
||||
(first, second) = Item().isBlockedByModalPanel()
|
||||
self.assertFalse(first)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
35
tests/QtGui/qgraphicsitem_test.py
Normal file
35
tests/QtGui/qgraphicsitem_test.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
''' Test cases related to QGraphicsItem and subclasses'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QGraphicsScene, QPolygonF, QColor, QBrush
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QColorOnSetBrush(UsesQApplication):
|
||||
'''Test case for passing a QColor directly to setBrush'''
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(QColorOnSetBrush, self).setUp()
|
||||
|
||||
self.scene = QGraphicsScene()
|
||||
poly = QPolygonF()
|
||||
self.item = self.scene.addPolygon(poly)
|
||||
self.color = QColor('black')
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.color
|
||||
del self.item
|
||||
del self.scene
|
||||
super(QColorOnSetBrush, self).tearDown()
|
||||
|
||||
def testQColor(self):
|
||||
#QGraphicsAbstractShapeItem.setBrush(QColor)
|
||||
self.item.setBrush(self.color)
|
||||
self.assertEqual(QBrush(self.color), self.item.brush())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
29
tests/QtGui/qgraphicsproxywidget_test.py
Executable file
29
tests/QtGui/qgraphicsproxywidget_test.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
import unittest
|
||||
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtCore import Qt, QTimer
|
||||
from PySide.QtGui import QLabel, QPainter
|
||||
from PySide.QtGui import QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsProxyWidget
|
||||
|
||||
class QGraphicsProxyWidgetTest(UsesQApplication):
|
||||
def testQGraphicsProxyWidget(self):
|
||||
scene = QGraphicsScene()
|
||||
|
||||
proxy = QGraphicsProxyWidget(None, Qt.Window)
|
||||
widget = QLabel('Widget')
|
||||
proxy.setWidget(widget)
|
||||
proxy.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
|
||||
scene.addItem(proxy)
|
||||
scene.setSceneRect(scene.itemsBoundingRect())
|
||||
|
||||
view = QGraphicsView(scene)
|
||||
view.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform)
|
||||
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
|
||||
view.show()
|
||||
|
||||
timer = QTimer.singleShot(100, self.app.quit)
|
||||
self.app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
152
tests/QtGui/qgraphicsscene_test.py
Normal file
152
tests/QtGui/qgraphicsscene_test.py
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
|
||||
'''Basic test cases for QGraphicsScene'''
|
||||
|
||||
import unittest
|
||||
import gc
|
||||
|
||||
from PySide.QtCore import QPointF
|
||||
from PySide.QtGui import QApplication, QPushButton, QPolygonF, QPixmap
|
||||
from PySide.QtGui import QGraphicsScene, QPainterPath
|
||||
from PySide.QtGui import QGraphicsEllipseItem, QGraphicsLineItem
|
||||
from PySide.QtGui import QGraphicsPathItem, QGraphicsPixmapItem
|
||||
from PySide.QtGui import QGraphicsPolygonItem, QGraphicsRectItem
|
||||
from PySide.QtGui import QGraphicsSimpleTextItem, QGraphicsTextItem
|
||||
from PySide.QtGui import QGraphicsProxyWidget
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class Constructor(unittest.TestCase):
|
||||
'''QGraphicsScene constructor'''
|
||||
|
||||
def testConstructor(self):
|
||||
#QGraphicsScene constructor
|
||||
obj = QGraphicsScene()
|
||||
self.assert_(isinstance(obj, QGraphicsScene))
|
||||
|
||||
|
||||
class ConstructorWithRect(unittest.TestCase):
|
||||
'''QGraphicsScene qrect constructor and related sizes'''
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
# PyQt4 doesn't accept a QRect as argument to constructor
|
||||
self.scene = QGraphicsScene(0, 200, 150, 175)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.scene
|
||||
|
||||
def testHeight(self):
|
||||
#QGraphicsScene.height()
|
||||
self.assertEqual(self.scene.height(), 175)
|
||||
|
||||
def testWidth(self):
|
||||
#QGraphicsScene.width()
|
||||
self.assertEqual(self.scene.width(), 150)
|
||||
|
||||
|
||||
class AddItem(UsesQApplication):
|
||||
'''Tests for QGraphicsScene.add*'''
|
||||
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(AddItem, self).setUp()
|
||||
self.scene = QGraphicsScene()
|
||||
# While the scene does not inherits from QWidget, requires
|
||||
# an application to make the internals work.
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.scene
|
||||
super(AddItem, self).tearDown()
|
||||
|
||||
def testEllipse(self):
|
||||
#QGraphicsScene.addEllipse
|
||||
item = self.scene.addEllipse(100, 100, 100, 100)
|
||||
self.assert_(isinstance(item, QGraphicsEllipseItem))
|
||||
|
||||
def testLine(self):
|
||||
#QGraphicsScene.addLine
|
||||
item = self.scene.addLine(100, 100, 200, 200)
|
||||
self.assert_(isinstance(item, QGraphicsLineItem))
|
||||
|
||||
def testPath(self):
|
||||
#QGraphicsScene.addPath
|
||||
item = self.scene.addPath(QPainterPath())
|
||||
self.assert_(isinstance(item, QGraphicsPathItem))
|
||||
|
||||
def testPixmap(self):
|
||||
#QGraphicsScene.addPixmap
|
||||
item = self.scene.addPixmap(QPixmap())
|
||||
self.assert_(isinstance(item, QGraphicsPixmapItem))
|
||||
|
||||
def testPolygon(self):
|
||||
#QGraphicsScene.addPolygon
|
||||
points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)]
|
||||
item = self.scene.addPolygon(QPolygonF(points))
|
||||
self.assert_(isinstance(item, QGraphicsPolygonItem))
|
||||
|
||||
def testRect(self):
|
||||
#QGraphicsScene.addRect
|
||||
item = self.scene.addRect(100, 100, 100, 100)
|
||||
self.assert_(isinstance(item, QGraphicsRectItem))
|
||||
|
||||
def testSimpleText(self):
|
||||
#QGraphicsScene.addSimpleText
|
||||
item = self.scene.addSimpleText('Monty Python 42')
|
||||
self.assert_(isinstance(item, QGraphicsSimpleTextItem))
|
||||
|
||||
def testText(self):
|
||||
#QGraphicsScene.addText
|
||||
item = self.scene.addText('Monty Python 42')
|
||||
self.assert_(isinstance(item, QGraphicsTextItem))
|
||||
|
||||
def testWidget(self):
|
||||
#QGraphicsScene.addWidget
|
||||
# XXX: printing some X11 error when using under PyQt4
|
||||
item = self.scene.addWidget(QPushButton())
|
||||
self.assert_(isinstance(item, QGraphicsProxyWidget))
|
||||
|
||||
|
||||
class ItemRetrieve(UsesQApplication):
|
||||
'''Tests for QGraphicsScene item retrieval methods'''
|
||||
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(ItemRetrieve, self).setUp()
|
||||
self.scene = QGraphicsScene()
|
||||
|
||||
self.topleft = QGraphicsRectItem(0, 0, 100, 100)
|
||||
self.topright = QGraphicsRectItem(100, 0, 100, 100)
|
||||
self.bottomleft = QGraphicsRectItem(0, 100, 100, 100)
|
||||
self.bottomright = QGraphicsRectItem(100, 100, 100, 100)
|
||||
|
||||
self.items = [self.topleft, self.topright, self.bottomleft,
|
||||
self.bottomright]
|
||||
|
||||
for item in self.items:
|
||||
self.scene.addItem(item)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.scene
|
||||
super(ItemRetrieve, self).tearDown()
|
||||
|
||||
def testItems(self):
|
||||
#QGraphicsScene.items()
|
||||
items = self.scene.items()
|
||||
self.assertEqual(items.sort(), self.items.sort())
|
||||
|
||||
def testItemAt(self):
|
||||
#QGraphicsScene.itemAt()
|
||||
self.assertEqual(self.scene.itemAt(50, 50), self.topleft)
|
||||
self.assertEqual(self.scene.itemAt(150, 50), self.topright)
|
||||
self.assertEqual(self.scene.itemAt(50, 150), self.bottomleft)
|
||||
self.assertEqual(self.scene.itemAt(150, 150), self.bottomright)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
27
tests/QtGui/qinputdialog_get_test.py
Normal file
27
tests/QtGui/qinputdialog_get_test.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import unittest
|
||||
|
||||
from PySide import QtCore, QtGui
|
||||
from helper import UsesQApplication, TimedQApplication
|
||||
|
||||
class TestInputDialog(TimedQApplication):
|
||||
|
||||
def testGetDouble(self):
|
||||
self.assertEquals(QtGui.QInputDialog.getDouble(None, "title", "label"), (0.0, False))
|
||||
|
||||
def testGetInt(self):
|
||||
self.assertEquals(QtGui.QInputDialog.getInt(None, "title", "label"), (0, False))
|
||||
|
||||
def testGetInteger(self):
|
||||
self.assertEquals(QtGui.QInputDialog.getInteger(None, "title", "label"), (0, False))
|
||||
|
||||
def testGetItem(self):
|
||||
(item, bool) = QtGui.QInputDialog.getItem(None, "title", "label", QtCore.QStringList(["1", "2", "3"]))
|
||||
self.assertEquals(str(item), "1")
|
||||
|
||||
def testGetText(self):
|
||||
(text, bool) = QtGui.QInputDialog.getText(None, "title", "label")
|
||||
self.assertEquals(str(text),"")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
18
tests/QtGui/qitemselection_test.py
Normal file
18
tests/QtGui/qitemselection_test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import unittest
|
||||
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtGui import QItemSelection, QStandardItemModel
|
||||
|
||||
class QItemSelectionTest(UsesQApplication):
|
||||
def testLen(self):
|
||||
model = QStandardItemModel(2, 2)
|
||||
model.insertRow(0)
|
||||
model.insertRow(1)
|
||||
model.insertColumn(0)
|
||||
model.insertColumn(1)
|
||||
selection = QItemSelection(model.index(0,0), model.index(1,1))
|
||||
self.assertEqual(len(selection), 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
112
tests/QtGui/qlayout_ref_test.py
Normal file
112
tests/QtGui/qlayout_ref_test.py
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
|
||||
'''Test cases for QLayout handling of child widgets references'''
|
||||
|
||||
import unittest
|
||||
from sys import getrefcount
|
||||
|
||||
from PySide.QtGui import QHBoxLayout, QVBoxLayout, QGridLayout, QWidget
|
||||
from PySide.QtGui import QStackedLayout, QFormLayout
|
||||
from PySide.QtGui import QApplication, QPushButton, QLabel
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class SaveReference(UsesQApplication):
|
||||
'''Test case to check if QLayout-derived classes increment the refcount
|
||||
of widgets passed to addWidget()'''
|
||||
|
||||
# Adding here as nose can't see the qapplication attrib we inherit
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(SaveReference, self).setUp()
|
||||
self.widget1 = QPushButton('click me')
|
||||
self.widget2 = QLabel('aaa')
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.widget2
|
||||
del self.widget1
|
||||
super(SaveReference, self).tearDown()
|
||||
|
||||
def checkLayoutReference(self, layout):
|
||||
#Checks the reference cound handling of layout.addWidget
|
||||
self.assertEqual(getrefcount(self.widget1), 2)
|
||||
layout.addWidget(self.widget1)
|
||||
self.assertEqual(getrefcount(self.widget1), 3)
|
||||
|
||||
self.assertEqual(getrefcount(self.widget2), 2)
|
||||
layout.addWidget(self.widget2)
|
||||
self.assertEqual(getrefcount(self.widget2), 3)
|
||||
|
||||
# Check if doesn't mess around with previous widget refcount
|
||||
self.assertEqual(getrefcount(self.widget1), 3)
|
||||
|
||||
def testMoveLayout(self):
|
||||
l = QHBoxLayout()
|
||||
self.assertEqual(getrefcount(self.widget1), 2)
|
||||
l.addWidget(self.widget1)
|
||||
self.assertEqual(getrefcount(self.widget1), 2)
|
||||
|
||||
w = QWidget()
|
||||
w.setLayout(l)
|
||||
self.assertEqual(getrefcount(self.widget1), 3)
|
||||
|
||||
|
||||
def testHBoxReference(self):
|
||||
#QHBoxLayout.addWidget reference count
|
||||
w = QWidget()
|
||||
self.checkLayoutReference(QHBoxLayout(w))
|
||||
|
||||
def testVBoxReference(self):
|
||||
#QVBoxLayout.addWidget reference count
|
||||
w = QWidget()
|
||||
self.checkLayoutReference(QVBoxLayout(w))
|
||||
|
||||
def testGridReference(self):
|
||||
#QGridLayout.addWidget reference count
|
||||
w = QWidget()
|
||||
self.checkLayoutReference(QGridLayout(w))
|
||||
|
||||
def testFormReference(self):
|
||||
#QFormLayout.addWidget reference count
|
||||
w = QWidget()
|
||||
self.checkLayoutReference(QFormLayout(w))
|
||||
|
||||
def testStackedReference(self):
|
||||
#QStackedLayout.addWidget reference count
|
||||
w = QWidget()
|
||||
self.checkLayoutReference(QStackedLayout(w))
|
||||
|
||||
class MultipleAdd(UsesQApplication):
|
||||
'''Test case to check if refcount is incremented only once when multiple
|
||||
calls to addWidget are made with the same widget'''
|
||||
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(MultipleAdd, self).setUp()
|
||||
self.widget = QPushButton('click me')
|
||||
self.win = QWidget()
|
||||
self.layout = QHBoxLayout(self.win)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.widget
|
||||
del self.layout
|
||||
del self.win
|
||||
super(MultipleAdd, self).tearDown()
|
||||
|
||||
def testRefCount(self):
|
||||
#Multiple QLayout.addWidget calls on the same widget
|
||||
self.assertEqual(getrefcount(self.widget), 2)
|
||||
self.layout.addWidget(self.widget)
|
||||
self.assertEqual(getrefcount(self.widget), 3)
|
||||
self.layout.addWidget(self.widget)
|
||||
self.assertEqual(getrefcount(self.widget), 3)
|
||||
self.layout.addWidget(self.widget)
|
||||
self.assertEqual(getrefcount(self.widget), 3)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
52
tests/QtGui/qlayout_test.py
Normal file
52
tests/QtGui/qlayout_test.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtGui import QLayout, QWidget, QPushButton, QWidgetItem
|
||||
|
||||
class MyLayout(QLayout):
|
||||
def __init__(self, parent=None):
|
||||
QLayout.__init__(self, parent)
|
||||
self._list = []
|
||||
|
||||
def addItem(self, item):
|
||||
self.add(item)
|
||||
|
||||
def addWidget(self, widget):
|
||||
self.add(QWidgetItem(widget))
|
||||
|
||||
def itemAt(self, index):
|
||||
if index < len(self._list):
|
||||
return self._list[index]
|
||||
|
||||
return None
|
||||
|
||||
def count(self):
|
||||
return len(self._list)
|
||||
|
||||
def add(self, item):
|
||||
self._list.append(item)
|
||||
|
||||
|
||||
|
||||
#Test if a layout implemented in python, the QWidget.setLayout works
|
||||
#fine because this implement som layout functions used in glue code of
|
||||
#QWidget, then in c++ when call a virtual function this need call the QLayout
|
||||
#function implemented in python
|
||||
|
||||
class QLayoutTest(UsesQApplication):
|
||||
|
||||
def testOwnershipTransfer(self):
|
||||
b = QPushButton("teste")
|
||||
l = MyLayout()
|
||||
l.addWidget(b)
|
||||
|
||||
self.assertEqual(sys.getrefcount(b), 2)
|
||||
|
||||
w = QWidget()
|
||||
w.setLayout(l)
|
||||
|
||||
self.assertEqual(sys.getrefcount(b), 3)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
16
tests/QtGui/qlcdnumber_test.py
Normal file
16
tests/QtGui/qlcdnumber_test.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import unittest
|
||||
|
||||
from PySide.QtGui import QApplication, QLCDNumber
|
||||
|
||||
class QLCDNumberOverflow(unittest.TestCase):
|
||||
'''Test case for unhandled overflow on QLCDNumber() numDigits argument (see bug #215).'''
|
||||
|
||||
def setUp(self):
|
||||
self.app = QApplication([])
|
||||
|
||||
def testnumDigitsOverflow(self):
|
||||
# NOTE: PyQt4 raises TypeError, but boost.python raises OverflowError
|
||||
self.assertRaises(OverflowError, QLCDNumber, 840835495615213080)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
25
tests/QtGui/qlistwidgetitem_test.py
Normal file
25
tests/QtGui/qlistwidgetitem_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QListWidgetItemConstructor(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(QListWidgetItemConstructor, self).setUp()
|
||||
self.widgetList = QtGui.QListWidget()
|
||||
|
||||
def tearDown(self):
|
||||
del self.widgetList
|
||||
super(QListWidgetItemConstructor, self).tearDown()
|
||||
|
||||
def testConstructorWithParent(self):
|
||||
# Bug 235 - QListWidgetItem constructor not saving ownership
|
||||
QtGui.QListWidgetItem(self.widgetList)
|
||||
item = self.widgetList.item(0)
|
||||
self.assertEqual(item.listWidget(), self.widgetList)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
32
tests/QtGui/qmainwindow_test.py
Normal file
32
tests/QtGui/qmainwindow_test.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 TestMainWindow(UsesQApplication):
|
||||
|
||||
def testCreateToolbar(self):
|
||||
w = MainWindow()
|
||||
w.show()
|
||||
QtCore.QTimer.singleShot(1000, self.app.quit)
|
||||
self.app.exec_()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
49
tests/QtGui/qmatrix_test.py
Normal file
49
tests/QtGui/qmatrix_test.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import unittest
|
||||
|
||||
from PySide.QtCore import QPoint
|
||||
from PySide.QtGui import QMatrix, QMatrix4x4
|
||||
|
||||
|
||||
def qpointTimesQMatrix(point, matrix):
|
||||
'''As seen in "QPoint QMatrix::map(const QPoint &p) const" C++ implementation.'''
|
||||
return QPoint(matrix.m11() * point.x() + matrix.m21() * point.y() + matrix.dx(),
|
||||
matrix.m12() * point.x() + matrix.m22() * point.y() + matrix.dy())
|
||||
|
||||
class QMatrixTest(unittest.TestCase):
|
||||
|
||||
def testMatrix(self):
|
||||
matrix = QMatrix(11, 12, 21, 22, 100, 200)
|
||||
point = QPoint(3, 3)
|
||||
self.assertEqual(point * matrix, qpointTimesQMatrix(point, matrix))
|
||||
|
||||
def testMatrixWithWrongType(self):
|
||||
matrix = QMatrix(11, 12, 21, 22, 100, 200)
|
||||
point = QPoint(3, 3)
|
||||
self.assertRaises(TypeError, matrix.__mul__, point)
|
||||
|
||||
def testMatrix4x4(self):
|
||||
self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 3.0])
|
||||
self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 'I',
|
||||
4.0, 5.0, 6.0, 7.0,
|
||||
8.0, 9.0, 'N', 11.0,
|
||||
12.0, 'd', 14.0, 'T'])
|
||||
|
||||
my_data = [0.0, 1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0, 7.0,
|
||||
8.0, 9.0, 10.0, 11.0,
|
||||
12.0, 13.0, 14.0, 15.0]
|
||||
my_datac = [0.0, 4.0, 8.0, 12.0,
|
||||
1.0, 5.0, 9.0, 13.0,
|
||||
2.0, 6.0, 10.0, 14.0,
|
||||
3.0, 7.0, 11.0, 15.0]
|
||||
|
||||
m = QMatrix4x4(my_data)
|
||||
d = m.data()
|
||||
self.assert_(my_datac, d)
|
||||
|
||||
d = m.copyDataTo()
|
||||
self.assert_(my_data == list(d))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
58
tests/QtGui/qmenu_test.py
Normal file
58
tests/QtGui/qmenu_test.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QMenu, QKeySequence, QIcon
|
||||
from PySide.QtCore import SLOT
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QMenuAddAction(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(QMenuAddAction, self).setUp()
|
||||
self.menu = QMenu()
|
||||
|
||||
def tearDown(self):
|
||||
del self.menu
|
||||
super(QMenuAddAction, self).tearDown()
|
||||
|
||||
def testAddActionWithoutKeySequenceCallable(self):
|
||||
# bug #280
|
||||
action = self.menu.addAction(self.app.tr('aaa'), lambda : 1)
|
||||
|
||||
def testAddActionKeySequenceCallable(self):
|
||||
# bug #228
|
||||
action = self.menu.addAction(self.app.tr('aaa'), lambda : 1,
|
||||
QKeySequence(self.app.tr('Ctrl+O')))
|
||||
|
||||
def testAddActionKeySequenceSlot(self):
|
||||
action = self.menu.addAction('Quit', self.app, SLOT('quit()'),
|
||||
QKeySequence('Ctrl+O'))
|
||||
|
||||
class QMenuAddActionWithIcon(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(QMenuAddActionWithIcon, self).setUp()
|
||||
self.menu = QMenu()
|
||||
self.icon = QIcon()
|
||||
|
||||
def tearDown(self):
|
||||
del self.menu
|
||||
del self.icon
|
||||
super(QMenuAddActionWithIcon, self).tearDown()
|
||||
|
||||
def testAddActionWithoutKeySequenceCallable(self):
|
||||
# bug #280
|
||||
action = self.menu.addAction(self.icon, self.app.tr('aaa'), lambda : 1)
|
||||
|
||||
def testAddActionKeySequenceCallable(self):
|
||||
# bug #228
|
||||
action = self.menu.addAction(self.icon, self.app.tr('aaa'), lambda : 1,
|
||||
QKeySequence(self.app.tr('Ctrl+O')))
|
||||
|
||||
def testAddActionKeySequenceSlot(self):
|
||||
action = self.menu.addAction(self.icon, 'Quit', self.app, SLOT('quit()'),
|
||||
QKeySequence('Ctrl+O'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
25
tests/QtGui/qmenuadd_test.py
Normal file
25
tests/QtGui/qmenuadd_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
''' Test the QMenu.addAction() method'''
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QMenuAddAction(UsesQApplication):
|
||||
|
||||
def openFile(self, *args):
|
||||
self.arg = args
|
||||
|
||||
def testQMenuAddAction(self):
|
||||
fileMenu = QtGui.QMenu("&File")
|
||||
|
||||
addNewAction = fileMenu.addAction("&Open...", self.openFile)
|
||||
addNewAction.trigger()
|
||||
self.assertEquals(self.arg, ())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
37
tests/QtGui/qobject_mi_test.py
Normal file
37
tests/QtGui/qobject_mi_test.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'''Test cases for multiple inheritance from 2 QObjects'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QObject
|
||||
from PySide.QtGui import *
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class WidgetValidator(QWidget, QIntValidator):
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
QIntValidator.__init__(self, parent)
|
||||
|
||||
|
||||
class DoubleQObjectInheritanceTest(UsesQApplication):
|
||||
|
||||
def testDouble(self):
|
||||
'''Double inheritance from QObject classes'''
|
||||
|
||||
obj = WidgetValidator()
|
||||
|
||||
#QObject methods
|
||||
obj.setObjectName('aaaa')
|
||||
self.assertEqual(obj.objectName(), 'aaaa')
|
||||
|
||||
#QWidget methods
|
||||
obj.setVisible(False)
|
||||
self.assertFalse(obj.isVisible())
|
||||
|
||||
#QIntValidator methods
|
||||
self.assertEqual(obj.validate('aaaa', 0), QValidator.Invalid)
|
||||
self.assertEqual(obj.validate('33', 0), QValidator.Acceptable)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
49
tests/QtGui/qpainter_test.py
Normal file
49
tests/QtGui/qpainter_test.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import unittest
|
||||
|
||||
from PySide.QtGui import QPainter, QBrush, QLinearGradient
|
||||
from PySide.QtCore import QRect, QRectF, Qt
|
||||
|
||||
class QPainterDrawText(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.painter = QPainter()
|
||||
self.text = 'teste!'
|
||||
|
||||
def tearDown(self):
|
||||
del self.text
|
||||
del self.painter
|
||||
|
||||
def testDrawText(self):
|
||||
# bug #254
|
||||
rect = self.painter.drawText(100, 100, 100, 100,
|
||||
Qt.AlignCenter | Qt.TextWordWrap,
|
||||
self.text)
|
||||
self.assert_(isinstance(rect, QRect))
|
||||
|
||||
def testDrawTextWithRect(self):
|
||||
# bug #225
|
||||
rect = QRect(100, 100, 100, 100)
|
||||
newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
|
||||
self.text)
|
||||
|
||||
self.assert_(isinstance(newRect, QRect))
|
||||
|
||||
def testDrawTextWithRectF(self):
|
||||
'''QPainter.drawText(QRectF, ... ,QRectF*) inject code'''
|
||||
rect = QRectF(100, 52.3, 100, 100)
|
||||
newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
|
||||
self.text)
|
||||
|
||||
self.assert_(isinstance(newRect, QRectF))
|
||||
|
||||
class SetBrushWithOtherArgs(unittest.TestCase):
|
||||
'''Using qpainter.setBrush with args other than QBrush'''
|
||||
|
||||
def testSetBrushGradient(self):
|
||||
painter = QPainter()
|
||||
gradient = QLinearGradient(0, 0, 0, 0)
|
||||
painter.setBrush(gradient)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
20
tests/QtGui/qpen_test.py
Normal file
20
tests/QtGui/qpen_test.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import Qt
|
||||
from PySide.QtGui import QPen
|
||||
|
||||
class QPenTest(unittest.TestCase):
|
||||
|
||||
def testCtorWithCreatedEnums(self):
|
||||
'''A simple case of QPen creation using created enums.'''
|
||||
width = 0
|
||||
style = Qt.PenStyle(0)
|
||||
cap = Qt.PenCapStyle(0)
|
||||
join = Qt.PenJoinStyle(0)
|
||||
pen = QPen(Qt.blue, width, style, cap, join)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
62
tests/QtGui/qpixmap_test.py
Normal file
62
tests/QtGui/qpixmap_test.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import unittest
|
||||
|
||||
import os
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtGui import *
|
||||
from PySide.QtCore import *
|
||||
|
||||
class QPixmapTest(UsesQApplication):
|
||||
def testQVariantConstructor(self):
|
||||
pixmap = QPixmap()
|
||||
v = QVariant(pixmap)
|
||||
pixmap_copy = QPixmap(v)
|
||||
|
||||
def testQSizeConstructor(self):
|
||||
pixmap = QPixmap(QSize(10,20))
|
||||
self.assert_(pixmap.size().height(), 20)
|
||||
|
||||
def testQStringConstructor(self):
|
||||
pixmap = QPixmap(QString("Testing!"))
|
||||
|
||||
def testQVariantConstructor2(self):
|
||||
v = QVariant(QPixmap())
|
||||
pixmap2 = QPixmap(v)
|
||||
v = QVariant(QImage())
|
||||
pixmap2 = QPixmap(v)
|
||||
|
||||
def testQPixmapLoadFromDataWithQFile(self):
|
||||
f = QFile(os.path.join(os.path.dirname(__file__), 'sample.png'))
|
||||
self.assert_(f.open(QIODevice.ReadOnly))
|
||||
data = f.read(f.size())
|
||||
f.close()
|
||||
pixmap = QPixmap()
|
||||
self.assert_(pixmap.loadFromData(data))
|
||||
|
||||
def testQPixmapLoadFromDataWithPython(self):
|
||||
data = open(os.path.join(os.path.dirname(__file__),'sample.png'),'rb').read()
|
||||
pixmap = QPixmap()
|
||||
self.assert_(pixmap.loadFromData(data))
|
||||
|
||||
|
||||
class QPixmapToImage(UsesQApplication):
|
||||
|
||||
def testFilledImage(self):
|
||||
'''QPixmap.fill + toImage + image.pixel'''
|
||||
pixmap = QPixmap(100, 200)
|
||||
pixmap.fill(Qt.red) # Default Qt.white
|
||||
|
||||
self.assertEqual(pixmap.height(), 200)
|
||||
self.assertEqual(pixmap.width(), 100)
|
||||
|
||||
image = pixmap.toImage()
|
||||
|
||||
self.assertEqual(image.height(), 200)
|
||||
self.assertEqual(image.width(), 100)
|
||||
|
||||
pixel = image.pixel(10,10)
|
||||
self.assertEqual(pixel, QColor(Qt.red).rgba())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
30
tests/QtGui/qpushbutton_test.py
Normal file
30
tests/QtGui/qpushbutton_test.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import unittest
|
||||
|
||||
from helper import UsesQApplication
|
||||
from PySide.QtGui import QPushButton, QMenu, QWidget
|
||||
from PySide.QtCore import QTimer
|
||||
|
||||
class MyWidget(QWidget):
|
||||
def __init__(self):
|
||||
QWidget.__init__(self)
|
||||
|
||||
m = QMenu(self)
|
||||
b = QPushButton("Hello", self)
|
||||
b.setMenu(m)
|
||||
|
||||
|
||||
class QPushButtonTest(UsesQApplication):
|
||||
def createMenu(self, button):
|
||||
m = QMenu()
|
||||
button.setMenu(m)
|
||||
|
||||
def testSetMenu(self):
|
||||
w = MyWidget()
|
||||
w.show()
|
||||
|
||||
timer = QTimer.singleShot(100, self.app.quit)
|
||||
self.app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
29
tests/QtGui/qradialgradient_test.py
Normal file
29
tests/QtGui/qradialgradient_test.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import unittest
|
||||
|
||||
from PySide.QtGui import QRadialGradient
|
||||
from PySide.QtCore import QPointF
|
||||
|
||||
class QRadialGradientConstructor(unittest.TestCase):
|
||||
def _compare(self, qptf, tpl):
|
||||
self.assertEqual((qptf.x(), qptf.y()), tpl)
|
||||
|
||||
def _assertValues(self, grad):
|
||||
self._compare(grad.center(), (1.0, 2.0))
|
||||
self._compare(grad.focalPoint(), (3.0, 4.0))
|
||||
self.assertEqual(grad.radius(), 5.0)
|
||||
|
||||
def testAllInt(self):
|
||||
grad = QRadialGradient(1, 2, 5, 3, 4)
|
||||
self._assertValues(grad)
|
||||
|
||||
def testQPointF(self):
|
||||
grad = QRadialGradient(QPointF(1, 2), 5, QPointF(3, 4))
|
||||
self._assertValues(grad)
|
||||
|
||||
def testSetQPointF(self):
|
||||
grad = QRadialGradient()
|
||||
grad.setCenter(QPointF(1, 2))
|
||||
self._compare(grad.center(), (1.0, 2.0))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
21
tests/QtGui/qregion_test.py
Normal file
21
tests/QtGui/qregion_test.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide.QtGui import QRegion
|
||||
from PySide.QtCore import QPoint
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QRegionTest(UsesQApplication):
|
||||
|
||||
def testFunctionUnit(self):
|
||||
r = QRegion(0, 0, 10, 10)
|
||||
r2 = QRegion(5, 5, 10, 10)
|
||||
|
||||
ru = r.united(r2)
|
||||
self.assert_(ru.contains(QPoint(0,0)))
|
||||
self.assert_(ru.contains(QPoint(5,5)))
|
||||
self.assert_(ru.contains(QPoint(10,10)))
|
||||
self.assert_(ru.contains(QPoint(14,14)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
48
tests/QtGui/qshortcut_test.py
Normal file
48
tests/QtGui/qshortcut_test.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
''' Test the QShortcut constructor'''
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
class Foo(QtGui.QWidget):
|
||||
def __init__(self):
|
||||
QtGui.QWidget.__init__(self)
|
||||
self.ok = False
|
||||
self.copy = False
|
||||
|
||||
def slot_of_foo(self):
|
||||
self.ok = True
|
||||
|
||||
def slot_of_copy(self):
|
||||
self.copy = True
|
||||
|
||||
class MyShortcut(QtGui.QShortcut):
|
||||
def __init__(self, keys, wdg, slot):
|
||||
QtGui.QShortcut.__init__(self, keys, wdg, slot)
|
||||
|
||||
def emit_signal(self):
|
||||
self.emit(QtCore.SIGNAL("activated()"))
|
||||
|
||||
class QAppPresence(unittest.TestCase):
|
||||
|
||||
def testQShortcut(self):
|
||||
self.qapp = QtGui.QApplication([])
|
||||
f = Foo()
|
||||
|
||||
self.sc = MyShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return), f, f.slot_of_foo)
|
||||
self.scstd = MyShortcut(QtGui.QKeySequence.Copy, f, f.slot_of_copy)
|
||||
QtCore.QTimer.singleShot(0, self.init);
|
||||
self.qapp.exec_()
|
||||
self.assertEquals(f.ok, True)
|
||||
self.assertEquals(f.copy, True)
|
||||
|
||||
def init(self):
|
||||
self.sc.emit_signal();
|
||||
self.scstd.emit_signal();
|
||||
self.qapp.quit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
26
tests/QtGui/qstandarditemmodel_test.py
Normal file
26
tests/QtGui/qstandarditemmodel_test.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import unittest
|
||||
|
||||
from PySide.QtGui import *
|
||||
from PySide.QtCore import *
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QStandardItemModelTest(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(QStandardItemModelTest, self).setUp()
|
||||
self.window = QWidget()
|
||||
self.model = QStandardItemModel(0, 3, self.window)
|
||||
|
||||
def tearDown(self):
|
||||
del self.window
|
||||
del self.model
|
||||
super(QStandardItemModelTest, self).tearDown()
|
||||
|
||||
def testInsertRow(self):
|
||||
# bug #227
|
||||
self.model.insertRow(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
40
tests/QtGui/qstring_qkeysequence_test.py
Normal file
40
tests/QtGui/qstring_qkeysequence_test.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''Tests conversions of QString to and from QKeySequence.'''
|
||||
|
||||
import unittest
|
||||
from helper import UsesQApplication
|
||||
|
||||
from PySide.QtCore import QString
|
||||
from PySide.QtGui import QKeySequence, QAction
|
||||
|
||||
class QStringQKeySequenceTest(UsesQApplication):
|
||||
'''Tests conversions of QString to and from QKeySequence.'''
|
||||
|
||||
def testQStringFromQKeySequence(self):
|
||||
'''Creates a QString from a QKeySequence.'''
|
||||
keyseq = 'Ctrl+A'
|
||||
a = QString(QKeySequence(keyseq))
|
||||
self.assertEqual(a, keyseq)
|
||||
|
||||
def testQStringAsQKeySequence(self):
|
||||
'''Passes a QString to an argument expecting a QKeySequence.'''
|
||||
keyseq = QString('Ctrl+A')
|
||||
action = QAction(None)
|
||||
action.setShortcut(keyseq)
|
||||
shortcut = action.shortcut()
|
||||
self.assert_(isinstance(shortcut, QKeySequence))
|
||||
self.assertEqual(shortcut.toString(), keyseq)
|
||||
|
||||
def testPythonStringAsQKeySequence(self):
|
||||
'''Passes a Python string to an argument expecting a QKeySequence.'''
|
||||
keyseq = 'Ctrl+A'
|
||||
action = QAction(None)
|
||||
action.setShortcut(keyseq)
|
||||
shortcut = action.shortcut()
|
||||
self.assert_(isinstance(shortcut, QKeySequence))
|
||||
self.assertEqual(shortcut.toString(), keyseq)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
32
tests/QtGui/qstyle_test.py
Executable file
32
tests/QtGui/qstyle_test.py
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import unittest
|
||||
from helper import UsesQApplication
|
||||
|
||||
from PySide.QtGui import QWidget, QLabel, QFontComboBox, QStyleFactory
|
||||
|
||||
class SetStyleTest(UsesQApplication):
|
||||
'''Tests setting the same QStyle for all objects in a UI hierarchy.'''
|
||||
|
||||
def testSetStyle(self):
|
||||
'''All this test have to do is not break with some invalid Python wrapper.'''
|
||||
|
||||
def setStyleHelper(widget, style):
|
||||
widget.setStyle(style)
|
||||
widget.setPalette(style.standardPalette())
|
||||
for child in widget.children():
|
||||
if isinstance(child, QWidget):
|
||||
setStyleHelper(child, style)
|
||||
|
||||
container = QWidget()
|
||||
# QFontComboBox is used because it has an QLineEdit created in C++ inside it,
|
||||
# and if the QWidget.setStyle(style) steals the ownership of the style
|
||||
# for the C++ originated widget everything will break.
|
||||
fontComboBox = QFontComboBox(container)
|
||||
label = QLabel(container)
|
||||
label.setText('Label')
|
||||
style = QStyleFactory.create(QStyleFactory.keys()[0])
|
||||
setStyleHelper(container, style)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
17
tests/QtGui/qtableview_test.py
Normal file
17
tests/QtGui/qtableview_test.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QAbstractTableModel
|
||||
from PySide.QtGui import QTableWidget
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QPenTest(UsesQApplication):
|
||||
|
||||
def testItemModel(self):
|
||||
tv = QTableWidget()
|
||||
|
||||
self.assertEqual(type(tv.model()), QAbstractTableModel)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
21
tests/QtGui/qtabwidget_test.py
Normal file
21
tests/QtGui/qtabwidget_test.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QTabWidget
|
||||
from helper import TimedQApplication
|
||||
|
||||
class RemoveTabMethod(TimedQApplication):
|
||||
def setUp(self):
|
||||
TimedQApplication.setUp(self)
|
||||
self.tab = QTabWidget()
|
||||
|
||||
def tearDown(self):
|
||||
del self.tab
|
||||
TimedQApplication.tearDown(self)
|
||||
|
||||
|
||||
def testRemoveTabPresence(self):
|
||||
self.assert_(getattr(self.tab, 'removeTab'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
32
tests/QtGui/qtextedit_test.py
Normal file
32
tests/QtGui/qtextedit_test.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
'''Test cases for QTextEdit and ownership problems.'''
|
||||
|
||||
import unittest
|
||||
from sys import getrefcount
|
||||
from PySide.QtGui import QTextEdit
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class DontTouchReference(UsesQApplication):
|
||||
'''Check if the QTextTable returned by QTextCursor.insertTable() is not
|
||||
referenced by the QTextCursor that returns it.'''
|
||||
|
||||
def setUp(self):
|
||||
super(DontTouchReference, self).setUp()
|
||||
self.editor = QTextEdit()
|
||||
self.cursor = self.editor.textCursor()
|
||||
self.table = self.cursor.insertTable(1, 1)
|
||||
|
||||
def testQTextTable(self):
|
||||
# methods which return QTextTable should not increment its reference
|
||||
self.assertEqual(getrefcount(self.table), 2)
|
||||
f = self.cursor.currentFrame()
|
||||
del f
|
||||
self.assertEqual(getrefcount(self.table), 2)
|
||||
# destroying the cursor should not raise any "RuntimeError: internal
|
||||
# C++ object already deleted." when accessing the QTextTable
|
||||
del self.cursor
|
||||
self.assertEqual(getrefcount(self.table), 2)
|
||||
cell = self.table.cellAt(0, 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
35
tests/QtGui/qtoolbar_test.py
Normal file
35
tests/QtGui/qtoolbar_test.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
'''Test cases for QToolbar'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QToolBar, QMainWindow, QAction
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class AddActionText(UsesQApplication):
|
||||
'''Test case for calling QToolbar.addAction passing a text'''
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(AddActionText, self).setUp()
|
||||
self.window = QMainWindow()
|
||||
self.toolbar = QToolBar()
|
||||
self.window.addToolBar(self.toolbar)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
super(AddActionText, self).tearDown()
|
||||
del self.toolbar
|
||||
del self.window
|
||||
|
||||
def testText(self):
|
||||
#QToolBar.addAction(text) - add a QToolButton
|
||||
self.toolbar.addAction('aaaa')
|
||||
self.assertEqual(len(self.toolbar.actions()), 1)
|
||||
action = self.toolbar.actions()[0]
|
||||
self.assert_(isinstance(action, QAction))
|
||||
self.assertEqual(action.text(), 'aaaa')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
31
tests/QtGui/qtoolbox_test.py
Normal file
31
tests/QtGui/qtoolbox_test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QToolBox, QWidget, QIcon
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class OwnershipControl(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(OwnershipControl, self).setUp()
|
||||
self.toolbox = QToolBox()
|
||||
|
||||
def tearDown(self):
|
||||
del self.toolbox
|
||||
super(OwnershipControl, self).tearDown()
|
||||
|
||||
def testAddItem(self):
|
||||
# Was losing ownership of the widget.
|
||||
index = self.toolbox.addItem(QWidget(), 'item')
|
||||
item = self.toolbox.widget(index)
|
||||
self.assert_(isinstance(item, QWidget))
|
||||
|
||||
def testAddItemWithIcon(self):
|
||||
index = self.toolbox.addItem(QWidget(), QIcon(), 'item')
|
||||
item = self.toolbox.widget(index)
|
||||
self.assert_(isinstance(item, QWidget))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
85
tests/QtGui/qvariant_test.py
Normal file
85
tests/QtGui/qvariant_test.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''Test cases for QVariant with QtGui types'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import *
|
||||
from PySide.QtGui import *
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class Dummy(object):
|
||||
pass
|
||||
|
||||
class QVariantTypeName(unittest.TestCase):
|
||||
def testQPen(self):
|
||||
obj = QVariant(QPen(Qt.red))
|
||||
self.assertEqual('QPen', obj.typeName())
|
||||
|
||||
def testQColor(self):
|
||||
obj = QVariant(QColor(Qt.red))
|
||||
self.assertEqual('QColor', obj.typeName())
|
||||
|
||||
def testGlobalColor(self):
|
||||
obj = QVariant(Qt.red)
|
||||
# XXX: PyQt4 returns int instead of QColor like the C++ version
|
||||
self.assertEqual('QColor', obj.typeName())
|
||||
|
||||
def testEnums(self):
|
||||
obj = QVariant(Qt.SolidLine)
|
||||
self.assertEqual('int', obj.typeName())
|
||||
|
||||
class QVariantQColorImplicitlyConvertion(unittest.TestCase):
|
||||
def testConversions(self):
|
||||
c1 = QColor(0, 0, 0)
|
||||
v = QVariant(c1)
|
||||
c2 = QColor(v)
|
||||
self.assertEqual(c1, c2)
|
||||
|
||||
class QVariantQPixmap(UsesQApplication):
|
||||
'''QVariant(QPixmap)'''
|
||||
|
||||
def testBasic(self):
|
||||
'''QVariant(QPixmap)'''
|
||||
pixmap = QPixmap(10,20)
|
||||
pixmap.fill(Qt.blue)
|
||||
variant = QVariant(pixmap)
|
||||
|
||||
self.assertEqual(variant.typeName(), "QPixmap")
|
||||
|
||||
def testQObject(self):
|
||||
obj = QObject()
|
||||
v = QVariant(obj)
|
||||
self.assertEqual(v.typeName(), 'QObject*')
|
||||
|
||||
def testQWidget(self):
|
||||
obj = QWidget()
|
||||
v = QVariant(obj)
|
||||
self.assertEqual(v.typeName(), 'QWidget*')
|
||||
|
||||
class MyColor(QColor):
|
||||
pass
|
||||
|
||||
class MyPrimitive(int):
|
||||
pass
|
||||
|
||||
class QVariantMess(unittest.TestCase):
|
||||
def testMyColor(self):
|
||||
c1 = MyColor()
|
||||
v = QVariant(c1)
|
||||
self.assertEqual(type(v.toPyObject()), MyColor)
|
||||
|
||||
def testMyPrimitive(self):
|
||||
p = MyPrimitive(3)
|
||||
v = QVariant(p)
|
||||
self.assertNotEqual(v.type(), QVariant.Int)
|
||||
self.assertTrue(v.toPyObject() is p)
|
||||
|
||||
def testMatrix2x2(self):
|
||||
m = QMatrix2x2()
|
||||
v = QVariant(m)
|
||||
self.assertEqual('QMatrix2x2', v.typeName())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
33
tests/QtGui/qwidget_setlayout_test.py
Normal file
33
tests/QtGui/qwidget_setlayout_test.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QWidget, QVBoxLayout, QPushButton, QApplication, QHBoxLayout
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QWidgetTest(UsesQApplication):
|
||||
|
||||
def test_setLayout(self):
|
||||
layout = QVBoxLayout()
|
||||
btn1 = QPushButton("button_v1")
|
||||
layout.addWidget(btn1)
|
||||
|
||||
btn2 = QPushButton("button_v2")
|
||||
layout.addWidget(btn2)
|
||||
|
||||
layout2 = QHBoxLayout()
|
||||
|
||||
btn1 = QPushButton("button_h1")
|
||||
layout2.addWidget(btn1)
|
||||
|
||||
btn2 = QPushButton("button_h2")
|
||||
layout2.addWidget(btn2)
|
||||
|
||||
layout.addLayout(layout2)
|
||||
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
30
tests/QtGui/qwidget_test.py
Normal file
30
tests/QtGui/qwidget_test.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QWidget, QMainWindow
|
||||
from helper import UsesQApplication
|
||||
|
||||
class QWidgetInherit(QMainWindow):
|
||||
def __init__(self):
|
||||
QWidget.__init__(self)
|
||||
|
||||
class QWidgetTest(UsesQApplication):
|
||||
|
||||
def testInheritance(self):
|
||||
newobj = QWidgetInherit()
|
||||
widget = QWidget()
|
||||
newobj.setCentralWidget(widget)
|
||||
self.assertEqual(widget, newobj.centralWidget())
|
||||
|
||||
class QWidgetVisible(UsesQApplication):
|
||||
|
||||
def testBasic(self):
|
||||
# Also related to bug #244, on existence of setVisible'''
|
||||
widget = QWidget()
|
||||
self.assert_(not widget.isVisible())
|
||||
widget.setVisible(True)
|
||||
self.assert_(widget.isVisible())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
71
tests/QtGui/reference_count_test.py
Normal file
71
tests/QtGui/reference_count_test.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
'''Test cases for Reference count when the object is created in c++ side'''
|
||||
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
import weakref
|
||||
import gc
|
||||
|
||||
|
||||
from PySide.QtCore import Qt, QPointF
|
||||
from PySide.QtGui import QApplication, QGraphicsScene, QGraphicsRectItem, QPolygonF, QGraphicsPolygonItem, QGraphicsRectItem
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
destroyedRect = False
|
||||
destroyedPol = False
|
||||
|
||||
def rect_del(o):
|
||||
global destroyedRect
|
||||
destroyedRect = True
|
||||
|
||||
def pol_del(o):
|
||||
global destroyedPol
|
||||
destroyedPol = True
|
||||
|
||||
class ReferenceCount(UsesQApplication):
|
||||
|
||||
def setUp(self):
|
||||
super(ReferenceCount, self).setUp()
|
||||
self.scene = QGraphicsScene()
|
||||
|
||||
def tearDown(self):
|
||||
super(ReferenceCount, self).tearDown()
|
||||
|
||||
def beforeTest(self):
|
||||
points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)]
|
||||
pol = self.scene.addPolygon(QPolygonF(points))
|
||||
self.assert_(isinstance(pol, QGraphicsPolygonItem))
|
||||
self.wrp = weakref.ref(pol, pol_del)
|
||||
|
||||
#refcount need be 3 because one ref for QGraphicsScene, and one to rect obj
|
||||
self.assertEqual(sys.getrefcount(pol), 3)
|
||||
|
||||
def testReferenceCount(self):
|
||||
global destroyedRect
|
||||
global destroyedPol
|
||||
|
||||
self.beforeTest()
|
||||
|
||||
rect = self.scene.addRect(10.0, 10.0, 10.0, 10.0)
|
||||
self.assert_(isinstance(rect, QGraphicsRectItem))
|
||||
|
||||
self.wrr = weakref.ref(rect, rect_del)
|
||||
|
||||
#refcount need be 3 because one ref for QGraphicsScene, and one to rect obj
|
||||
self.assertEqual(sys.getrefcount(rect), 3)
|
||||
|
||||
del rect
|
||||
#not destroyed because one ref continue in QGraphicsScene
|
||||
self.assertEqual(destroyedRect, False)
|
||||
self.assertEqual(destroyedPol, False)
|
||||
|
||||
del self.scene
|
||||
|
||||
#QGraphicsScene was destroyed and this destroy internal ref to rect
|
||||
self.assertEqual(destroyedRect, True)
|
||||
self.assertEqual(destroyedPol, True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
BIN
tests/QtGui/sample.png
Normal file
BIN
tests/QtGui/sample.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
15
tests/QtGui/standardpixmap_test.py
Normal file
15
tests/QtGui/standardpixmap_test.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QPixmap, QStyle
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class StandardPixmapTest(UsesQApplication):
|
||||
def testDefaultOptions(self): # Bug 253
|
||||
pixmap = self.app.style().standardPixmap(QStyle.SP_DirClosedIcon)
|
||||
self.assert_(isinstance(pixmap, QPixmap))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
14
tests/QtGui/timed_app_test.py
Normal file
14
tests/QtGui/timed_app_test.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from helper import TimedQApplication
|
||||
|
||||
class TestTimedApp(TimedQApplication):
|
||||
'''Simple test case for TimedQApplication'''
|
||||
|
||||
def testFoo(self):
|
||||
#Simple test of TimedQApplication
|
||||
self.app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
70
tests/QtGui/virtual_protected_inheritance_test.py
Normal file
70
tests/QtGui/virtual_protected_inheritance_test.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
'''Test cases for overriding inherited protected virtual methods'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QTimerEvent
|
||||
from PySide.QtGui import QApplication, QSpinBox
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class MySpinButton(QSpinBox):
|
||||
'''Simple example class of overriding QObject.timerEvent'''
|
||||
|
||||
def __init__(self, max_runs=5, app=None):
|
||||
#Creates a new spinbox that will run <max_runs> and quit <app>
|
||||
super(MySpinButton, self).__init__()
|
||||
|
||||
if app is None:
|
||||
app = QApplication([])
|
||||
|
||||
self.app = app
|
||||
self.max_runs = max_runs
|
||||
self.runs = 0
|
||||
|
||||
def timerEvent(self, event):
|
||||
#Timer event method
|
||||
self.runs += 1
|
||||
|
||||
self.setValue(self.runs)
|
||||
|
||||
if self.runs == self.max_runs:
|
||||
self.app.quit()
|
||||
|
||||
if not isinstance(event, QTimerEvent):
|
||||
raise TypeError('Invalid event type. Must be TimerEvent')
|
||||
|
||||
class TimerEventTest(UsesQApplication):
|
||||
'''Test case for running QObject.timerEvent from inherited class'''
|
||||
|
||||
qapplication = True
|
||||
|
||||
def setUp(self):
|
||||
#Acquire resources
|
||||
super(TimerEventTest, self).setUp()
|
||||
self.widget = MySpinButton(app=self.app)
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.widget
|
||||
super(TimerEventTest, self).tearDown()
|
||||
|
||||
def testMethod(self):
|
||||
#QWidget.timerEvent overrinding (protected inherited)
|
||||
timer_id = self.widget.startTimer(0)
|
||||
|
||||
self.app.exec_()
|
||||
|
||||
self.widget.killTimer(timer_id)
|
||||
|
||||
self.assertEqual(self.widget.runs, 5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
#app = QApplication([])
|
||||
#widget = MySpinButton(app=app)
|
||||
#widget.startTimer(500)
|
||||
#widget.show()
|
||||
#app.exec_()
|
||||
|
||||
48
tests/QtGui/virtual_pure_override.py
Normal file
48
tests/QtGui/virtual_pure_override.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QGraphicsScene, QGraphicsRectItem, QGraphicsView, QApplication, QBrush, QColor
|
||||
from PySide.QtCore import QTimer
|
||||
from helper import UsesQApplication
|
||||
|
||||
qgraphics_item_painted = False
|
||||
|
||||
class RoundRectItem(QGraphicsRectItem):
|
||||
|
||||
def __init__(self, x, y, w, h):
|
||||
QGraphicsRectItem.__init__(self, x, y, w, h)
|
||||
|
||||
def paint(self, painter, qstyleoptiongraphicsitem, qwidget):
|
||||
global qgraphics_item_painted
|
||||
qgraphics_item_painted = True
|
||||
|
||||
|
||||
class QGraphicsItemTest(UsesQApplication):
|
||||
|
||||
def createRoundRect(self, scene):
|
||||
item = RoundRectItem(10, 10, 100, 100)
|
||||
item.setBrush(QBrush(QColor(255, 0, 0)))
|
||||
scene.addItem(item)
|
||||
return item
|
||||
|
||||
def quit_app(self):
|
||||
self.app.quit()
|
||||
|
||||
def test_setParentItem(self):
|
||||
global qgraphics_item_painted
|
||||
|
||||
scene = QGraphicsScene()
|
||||
scene.addText("test")
|
||||
view = QGraphicsView(scene)
|
||||
|
||||
rect = self.createRoundRect(scene)
|
||||
view.show()
|
||||
QTimer.singleShot(1000, self.quit_app)
|
||||
self.app.exec_()
|
||||
self.assert_(qgraphics_item_painted)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
23
tests/QtGui/wrong_return_test.py
Normal file
23
tests/QtGui/wrong_return_test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'''Test cases for Virtual functions with wrong return type'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide import QtCore, QtGui
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class MyWidget(QtGui.QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super(MyWidget, self).__init__(parent)
|
||||
|
||||
def sizeHint(self):
|
||||
pass
|
||||
|
||||
class testCase(UsesQApplication):
|
||||
|
||||
def testVirtualReturn(self):
|
||||
w = MyWidget()
|
||||
self.assertRaises(TypeError, w.show)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
17
tests/QtGui/x11_symbols.py
Normal file
17
tests/QtGui/x11_symbols.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
''' Test the presence of X11 symbols in QtGui'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtGui import QPixmap
|
||||
|
||||
class X11Test(unittest.TestCase):
|
||||
|
||||
def test(self):
|
||||
self.assert_('handle' in dir(QPixmap))
|
||||
self.assert_('x11Info' in dir(QPixmap))
|
||||
self.assert_('x11PictureHandle' in dir(QPixmap))
|
||||
self.assert_('x11SetDefaultScreen' in dir(QPixmap))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue