File: test_qmenu_leak_workaround.py

package info (click to toggle)
python-pyqtgraph 0.13.7-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,072 kB
  • sloc: python: 54,043; makefile: 127; ansic: 40; sh: 2
file content (25 lines) | stat: -rw-r--r-- 823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import sys
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets

def test_qmenu_leak_workaround():
    # refer to https://github.com/pyqtgraph/pyqtgraph/pull/2518
    pg.mkQApp()
    topmenu = QtWidgets.QMenu()
    submenu = QtWidgets.QMenu()

    refcnt1 = sys.getrefcount(submenu)

    # check that after the workaround,
    # submenu has no change in refcnt
    topmenu.addMenu(submenu)
    submenu.setParent(None) # this is the workaround for PySide{2,6},
                            # and should have no effect on bindings
                            # where it is not needed.
    refcnt2 = sys.getrefcount(submenu)
    assert refcnt2 == refcnt1
    
    # check that topmenu is not a C++ parent of submenu.
    # i.e. deleting topmenu leaves submenu alive
    del topmenu
    assert pg.Qt.isQObjectAlive(submenu)