Skip to content
Permalink
Browse files

Modify the test case to use spy signal

(cherry picked from commit e62aaef)
  • Loading branch information
nirvn authored and nyalldawson committed Feb 19, 2021
1 parent 3436f80 commit c603c0feec7861dc7f2788e6468e63d0462d291e
Showing with 13 additions and 10 deletions.
  1. +13 −10 tests/src/python/test_qgsvectorlayerfeaturecounter.py
@@ -17,6 +17,7 @@
from qgis.PyQt.QtCore import QVariant, Qt, QDateTime, QDate, QTime
from qgis.PyQt.QtGui import QPainter
from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtTest import QSignalSpy

from qgis.core import (QgsWkbTypes,
QgsVectorLayer,
@@ -72,23 +73,25 @@ def tearDown(self):

def testFeaturesCount(self):

def onSymbolFeatureCountMapChanged():
assert self.vl.featureCount(self.vl.renderer().legendSymbolItems()[0].ruleKey()) == 4
self.assertTrue(self.vl.renderer().legendSymbolItems())

assert self.vl.renderer().legendSymbolItems()

self.vl.symbolFeatureCountMapChanged.connect(onSymbolFeatureCountMapChanged)
signal_spy = QSignalSpy(self.vl.symbolFeatureCountMapChanged)
self.vl.countSymbolFeatures()
signal_spy.wait()

def testFeaturesCountOnEmptyLayer(self):
self.assertEqual(len(signal_spy), 1)
self.assertEqual(self.vl.featureCount(self.vl.renderer().legendSymbolItems()[0].ruleKey()), 5)

def onSymbolFeatureCountMapChanged():
assert self.vl2.featureCount(self.vl2.renderer().legendSymbolItems()[0].ruleKey()) == 0
def testFeaturesCountOnEmptyLayer(self):

assert self.vl2.renderer().legendSymbolItems()
self.assertTrue(self.vl2.renderer().legendSymbolItems())

self.vl2.symbolFeatureCountMapChanged.connect(onSymbolFeatureCountMapChanged)
signal_spy = QSignalSpy(self.vl2.symbolFeatureCountMapChanged)
self.vl2.countSymbolFeatures()
signal_spy.wait()

self.assertEqual(len(signal_spy), 1)
self.assertEqual(self.vl2.featureCount(self.vl2.renderer().legendSymbolItems()[0].ruleKey()), 0)


if __name__ == '__main__':

0 comments on commit c603c0f

Please sign in to comment.