Skip to content

Commit 1cfd6ee

Browse files
committedNov 18, 2017
Add provider test to ensure that extent is correctly calculated
for layers with 1 point and also no features The first scenario should return an 'empty' rectangle with x/y min/max matching just the single point's coordinate, the second scenario must return a null rectangle (not an empty 0,0 rectangle!)
1 parent af6b4cc commit 1cfd6ee

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed
 

‎tests/src/python/providertestbase.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ def getSubsetString2(self):
184184
"""Individual providers may need to override this depending on their subset string formats"""
185185
return '"cnt" > 100 and "cnt" < 400'
186186

187+
def getSubsetString3(self):
188+
"""Individual providers may need to override this depending on their subset string formats"""
189+
return '"name"=\'Apple\''
190+
191+
def getSubsetStringNoMatching(self):
192+
"""Individual providers may need to override this depending on their subset string formats"""
193+
return '"name"=\'AppleBearOrangePear\''
194+
187195
def testOrderBy(self):
188196
try:
189197
self.disableCompiler()
@@ -281,9 +289,30 @@ def testMaxValue(self):
281289
def testExtent(self):
282290
reference = QgsGeometry.fromRect(
283291
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
284-
provider_extent = QgsGeometry.fromRect(self.source.extent())
292+
provider_extent = self.source.extent()
293+
self.assertAlmostEqual(provider_extent.xMinimum(), -71.123, 3)
294+
self.assertAlmostEqual(provider_extent.xMaximum(), -65.32, 3)
295+
self.assertAlmostEqual(provider_extent.yMinimum(), 66.33, 3)
296+
self.assertAlmostEqual(provider_extent.yMaximum(), 78.3, 3)
297+
298+
# with only one point
299+
subset = self.getSubsetString3()
300+
self.source.setSubsetString(subset)
301+
self.assertEqual(self.source.featureCount(), 1)
302+
provider_extent = self.source.extent()
303+
self.source.setSubsetString(None)
304+
self.assertAlmostEqual(provider_extent.xMinimum(), -68.2, 3)
305+
self.assertAlmostEqual(provider_extent.xMaximum(), -68.2, 3)
306+
self.assertAlmostEqual(provider_extent.yMinimum(), 70.8, 3)
307+
self.assertAlmostEqual(provider_extent.yMaximum(), 70.8, 3)
285308

286-
self.assertTrue(QgsGeometry.compare(provider_extent.asPolygon()[0], reference.asPolygon()[0], 0.00001))
309+
# with no points
310+
subset = self.getSubsetStringNoMatching()
311+
self.source.setSubsetString(subset)
312+
self.assertEqual(self.source.featureCount(), 0)
313+
provider_extent = self.source.extent()
314+
self.source.setSubsetString(None)
315+
self.assertTrue(provider_extent.isNull())
287316

288317
def testUnique(self):
289318
self.assertEqual(set(self.source.uniqueValues(1)), set([-200, 100, 200, 300, 400]))

0 commit comments

Comments
 (0)
Please sign in to comment.