Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions tests/PythonQtTestCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ void PythonQtTestCleanup::testCallQtMethodInDestructorOwnedQTimer()

void PythonQtTestCleanup::testCallQtMethodInDestructorWeakRefGuarded()
{
QVERIFY(_helper->runScript(
"import weakref\n" \
"import PythonQt.QtCore\n" \
"class TimerWrapper(object):\n" \
" def __init__(self):\n" \
" self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \
" def __del__(self):\n" \
" if self.timerWeakRef():\n" \
" self.timerWeakRef().setSingleShot(True)\n" \
"x = TimerWrapper()\n" \
"obj.setPassed()\n"
));
QVERIFY(_helper->runScript(
"import weakref\n" \
"import PythonQt.QtCore\n" \
"class TimerWrapper(object):\n" \
" def __init__(self):\n" \
" self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \
" def __del__(self):\n" \
" if self.timerWeakRef():\n" \
" self.timerWeakRef().setSingleShot(True)\n" \
"x = TimerWrapper()\n" \
"obj.setPassed()\n"
));
}

void PythonQtTestCleanup::testSignalReceiverCleanup()
Expand All @@ -81,11 +81,21 @@ void PythonQtTestCleanup::testSignalReceiverCleanup()

// Test that PythonQtSignalReceiver is cleaned up properly,
// i.e. PythonQt::cleanup() doesn't segfault
main.evalScript(
QVERIFY(_helper->runScript(
"import PythonQt.QtCore\n" \
"timer = PythonQt.QtCore.QTimer(obj)\n" \
"timer.connect('destroyed()', obj.onDestroyed)\n"
);
"timer.connect('destroyed()', obj.onDestroyed)\n" \
"obj.setPassed()\n"
));
}

void PythonQtTestCleanup::testPyFinalizeThenPythonQtCleanup()
{
if (Py_IsInitialized()) {
Py_Finalize();
}

PythonQt::cleanup();
}

bool PythonQtTestCleanupHelper::runScript(const char* script)
Expand Down
1 change: 1 addition & 0 deletions tests/PythonQtTestCleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private Q_SLOTS:
void testCallQtMethodInDestructorOwnedQTimer();
void testCallQtMethodInDestructorWeakRefGuarded();
void testSignalReceiverCleanup();
void testPyFinalizeThenPythonQtCleanup();

private:
PythonQtTestCleanupHelper* _helper;
Expand Down
Loading