Updated pyside and signals tests to works with python 2.x and 3.x
This commit is contained in:
parent
1874425448
commit
6869a49bc3
3 changed files with 19 additions and 22 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import py3kcompat as py3k
|
||||||
from testbinding import TestView
|
from testbinding import TestView
|
||||||
from PySide.QtCore import QAbstractListModel, QObject, QModelIndex
|
from PySide.QtCore import QAbstractListModel, QObject, QModelIndex
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ class ModelViewTest(unittest.TestCase):
|
||||||
model = ListModelThatReturnsString()
|
model = ListModelThatReturnsString()
|
||||||
view = TestView(model)
|
view = TestView(model)
|
||||||
obj = view.getData()
|
obj = view.getData()
|
||||||
self.assertEqual(type(obj), unicode)
|
self.assertEqual(type(obj), py3k.unicode)
|
||||||
self.assertEqual(obj, 'string')
|
self.assertEqual(obj, 'string')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
import functools
|
|
||||||
|
|
||||||
from PySide.QtCore import *
|
from PySide.QtCore import QObject, Slot, SIGNAL, SLOT
|
||||||
|
|
||||||
class MyObject(QObject):
|
class MyObject(QObject):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
|
@ -24,7 +22,7 @@ class MyObject(QObject):
|
||||||
def foo(self):
|
def foo(self):
|
||||||
self._slotCalledCount = self._slotCalledCount + 1
|
self._slotCalledCount = self._slotCalledCount + 1
|
||||||
|
|
||||||
@Slot(unicode, int)
|
@Slot(str, int)
|
||||||
def mySlot4(self, a, b):
|
def mySlot4(self, a, b):
|
||||||
self._slotCalledCount = self._slotCalledCount + 1
|
self._slotCalledCount = self._slotCalledCount + 1
|
||||||
|
|
||||||
|
|
@ -41,17 +39,17 @@ class StaticMetaObjectTest(unittest.TestCase):
|
||||||
def testSignalPropagation(self):
|
def testSignalPropagation(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
m = o.metaObject()
|
m = o.metaObject()
|
||||||
self.assert_(m.indexOfSlot('mySlot()') > 0)
|
self.assertTrue(m.indexOfSlot('mySlot()') > 0)
|
||||||
self.assert_(m.indexOfSlot('mySlot2(int)') > 0)
|
self.assertTrue(m.indexOfSlot('mySlot2(int)') > 0)
|
||||||
self.assert_(m.indexOfSlot('mySlot2(QString)') > 0)
|
self.assertTrue(m.indexOfSlot('mySlot2(QString)') > 0)
|
||||||
self.assert_(m.indexOfSlot('mySlot3()') > 0)
|
self.assertTrue(m.indexOfSlot('mySlot3()') > 0)
|
||||||
self.assert_(m.indexOfSlot('mySlot4(QString,int)') > 0)
|
self.assertTrue(m.indexOfSlot('mySlot4(QString,int)') > 0)
|
||||||
|
|
||||||
def testEmission(self):
|
def testEmission(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
o.connect(SIGNAL("mySignal()"), o, SLOT("mySlot()"))
|
o.connect(SIGNAL("mySignal()"), o, SLOT("mySlot()"))
|
||||||
o.emit(SIGNAL("mySignal()"))
|
o.emit(SIGNAL("mySignal()"))
|
||||||
self.assert_(o._slotCalledCount == 1)
|
self.assertTrue(o._slotCalledCount == 1)
|
||||||
|
|
||||||
def testResult(self):
|
def testResult(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
import functools
|
|
||||||
|
|
||||||
from PySide.QtCore import *
|
from PySide.QtCore import QTimer, Signal, QObject, Slot, Qt
|
||||||
from helper import UsesQCoreApplication
|
from helper import UsesQCoreApplication
|
||||||
|
|
||||||
class MyObject(QTimer):
|
class MyObject(QTimer):
|
||||||
sig1 = Signal()
|
sig1 = Signal()
|
||||||
sig2 = Signal(int, name='rangeChanged')
|
sig2 = Signal(int, name='rangeChanged')
|
||||||
sig3 = Signal(int)
|
sig3 = Signal(int)
|
||||||
sig4 = Signal((int,), (unicode,))
|
sig4 = Signal((int,), (str,))
|
||||||
sig5 = Signal((unicode,), (int,))
|
sig5 = Signal((str,), (int,))
|
||||||
sig6 = Signal(QObject)
|
sig6 = Signal(QObject)
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
|
|
@ -38,7 +36,7 @@ class SignalObjectTest(UsesQCoreApplication):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
o.sig1.connect(o.slot1)
|
o.sig1.connect(o.slot1)
|
||||||
o.sig1.emit()
|
o.sig1.emit()
|
||||||
self.assert_(o._called)
|
self.assertTrue(o._called)
|
||||||
|
|
||||||
def testSignalWithArgs(self):
|
def testSignalWithArgs(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
|
|
@ -53,8 +51,8 @@ class SignalObjectTest(UsesQCoreApplication):
|
||||||
|
|
||||||
def testDictOperator(self):
|
def testDictOperator(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
o.sig4[unicode].connect(o.slotString)
|
o.sig4[str].connect(o.slotString)
|
||||||
o.sig4[unicode].emit("PySide")
|
o.sig4[str].emit("PySide")
|
||||||
self.assertEqual(o._s, "PySide")
|
self.assertEqual(o._s, "PySide")
|
||||||
|
|
||||||
def testGeneretedSignal(self):
|
def testGeneretedSignal(self):
|
||||||
|
|
@ -62,19 +60,19 @@ class SignalObjectTest(UsesQCoreApplication):
|
||||||
o.timeout.connect(self.cb)
|
o.timeout.connect(self.cb)
|
||||||
o.start(100)
|
o.start(100)
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
self.assert_(self._cb_called)
|
self.assertTrue(self._cb_called)
|
||||||
|
|
||||||
def testConnectionType(self):
|
def testConnectionType(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
o.timeout.connect(self.cb, type=Qt.DirectConnection)
|
o.timeout.connect(self.cb, type=Qt.DirectConnection)
|
||||||
o.start(100)
|
o.start(100)
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
self.assert_(self._cb_called)
|
self.assertTrue(self._cb_called)
|
||||||
|
|
||||||
def testSignalWithSignal(self):
|
def testSignalWithSignal(self):
|
||||||
o = MyObject()
|
o = MyObject()
|
||||||
o.sig2.connect(o.myRange)
|
o.sig2.connect(o.myRange)
|
||||||
print "sig->sig", o.sig5.connect(o.sig2)
|
o.sig5.connect(o.sig2)
|
||||||
o.sig5[int].emit(10)
|
o.sig5[int].emit(10)
|
||||||
self.assertEqual(o._range, 10)
|
self.assertEqual(o._range, 10)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue