Skip to content

Commit

Permalink
[processing] added test for invalid geometry checking
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya authored and alexbruy committed Jan 9, 2017
1 parent 7b68c77 commit 3067648
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/plugins/processing/tests/TestData.py
Expand Up @@ -36,3 +36,7 @@ def table():

def points():
return os.path.join(testDataPath, 'points.gml')

def invalid_geometries():
return os.path.join(testDataPath, 'invalidgeometries.gml')

16 changes: 15 additions & 1 deletion python/plugins/processing/tests/ToolsTest.py
Expand Up @@ -33,7 +33,7 @@
from qgis.testing import start_app, unittest

from processing.core.ProcessingConfig import ProcessingConfig
from processing.tests.TestData import testDataPath, points
from processing.tests.TestData import testDataPath, points, invalid_geometries
from processing.tools import vector

testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')
Expand Down Expand Up @@ -98,7 +98,21 @@ def testFeatures(self):
features = vector.features(test_layer, QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry))
self.assertEqual(set([f.id() for f in features]), set([2, 4, 6]))

#test exception is raised when filtering invalid geoms
test_layer_invalid_geoms = QgsVectorLayer(invalid_geometries(), 'test', 'ogr')

previous_value_invalid_geoms = ProcessingConfig.getSetting(ProcessingConfig.FILTER_INVALID_GEOMETRIES)
ProcessingConfig.setSettingValue(ProcessingConfig.FILTER_INVALID_GEOMETRIES, 2)
try:
features = vector.features(test_layer_invalid_geoms)
features = [f for f in features]
self.fail()

This comment has been minimized.

Copy link
@rldhont

rldhont Jan 9, 2017

Contributor

@volaya the test fails here. Does this code have to fail at vector.feature ?

except GeoAlgorithmExecutionException:
pass

ProcessingConfig.setSettingValue(ProcessingConfig.FILTER_INVALID_GEOMETRIES, previous_value_invalid_geoms)
ProcessingConfig.setSettingValue(ProcessingConfig.USE_SELECTED, previous_value)


def testValues(self):
ProcessingConfig.initialize()
Expand Down

4 comments on commit 3067648

@rldhont
Copy link
Contributor

@rldhont rldhont commented on 3067648 Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global name 'GeoAlgorithmExecutionException' is not defined!
https://travis-ci.org/qgis/QGIS/builds/190244003

@alexbruy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, it passed locally. Missed import should be fixed now

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volaya I've reverted this test for now due to failures on Travis

@volaya
Copy link
Contributor Author

@volaya volaya commented on 3067648 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson Thanks for that. I was a bit puzzled with the test. The test data has a self-intersecting polygon, so that should be signaled as an invalid geometry and an error raised. However, the polygons is skipped, because the isGeosEmpty() method returns true for that geometry... The geometry is wrong, but not empty. Am I missing something, or that might be some error on the core geometry class?

Please sign in to comment.