Tests synchronized with the boost python PySide.
This commit is contained in:
parent
84282e06ac
commit
3deada6b7e
14 changed files with 329 additions and 8 deletions
22
tests/qtcore/deletelater_test.py
Normal file
22
tests/qtcore/deletelater_test.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
'''Test cases for QTimer.singleShot'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL
|
||||||
|
from helper import UsesQCoreApplication
|
||||||
|
|
||||||
|
class TestDeleteLater(UsesQCoreApplication):
|
||||||
|
'''Test case for function DeleteLater'''
|
||||||
|
|
||||||
|
def testCase(self):
|
||||||
|
o = QObject()
|
||||||
|
o.deleteLater()
|
||||||
|
del o
|
||||||
|
QTimer.singleShot(100, self.app.quit)
|
||||||
|
self.app.exec_()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
28
tests/qtcore/qdate_test.py
Normal file
28
tests/qtcore/qdate_test.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
'''Test cases for QDate'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import *
|
||||||
|
|
||||||
|
class TestQDate (unittest.TestCase):
|
||||||
|
def testGetDate(self):
|
||||||
|
date = QDate(2009, 22, 9)
|
||||||
|
tuple_ = date.getDate()
|
||||||
|
self.assertEquals(tuple, tuple_.__class__)
|
||||||
|
(y, m, d) = tuple_
|
||||||
|
self.assertEqual(date.year(), y)
|
||||||
|
self.assertEqual(date.month(), m)
|
||||||
|
self.assertEqual(date.day(), d)
|
||||||
|
|
||||||
|
def testGetWeekNumber(self):
|
||||||
|
date = QDate(2000, 1, 1)
|
||||||
|
tuple_ = date.weekNumber()
|
||||||
|
self.assertEquals(tuple, tuple_.__class__)
|
||||||
|
(week, yearNumber) = tuple_
|
||||||
|
self.assertEqual(week, 52)
|
||||||
|
self.assertEqual(yearNumber, 1999)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
16
tests/qtcore/qhandle_test.py
Normal file
16
tests/qtcore/qhandle_test.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
'''Test cases for QEnum and QFlags'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import QThread, Qt
|
||||||
|
|
||||||
|
class TestHANDLE(unittest.TestCase):
|
||||||
|
def testIntConversion(self):
|
||||||
|
i = 0
|
||||||
|
h = QThread.currentThreadId()
|
||||||
|
i = 0 + int(h)
|
||||||
|
self.assertEqual(i, int(h))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
20
tests/qtcore/qlinef_test.py
Normal file
20
tests/qtcore/qlinef_test.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
'''Test cases for QLineF'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PySide.QtCore import *
|
||||||
|
|
||||||
|
class TestQLineF (unittest.TestCase):
|
||||||
|
def testIntersect(self):
|
||||||
|
l1 = QLineF(0, 0, 1, 0)
|
||||||
|
l2 = QLineF(1, -1, 1, 1)
|
||||||
|
tuple_ = l1.intersect(l2)
|
||||||
|
self.assertEquals(tuple, tuple_.__class__)
|
||||||
|
(value, p) = tuple_
|
||||||
|
self.assertEquals(QLineF.BoundedIntersection, value)
|
||||||
|
self.assertEqual(QPointF(1, 0), p)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
18
tests/qtcore/qprocess_test.py
Normal file
18
tests/qtcore/qprocess_test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
'''Test cases for QProcess'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PySide.QtCore import *
|
||||||
|
|
||||||
|
class TestQProcess (unittest.TestCase):
|
||||||
|
def testStartDetached(self):
|
||||||
|
tuple_ = QProcess.startDetached("dir", [], os.getcwd())
|
||||||
|
self.assertEquals(tuple, tuple_.__class__)
|
||||||
|
(value, pid) = tuple_
|
||||||
|
self.assertEquals(bool, value.__class__)
|
||||||
|
self.assertEqual(long, pid.__class__)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -11,11 +11,7 @@ class ResourcesUsage(unittest.TestCase):
|
||||||
'''Test case for resources usage'''
|
'''Test case for resources usage'''
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
try:
|
f = open(os.path.join(os.path.dirname(__file__), 'quoteEnUS.txt'))
|
||||||
f = open('quoteEnUS.txt')
|
|
||||||
except IOError:
|
|
||||||
f = open(os.path.join('qtcore', 'quoteEnUS.txt'))
|
|
||||||
|
|
||||||
self.text = f.read()
|
self.text = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
|
||||||
87
tests/qtcore/qtextstream_test.py
Normal file
87
tests/qtcore/qtextstream_test.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
|
||||||
|
'''Unit tests for QTextStream'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import QTextStream, QIODevice, QString, QByteArray
|
||||||
|
from PySide.QtCore import QTextCodec, QFile
|
||||||
|
|
||||||
|
class QTextStreamShiftTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.ba = QByteArray()
|
||||||
|
self.read = QTextStream(self.ba, QIODevice.ReadOnly)
|
||||||
|
self.write = QTextStream(self.ba, QIODevice.WriteOnly)
|
||||||
|
|
||||||
|
def testNumber(self):
|
||||||
|
'''QTextStream << number'''
|
||||||
|
|
||||||
|
self.write << QString('4')
|
||||||
|
res = self.read.readLine()
|
||||||
|
self.assert_(isinstance(res, QString))
|
||||||
|
self.assertEqual(res, QString('4'))
|
||||||
|
|
||||||
|
class QTextStreamGetSet(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.obj = QTextStream()
|
||||||
|
|
||||||
|
|
||||||
|
def testCodec(self):
|
||||||
|
'''QTextStream set/get Codec'''
|
||||||
|
|
||||||
|
codec = QTextCodec.codecForName('ISO8859-1')
|
||||||
|
self.obj.setCodec(codec)
|
||||||
|
self.assertEqual(codec, self.obj.codec())
|
||||||
|
|
||||||
|
def testDevice(self):
|
||||||
|
'''QTextStream get/set Device'''
|
||||||
|
device = QFile()
|
||||||
|
self.obj.setDevice(device)
|
||||||
|
self.assertEqual(device, self.obj.device())
|
||||||
|
self.obj.setDevice(None)
|
||||||
|
self.assertEqual(None, self.obj.device())
|
||||||
|
|
||||||
|
class QTextStreamInitialization(unittest.TestCase):
|
||||||
|
|
||||||
|
def testConstruction(self):
|
||||||
|
'''QTextStream construction'''
|
||||||
|
obj = QTextStream()
|
||||||
|
|
||||||
|
self.assertEqual(obj.codec(), QTextCodec.codecForLocale())
|
||||||
|
self.assertEqual(obj.device(), None)
|
||||||
|
self.assertEqual(obj.string(), None)
|
||||||
|
|
||||||
|
self.assert_(obj.atEnd())
|
||||||
|
self.assertEqual(obj.readAll(), '')
|
||||||
|
|
||||||
|
class QTextStreamReadLinesFromDevice(unittest.TestCase):
|
||||||
|
|
||||||
|
def _check_data(self, data_set):
|
||||||
|
|
||||||
|
for data, lines in data_set:
|
||||||
|
stream = QTextStream(data)
|
||||||
|
|
||||||
|
res = []
|
||||||
|
while not stream.atEnd():
|
||||||
|
res.append(stream.readLine())
|
||||||
|
|
||||||
|
self.assertEqual(res, lines)
|
||||||
|
|
||||||
|
def testLatin1(self):
|
||||||
|
'''QTextStream readLine for simple Latin1 strings'''
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
data.append((QByteArray(), []))
|
||||||
|
data.append((QByteArray('\n'), ['']))
|
||||||
|
data.append((QByteArray('\r\n'), ['']))
|
||||||
|
data.append((QByteArray('ole'), ['ole']))
|
||||||
|
data.append((QByteArray('ole\n'), ['ole']))
|
||||||
|
data.append((QByteArray('ole\r\n'), ['ole']))
|
||||||
|
data.append((QByteArray('ole\r\ndole\r\ndoffen'), ['ole', 'dole', 'doffen']))
|
||||||
|
|
||||||
|
self._check_data(data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -139,7 +139,7 @@ class ItemRetrieve(UsesQApplication):
|
||||||
def testItems(self):
|
def testItems(self):
|
||||||
#QGraphicsScene.items()
|
#QGraphicsScene.items()
|
||||||
items = self.scene.items()
|
items = self.scene.items()
|
||||||
self.assertEqual(items, self.items)
|
self.assertEqual(items.sort(), self.items.sort())
|
||||||
|
|
||||||
def testItemAt(self):
|
def testItemAt(self):
|
||||||
#QGraphicsScene.itemAt()
|
#QGraphicsScene.itemAt()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from PySide.QtGui import QPainter
|
from PySide.QtGui import QPainter, QBrush, QLinearGradient
|
||||||
from PySide.QtCore import QRect, Qt
|
from PySide.QtCore import QRect, Qt
|
||||||
|
|
||||||
class QPainterDrawText(unittest.TestCase):
|
class QPainterDrawText(unittest.TestCase):
|
||||||
|
|
@ -26,6 +26,14 @@ class QPainterDrawText(unittest.TestCase):
|
||||||
self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
|
self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
|
||||||
self.text)
|
self.text)
|
||||||
|
|
||||||
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,14 @@ class Foo(QtGui.QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtGui.QWidget.__init__(self)
|
QtGui.QWidget.__init__(self)
|
||||||
self.ok = False
|
self.ok = False
|
||||||
|
self.copy = False
|
||||||
|
|
||||||
def slot_of_foo(self):
|
def slot_of_foo(self):
|
||||||
self.ok = True
|
self.ok = True
|
||||||
|
|
||||||
|
def slot_of_copy(self):
|
||||||
|
self.copy = True
|
||||||
|
|
||||||
class MyShortcut(QtGui.QShortcut):
|
class MyShortcut(QtGui.QShortcut):
|
||||||
def __init__(self, keys, wdg, slot):
|
def __init__(self, keys, wdg, slot):
|
||||||
QtGui.QShortcut.__init__(self, keys, wdg, slot)
|
QtGui.QShortcut.__init__(self, keys, wdg, slot)
|
||||||
|
|
@ -27,14 +31,17 @@ class QAppPresence(unittest.TestCase):
|
||||||
def testQShortcut(self):
|
def testQShortcut(self):
|
||||||
self.qapp = QtGui.QApplication([])
|
self.qapp = QtGui.QApplication([])
|
||||||
f = Foo()
|
f = Foo()
|
||||||
|
|
||||||
self.sc = MyShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Return), f, f.slot_of_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);
|
QtCore.QTimer.singleShot(0, self.init);
|
||||||
self.qapp.exec_()
|
self.qapp.exec_()
|
||||||
self.assertEquals(f.ok, True)
|
self.assertEquals(f.ok, True)
|
||||||
|
self.assertEquals(f.copy, True)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.sc.emit_signal();
|
self.sc.emit_signal();
|
||||||
|
self.scstd.emit_signal();
|
||||||
self.qapp.quit()
|
self.qapp.quit()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__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()
|
||||||
48
tests/qtuitools/test.ui
Normal file
48
tests/qtuitools/test.ui
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Form</class>
|
||||||
|
<widget class="QWidget" name="Form">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>185</width>
|
||||||
|
<height>133</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QFrame" name="child_object">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>181</width>
|
||||||
|
<height>131</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="grandson_object">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>50</x>
|
||||||
|
<y>60</y>
|
||||||
|
<width>80</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>PushButton</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
14
tests/qtuitools/ui_test.py
Normal file
14
tests/qtuitools/ui_test.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtUiTools import QUiLoader
|
||||||
|
|
||||||
|
from helper import UsesQApplication
|
||||||
|
|
||||||
|
class QUiLoaderCreation(UsesQApplication):
|
||||||
|
|
||||||
|
def testConstructor(self):
|
||||||
|
loader = QUiLoader()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
34
tests/qtuitools/uiloader_test.py
Normal file
34
tests/qtuitools/uiloader_test.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
from helper import UsesQApplication
|
||||||
|
|
||||||
|
from PySide.QtGui import QWidget, QFrame, QPushButton
|
||||||
|
from PySide.QtUiTools import QUiLoader
|
||||||
|
|
||||||
|
#ugly workaround for work with ctest
|
||||||
|
file_path = [ "./test.ui", "./qtuitools/test.ui", "../tests/qtuitools/test.ui", "../../tests/qtuitools/test.ui" ]
|
||||||
|
|
||||||
|
def get_file_path():
|
||||||
|
for path in file_path:
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
return ""
|
||||||
|
|
||||||
|
class QUioaderTeste(UsesQApplication):
|
||||||
|
def testLoadFile(self):
|
||||||
|
widget = QWidget()
|
||||||
|
|
||||||
|
file_path = get_file_path()
|
||||||
|
self.assertTrue(file_path != "")
|
||||||
|
|
||||||
|
QUiLoader.loadUi(file_path, widget)
|
||||||
|
|
||||||
|
self.assertTrue("child_object" in dir(widget))
|
||||||
|
self.assertTrue("grandson_object" in dir(widget.child_object))
|
||||||
|
|
||||||
|
self.assertEqual(type(widget.child_object), QFrame)
|
||||||
|
self.assertEqual(type(widget.child_object.grandson_object), QPushButton)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue