Added all original pyside unit tests to the shiboken version.

This commit is contained in:
Hugo Lima 2009-09-21 14:51:26 -03:00
commit 9af36fbb64
160 changed files with 6616 additions and 12 deletions

View 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()

View 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()

View 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()

View 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()

View 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()

View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
import unittest
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 ParentPolicyTest(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)
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,19 @@
import unittest
from PySide import QtGui, QtCore
class Properties(unittest.TestCase):
def testStaticProperty(self):
self.assertEqual(QtGui.QGraphicsItem.UserType, 65536)
def testMemberProperty(self):
i = QtGui.QGraphicsItem()
self.assertEqual(i.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
View 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()

View 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()

View 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()

View 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()

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import unittest
import sys
from PySide import QtGui, QtCore
class QAppPresence(unittest.TestCase):
def testQPixmap(self):
ds = QtCore.QDataStream()
p = QtGui.QPixmap()
ds << p
ds >> p
if __name__ == '__main__':
app = QtGui.QApplication([])
unittest.main()

View 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()

View 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, self.items)
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()

View file

@ -0,0 +1,46 @@
'''Test cases for QLabel->pixmap refcount control'''
import unittest
import sys
from helper import UsesQApplication
from PySide.QtGui import QApplication, QLabel, QPixmap
class QLabelTest(UsesQApplication):
'''Test case for constructor of QBrush'''
def testDestroyOwner(self):
p = QPixmap()
l = QLabel()
l.setPixmap(p)
del p
p1 = l.pixmap()
self.assertEqual(sys.getrefcount(p1), 2)
self.assertEqual(sys.getrefcount(l), 2)
del l
self.assertEqual(sys.getrefcount(p1), 2)
def testRefCount(self):
p = QPixmap()
l = QLabel()
l.setPixmap(p)
del p
p1 = l.pixmap()
self.assertEqual(sys.getrefcount(p1), 2)
p2 = l.pixmap()
self.assertEqual(sys.getrefcount(p2), 3)
p3 = l.pixmap()
self.assertEqual(sys.getrefcount(p3), 4)
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,96 @@
'''Test cases for QLayout handling of child widgets references'''
import unittest
from sys import getrefcount
from PySide.QtGui import QHBoxLayout, QVBoxLayout, QGridLayout
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 testHBoxReference(self):
#QHBoxLayout.addWidget reference count
self.checkLayoutReference(QHBoxLayout())
def testVBoxReference(self):
#QVBoxLayout.addWidget reference count
self.checkLayoutReference(QVBoxLayout())
def testGridReference(self):
#QGridLayout.addWidget reference count
self.checkLayoutReference(QGridLayout())
def testFormReference(self):
#QFormLayout.addWidget reference count
self.checkLayoutReference(QFormLayout())
def testStackedReference(self):
#QStackedLayout.addWidget reference count
self.checkLayoutReference(QStackedLayout())
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.layout = QHBoxLayout()
def tearDown(self):
#Release resources
del self.widget
del self.layout
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()

View 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()

View 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()

View 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()

View 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()

58
tests/qtgui/qmenu_test.py Normal file
View 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()

View file

@ -0,0 +1,31 @@
import unittest
from PySide.QtGui import QPainter
from PySide.QtCore import QRect, 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.assertNotEqual(rect, None)
def testDrawTextWithRect(self):
# bug #225
rect = QRect(100, 100, 100, 100)
self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
self.text)
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,16 @@
import unittest
from helper import UsesQApplication
from PySide.QtGui import QPixmap
from PySide.QtCore import QVariant
#Only test if is possible create a QPixmap from a QVariant
class QPixmapTest(UsesQApplication):
def testQVariantConstructor(self):
pixmap = QPixmap()
v = QVariant(pixmap)
pixmap_copy = QPixmap(v)
if __name__ == '__main__':
unittest.main()

View 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()

View 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()

View file

@ -0,0 +1,41 @@
# -*- 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
def slot_of_foo(self):
self.ok = 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)
QtCore.QTimer.singleShot(0, self.init);
self.qapp.exec_()
self.assertEquals(f.ok, True)
def init(self):
self.sc.emit_signal();
self.qapp.quit()
if __name__ == '__main__':
unittest.main()

View 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()

View file

@ -0,0 +1,14 @@
import unittest
from PySide.QtGui import QPixmap, QStyle
from helper import UsesQApplication
class StandardPixmap(UsesQApplication):
def testDefaultOptions(self): # Bug 253
pixmap = self.app.style().standardPixmap(QStyle.SP_DirClosedIcon)
self.assert_(isinstance(pixmap, QPixmap))
if __name__ == '__main__':
unittest.main()

View 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()

View 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()

View 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()

View file

@ -0,0 +1,39 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''Test cases for QVariant with QtGui types'''
import unittest
from PySide.QtCore import *
from PySide.QtGui import *
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)
if __name__ == '__main__':
unittest.main()

View 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()

View file

@ -0,0 +1,18 @@
import unittest
from PySide.QtGui import QWidget
from helper import UsesQApplication
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()

View 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()

View 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()

View 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_()

View 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()

View 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()