Skip to content
Permalink
Browse files

Modify the test case to use spy signal

  • Loading branch information
nirvn committed Feb 9, 2021
1 parent 1536408 commit e62aaef0c6052544ab2c0833405b7200c51697c5
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 e62aaef

Please sign in to comment.