Skip to content
Permalink
Browse files
Make test more exhaustive
  • Loading branch information
nyalldawson committed May 27, 2021
1 parent aa93d03 commit d8f5de5cf1feaa8c5bce9590b5a87591f15f253b
Showing with 14 additions and 5 deletions.
  1. +14 −5 tests/src/python/test_qgsdataitem.py
@@ -13,6 +13,7 @@

import os
from qgis.PyQt.QtCore import QEventLoop
from qgis.PyQt import sip
from qgis.core import QgsDataCollectionItem, QgsLayerItem, QgsDirectoryItem
from utilities import unitTestDataPath
from qgis.testing import start_app, unittest
@@ -65,18 +66,26 @@ def testPythonCreateChildrenCalledFromCplusplus(self):
# Python object PyQgsLayerItem should still be alive
self.assertFalse(tabSetDestroyedFlag[0])

children = item.children()
self.assertEqual(len(children), 2)
self.assertEqual(children[0].name(), "name")
self.assertEqual(children[1].name(), "name2")
self.assertTrue(item.hasChildren())
self.assertEqual(item.rowCount(), 2)

del(children)
if i % 2 == 0:
# make the test a bit more exhaustive -- on every second run we don't eveb
# create any sip wrappers around the children
children = item.children()
self.assertEqual(len(children), 2)
self.assertEqual(children[0].name(), "name")
self.assertEqual(children[1].name(), "name2")

# Delete the object and make sure all deferred deletions are processed
item.destroyed.connect(loop.quit)
item.deleteLater()
loop.exec_()

if i % 2 == 0:
self.assertTrue(sip.isdeleted(children[0]))
self.assertTrue(sip.isdeleted(children[1]))

# Check that the PyQgsLayerItem Python object is now destroyed
self.assertTrue(tabSetDestroyedFlag[0])
tabSetDestroyedFlag[0] = False

0 comments on commit d8f5de5

Please sign in to comment.