def testQCoreAppChildren(self): #QObject.children() after creating a QCoreApplication # Minimal test: # 1- Create QCoreApp # 2- Create parent and childrens # 3- While keeping the children alive, call parent.children() # 4- Delete parent app = QCoreApplication([]) parent = QObject() children = [QObject(parent) for x in range(25)] # Uncomment the lines below to make the test pass # del children # del child2 del parent # XXX Segfaults here self.assert_(True)
def testInstallEventFilterRefCountAfterDelete(self): '''Bug 910 - installEventFilter() increments reference count on target object http://bugs.pyside.org/show_bug.cgi?id=910''' obj = QObject() filt = QObject() self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.installEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) wref = weakref.ref(obj) del obj self.assertEqual(wref(), None)
def testReprFunction(self): reprPen = repr(QPen()) self.assertTrue(reprPen.startswith("<PySide.QtGui.QPen")) reprBrush = repr(QBrush()) self.assertTrue(reprBrush.startswith("<PySide.QtGui.QBrush")) reprObject = repr(QObject()) self.assertTrue(reprObject.startswith("<PySide.QtCore.QObject"))
def testIt(self): global called called = False o = QObject() o.connect(o, SIGNAL("ASignal"), functools.partial(someSlot, "partial ..")) o.emit(SIGNAL("ASignal")) self.assertTrue(called)
def testQStringDefault(self): obj = QObject() obj.setObjectName('foo') self.assertEqual(obj.objectName(), py3k.unicode_('foo')) obj.setObjectName(py3k.unicode_('áâãà')) self.assertEqual(obj.objectName(), py3k.unicode_('áâãà')) obj.setObjectName(None) self.assertEqual(obj.objectName(), py3k.unicode_(''))
def testInstallEventFilterRefCountAfterRemove(self): # Bug 910 obj = QObject() filt = QObject() self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.installEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.removeEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) wref = weakref.ref(obj) del obj self.assertEqual(wref(), None)
def testConnection(self): o = TestObject(0) c = QObject() c.setObjectName("child") self._child = None o.childrenChanged.connect(self.childrenChanged) o.addChild(c) self.assertEquals(self._child.objectName(), "child")
def testWrongType(self): '''Wrong type passed to QFlags binary operators''' self.assertRaises(TypeError, Qt.NoItemFlags | '43') self.assertRaises(TypeError, Qt.NoItemFlags & '43') self.assertRaises(TypeError, 'jabba' & Qt.NoItemFlags) self.assertRaises(TypeError, 'hut' & Qt.NoItemFlags) self.assertRaises(TypeError, Qt.NoItemFlags & QObject())
def testChildEventMonkeyPatch(self): #Test if the new childEvent injected on QObject instance is called from C++ parent = QObject() def childEvent(obj, event): self.duck_childEvent_called = True parent.childEvent = MethodType(childEvent, parent, QObject) child = QObject() child.setParent(parent) self.assert_(self.duck_childEvent_called) # This is done to decrease the refcount of the vm object # allowing the object wrapper to be deleted before the # BindingManager. This is useful when compiling Shiboken # for debug, since the BindingManager destructor has an # assert that checks if the wrapper mapper is empty. parent.childEvent = None
def testUtf8(self): translator = QTranslator() translator.load(os.path.join(self.trdir, 'trans_russian.qm')) self.app.installTranslator(translator) obj = QObject() obj.setObjectName(obj.trUtf8('Hello World!')) self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
def testBasic(self): '''QObject.signalsBlocked() and blockSignals() The signals aren't blocked by default. blockSignals returns the previous value''' obj = QObject() self.assert_(not obj.signalsBlocked()) self.assert_(not obj.blockSignals(True)) self.assert_(obj.signalsBlocked()) self.assert_(obj.blockSignals(False))
def testLatin(self): #Set string value to Latin translator = QTranslator() translator.load(os.path.join(self.trdir, 'trans_latin.qm')) self.app.installTranslator(translator) obj = QObject() obj.setObjectName(obj.tr('Hello World!')) self.assertEqual(obj.objectName(), py3k.unicode_('Orbis, te saluto!'))
def testObjectRefcount(self): """Emission of QObject.destroyed() to a python slot""" def callback(): pass obj = QObject() refcount = getrefcount(obj) QObject.connect(obj, SIGNAL('destroyed()'), callback) self.assertEqual(refcount, getrefcount(obj)) QObject.disconnect(obj, SIGNAL('destroyed()'), callback) self.assertEqual(refcount, getrefcount(obj))
def testSharedSignalEmission(self): o = QObject() m = MyObject() o.connect(SIGNAL("foo2()"), m.mySlot) m.connect(SIGNAL("foo2()"), m.mySlot) o.emit(SIGNAL("foo2()")) self.assertEqual(m._slotCalledCount, 1) del o m.emit(SIGNAL("foo2()")) self.assertEqual(m._slotCalledCount, 2)
def testRefCount(self): o = QObject() filt = MyFilter() o.installEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2) o.installEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2) o.removeEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2)
def testDisconnectCleanup(self): for c in range(MAX_LOOPS): self._count = 0 self._senders = [] for i in range(MAX_OBJECTS): o = QObject() QObject.connect(o, SIGNAL("fire()"), lambda: self.myCB()) self._senders.append(o) o.emit(SIGNAL("fire()")) self.assertEqual(self._count, MAX_OBJECTS) #delete all senders will disconnect the signals self._senders = []
def testIt(self): app = QApplication([]) self.assertEqual("<__main__.MyQObject object at ", repr(MyQObject())[:30]) self.assertEqual("<__main__.MyQWidget object at ", repr(MyQWidget())[:30]) self.assertEqual("<__main__.MyQGraphicsObject(this = 0x", repr(MyQGraphicsObject())[:37]) self.assertEqual("<__main__.MyQGraphicsItem(this = 0x", repr(MyQGraphicsItem())[:35]) self.assertEqual("<PySide.QtCore.QObject object at ", repr(QObject())[:33]) self.assertEqual("<PySide.QtCore.QObject object at ", repr(PySide.QtCore.QObject())[:33]) self.assertEqual("<PySide.QtGui.QWidget object at ", repr(QWidget())[:32]) self.assertEqual("<PySide.QtGui.QGraphicsWidget(this = 0x", repr(QGraphicsWidget())[:39])
def test_qt(): from PySide.QtCore import QObject @Q_Q class _A(object): def __init__(self, q): pass def __del__(self): print "del B" class A(QObject): def __init__(self): super(A, self).__init__() self.__d = _A(self) def __del__(self): print "del A" a = A() b = QObject() #b.setParent(a) a = 0
def testString(self): # No implicit conversions from QByteArray to python string ba = QByteArray("object name") obj = QObject() self.assertRaises(TypeError, obj.setObjectName, ba)
def testDestroyed(self): """Emission of QObject.destroyed() to a python slot""" obj = QObject() QObject.connect(obj, SIGNAL('destroyed()'), self.destroyed_cb) del obj self.assert_(self.called)
def run(self): #Start-quit sequence self.qobj = QObject() mutex.lock() self.called = True mutex.unlock()
def testInvalidDisconnection(self): o = QObject() self.assertRaises(RuntimeError, o.destroyed.disconnect, self.callback)
def setUp(self): #Acquire resources self.obj = QObject()
def testSignalWithObject(self): o = MyObject() o.sig6.connect(o.slotObject) arg = QObject() o.sig6.emit(arg) self.assertEqual(arg, o._o)
# along with this program. If not, see <http://www.gnu.org/licenses/>. """ State machines for the Bitmask app. """ import logging from PySide import QtCore from PySide.QtCore import QStateMachine, QState, Signal from PySide.QtCore import QObject from leap.bitmask.services import connections from leap.common.check import leap_assert_type logger = logging.getLogger(__name__) _tr = QObject().tr # Indexes for the state dict _ON = "on" _OFF = "off" _CON = "connecting" _DIS = "disconnecting" class SignallingState(QState): """ A state that emits a custom signal on entry. """ def __init__(self, signal, parent=None, name=None): """ Initializer.
def testSetUnicodeRetrieveUnicode(self): #Set Python unicode string and retrieve unicode obj = QObject() obj.setObjectName(py3k.unicode_('ümlaut')) self.assertEqual(obj.objectName(), py3k.unicode_('ümlaut'))
def testSetRegularStringRetrieveUnicode(self): #Set regular Python string retrieve unicode obj = QObject() obj.setObjectName('test') self.assertEqual(obj.objectName(), py3k.unicode_('test'))
def testCase(self): o = QObject() o.deleteLater() del o QTimer.singleShot(100, self.app.quit) self.app.exec_()
def testQTimer(self): parent = ExtQTimer() child = QObject() child.setParent(parent) self.assert_(parent.child_event_received)
def testQObject(self): parent = ExtQObject() child = QObject() child.setParent(parent) self.assertTrue(parent.child_event_received)