From 27f24d1a6a6aa512a87e7b74517c22962ca958fd Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 27 Apr 2014 13:27:25 -0400 Subject: [PATCH] Expand ref cycle check to include all child QObjects --- pyqtgraph/tests/test_ref_cycles.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/tests/test_ref_cycles.py b/pyqtgraph/tests/test_ref_cycles.py index 3e78b382..9e3fee19 100644 --- a/pyqtgraph/tests/test_ref_cycles.py +++ b/pyqtgraph/tests/test_ref_cycles.py @@ -11,8 +11,27 @@ def assert_alldead(refs): for ref in refs: assert ref() is None +def qObjectTree(root): + """Return root and its entire tree of qobject children""" + childs = [root] + for ch in pg.QtCore.QObject.children(root): + childs += qObjectTree(ch) + return childs + def mkrefs(*objs): - return map(weakref.ref, objs) + """Return a list of weakrefs to each object in *objs. + QObject instances are expanded to include all child objects. + """ + allObjs = {} + for obj in objs: + if isinstance(obj, pg.QtCore.QObject): + obj = qObjectTree(obj) + else: + obj = [obj] + for o in obj: + allObjs[id(o)] = o + + return map(weakref.ref, allObjs.values()) def test_PlotWidget(): def mkobjs(*args, **kwds):