From 58ac5dbec6ca09ffca6a937d7108f702144a4224 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 10 Sep 2025 19:48:23 -0400 Subject: [PATCH 1/3] style(PythonQtTestCleanup): Consistently indent test cases --- tests/PythonQtTestCleanup.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index d8d652fa2..0c82ebadf 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -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() From 39fcb2ab3d98947caa58c7809ed89632f9eb2347 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 10 Sep 2025 19:49:23 -0400 Subject: [PATCH 2/3] chore(PythonQtTestCleanup): Consistently use helper to run test scripts --- tests/PythonQtTestCleanup.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index 0c82ebadf..273ad49bb 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -81,11 +81,12 @@ 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" + )); } bool PythonQtTestCleanupHelper::runScript(const char* script) From ae3efa6425164126967ee8ee1298aa82b347b1b0 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 10 Sep 2025 20:02:09 -0400 Subject: [PATCH 3/3] tests: Update PythonQtTestCleanup to test alternative cleanup order This adds a new test to PythonQtTestCleanup to verify behavior when Python is finalized before PythonQt cleanup is called. --- tests/PythonQtTestCleanup.cpp | 9 +++++++++ tests/PythonQtTestCleanup.h | 1 + 2 files changed, 10 insertions(+) diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index 273ad49bb..c10681d1b 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -89,6 +89,15 @@ void PythonQtTestCleanup::testSignalReceiverCleanup() )); } +void PythonQtTestCleanup::testPyFinalizeThenPythonQtCleanup() +{ + if (Py_IsInitialized()) { + Py_Finalize(); + } + + PythonQt::cleanup(); +} + bool PythonQtTestCleanupHelper::runScript(const char* script) { _passed = false; diff --git a/tests/PythonQtTestCleanup.h b/tests/PythonQtTestCleanup.h index 82b14d547..c7e593e24 100644 --- a/tests/PythonQtTestCleanup.h +++ b/tests/PythonQtTestCleanup.h @@ -20,6 +20,7 @@ private Q_SLOTS: void testCallQtMethodInDestructorOwnedQTimer(); void testCallQtMethodInDestructorWeakRefGuarded(); void testSignalReceiverCleanup(); + void testPyFinalizeThenPythonQtCleanup(); private: PythonQtTestCleanupHelper* _helper;