Skip to content

Commit d62d412

Browse files
jcfrmrbean-bremen
authored andcommitted
tests(cleanup): clarify destructor tests and add weakref-guarded variant
- Rename `testCallQtMethodInDel` to make intent explicit. - Add `testCallQtMethodInDestructorWeakRefGuarded` to cover the pattern where `__del__` dereferences a `weakref` before calling a Qt method.
1 parent b4fc6ee commit d62d412

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

tests/PythonQtTestCleanup.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void PythonQtTestCleanup::testQtEnum()
4444
));
4545
}
4646

47-
void PythonQtTestCleanup::testCallQtMethodInDel()
47+
void PythonQtTestCleanup::testCallQtMethodInDestructorOwnedQTimer()
4848
{
4949
QVERIFY(_helper->runScript(
5050
"import PythonQt.QtCore\n" \
@@ -59,6 +59,22 @@ void PythonQtTestCleanup::testCallQtMethodInDel()
5959
));
6060
}
6161

62+
void PythonQtTestCleanup::testCallQtMethodInDestructorWeakRefGuarded()
63+
{
64+
QVERIFY(_helper->runScript(
65+
"import weakref\n" \
66+
"import PythonQt.QtCore\n" \
67+
"class TimerWrapper(object):\n" \
68+
" def __init__(self):\n" \
69+
" self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \
70+
" def __del__(self):\n" \
71+
" if self.timerWeakRef():\n" \
72+
" self.timerWeakRef().setSingleShot(True)\n" \
73+
"x = TimerWrapper()\n" \
74+
"obj.setPassed()\n"
75+
));
76+
}
77+
6278
void PythonQtTestCleanup::testSignalReceiverCleanup()
6379
{
6480
PythonQtObjectPtr main = PythonQt::self()->getMainModule();

tests/PythonQtTestCleanup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ private Q_SLOTS:
1717
void cleanup();
1818

1919
void testQtEnum();
20-
void testCallQtMethodInDel();
20+
void testCallQtMethodInDestructorOwnedQTimer();
21+
void testCallQtMethodInDestructorWeakRefGuarded();
2122
void testSignalReceiverCleanup();
2223

2324
private:

0 commit comments

Comments
 (0)