Skip to content
Permalink
Browse files

Merge pull request #3701 from alexbruy/processing-ogr-tests

[processsing] tests for GDAL algorithms
  • Loading branch information
alexbruy committed Nov 14, 2016
2 parents 798bc09 + d81533e commit 6e9631ea87c501764dcf7462ce787a515ba29a30
Showing with 903 additions and 1,975 deletions.
  1. +0 −1 python/plugins/processing/__init__.py
  2. +0 −1 python/plugins/processing/algs/gdal/GdalAlgorithm.py
  3. +8 −11 python/plugins/processing/algs/gdal/offsetcurve.py
  4. +7 −5 python/plugins/processing/algs/gdal/ogr2ogrbuffer.py
  5. +36 −32 python/plugins/processing/algs/gdal/ogr2ogrdissolve.py
  6. +0 −1 python/plugins/processing/algs/gdal/ogr2ogrpointsonlines.py
  7. +6 −4 python/plugins/processing/algs/gdal/onesidebuffer.py
  8. +1 −1 python/plugins/processing/algs/grass/GrassUtils.py
  9. +1 −1 python/plugins/processing/algs/grass7/Grass7Utils.py
  10. +0 −1 python/plugins/processing/tests/AlgorithmsTestBase.py
  11. +2 −2 python/plugins/processing/tests/CMakeLists.txt
  12. +14 −14 python/plugins/processing/tests/GdalAlgorithmsTest.py
  13. +2 −2 python/plugins/processing/tests/ParametersTest.py
  14. +3 −44 python/plugins/processing/tests/TestData.py
  15. +76 −90 python/plugins/processing/tests/ToolsTest.py
  16. BIN python/plugins/processing/tests/data/lines.dbf
  17. +0 −1 python/plugins/processing/tests/data/lines.prj
  18. +0 −1 python/plugins/processing/tests/data/lines.qpj
  19. BIN python/plugins/processing/tests/data/lines.shp
  20. BIN python/plugins/processing/tests/data/lines.shx
  21. BIN python/plugins/processing/tests/data/points.dbf
  22. +0 −1 python/plugins/processing/tests/data/points.prj
  23. +0 −1 python/plugins/processing/tests/data/points.qpj
  24. BIN python/plugins/processing/tests/data/points.shp
  25. BIN python/plugins/processing/tests/data/points.shx
  26. BIN python/plugins/processing/tests/data/points2.dbf
  27. +0 −1 python/plugins/processing/tests/data/points2.prj
  28. +0 −1 python/plugins/processing/tests/data/points2.qpj
  29. BIN python/plugins/processing/tests/data/points2.shp
  30. BIN python/plugins/processing/tests/data/points2.shx
  31. BIN python/plugins/processing/tests/data/polygons.dbf
  32. +0 −10 python/plugins/processing/tests/data/polygons.geojson
  33. +0 −1 python/plugins/processing/tests/data/polygons.prj
  34. +0 −1 python/plugins/processing/tests/data/polygons.qpj
  35. BIN python/plugins/processing/tests/data/polygons.shp
  36. BIN python/plugins/processing/tests/data/polygons.shx
  37. BIN python/plugins/processing/tests/data/polygons2.dbf
  38. +0 −1 python/plugins/processing/tests/data/polygons2.prj
  39. +0 −1 python/plugins/processing/tests/data/polygons2.qpj
  40. BIN python/plugins/processing/tests/data/polygons2.shp
  41. BIN python/plugins/processing/tests/data/polygons2.shx
  42. +0 −356 python/plugins/processing/tests/data/project.qgs
  43. BIN python/plugins/processing/tests/data/union.dbf
  44. +0 −1 python/plugins/processing/tests/data/union.prj
  45. +0 −1 python/plugins/processing/tests/data/union.qpj
  46. BIN python/plugins/processing/tests/data/union.shp
  47. BIN python/plugins/processing/tests/data/union.shx
  48. +0 −23 python/plugins/processing/tests/testdata/expected/PolygonDissolveTest_output.xsd
  49. +0 −30 python/plugins/processing/tests/testdata/expected/autoincrement_field.xsd
  50. +0 −23 python/plugins/processing/tests/testdata/expected/buffer_lines.xsd
  51. +0 −23 python/plugins/processing/tests/testdata/expected/buffer_lines_flat.xsd
  52. +0 −23 python/plugins/processing/tests/testdata/expected/buffer_lines_square.xsd
  53. +0 −43 python/plugins/processing/tests/testdata/expected/buffer_polys.xsd
  54. +0 −43 python/plugins/processing/tests/testdata/expected/buffer_polys_bevel.xsd
  55. +0 −43 python/plugins/processing/tests/testdata/expected/buffer_polys_dissolve.xsd
  56. +0 −43 python/plugins/processing/tests/testdata/expected/buffer_polys_mitre.xsd
  57. +0 −43 python/plugins/processing/tests/testdata/expected/dissolve_field.xsd
  58. +0 −43 python/plugins/processing/tests/testdata/expected/dissolve_two_fields.xsd
  59. +0 −43 python/plugins/processing/tests/testdata/expected/eliminate_largest_area.xsd
  60. +0 −43 python/plugins/processing/tests/testdata/expected/eliminate_smallest_area.xsd
  61. +16 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_lines.gfs
  62. +48 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_lines.gml
  63. +32 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_polys.gfs
  64. +58 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_polys.gml
  65. +32 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_polys_dissolve.gfs
  66. +22 −0 python/plugins/processing/tests/testdata/expected/gdal/buffer_polys_dissolve.gml
  67. +16 −0 python/plugins/processing/tests/testdata/expected/gdal/offset_lines.gfs
  68. +48 −0 python/plugins/processing/tests/testdata/expected/gdal/offset_lines.gml
  69. +16 −0 python/plugins/processing/tests/testdata/expected/gdal/one_side_buffer.gfs
  70. +48 −0 python/plugins/processing/tests/testdata/expected/gdal/one_side_buffer.gml
  71. +16 −0 python/plugins/processing/tests/testdata/expected/gdal/points_along_lines.gfs
  72. +48 −0 python/plugins/processing/tests/testdata/expected/gdal/points_along_lines.gml
  73. +21 −0 python/plugins/processing/tests/testdata/expected/gdal/polygonize.gfs
  74. +134 −0 python/plugins/processing/tests/testdata/expected/gdal/polygonize.gml
  75. +0 −23 python/plugins/processing/tests/testdata/expected/line_offset_bevel.xsd
  76. +0 −23 python/plugins/processing/tests/testdata/expected/line_offset_mitre.xsd
  77. +0 −23 python/plugins/processing/tests/testdata/expected/line_offset_round_negative.xsd
  78. +0 −23 python/plugins/processing/tests/testdata/expected/line_offset_round_positive.xsd
  79. +0 −23 python/plugins/processing/tests/testdata/expected/lines_boundary.xsd
  80. +0 −23 python/plugins/processing/tests/testdata/expected/lines_bounds.xsd
  81. +0 −23 python/plugins/processing/tests/testdata/expected/lines_split_with_lines.xsd
  82. +0 −23 python/plugins/processing/tests/testdata/expected/lines_split_with_same_lines.xsd
  83. +0 −23 python/plugins/processing/tests/testdata/expected/merge_lines.xsd
  84. +0 −23 python/plugins/processing/tests/testdata/expected/multi_to_single.xsd
  85. +0 −23 python/plugins/processing/tests/testdata/expected/multiline_boundary.xsd
  86. +0 −23 python/plugins/processing/tests/testdata/expected/multiline_bounds.xsd
  87. +0 −23 python/plugins/processing/tests/testdata/expected/multiline_offset.xsd
  88. +0 −30 python/plugins/processing/tests/testdata/expected/multipoint_bounds.xsd
  89. +0 −47 python/plugins/processing/tests/testdata/expected/multipoint_delaunay.xsd
  90. +0 −43 python/plugins/processing/tests/testdata/expected/multipoly_boundary.xsd
  91. +0 −43 python/plugins/processing/tests/testdata/expected/multipoly_bounds.xsd
  92. +0 −23 python/plugins/processing/tests/testdata/expected/nullGeometryDissolve_output.xsd
  93. +0 −23 python/plugins/processing/tests/testdata/expected/point_bounds.xsd
  94. +0 −23 python/plugins/processing/tests/testdata/expected/point_on_line.xsd
  95. +0 −30 python/plugins/processing/tests/testdata/expected/point_on_multipoint.xsd
  96. +0 −43 python/plugins/processing/tests/testdata/expected/point_on_poly.xsd
  97. +0 −43 python/plugins/processing/tests/testdata/expected/poly_boundary.xsd
  98. +0 −43 python/plugins/processing/tests/testdata/expected/poly_bounds.xsd
  99. +0 −43 python/plugins/processing/tests/testdata/expected/polys_centroid.xsd
  100. +0 −43 python/plugins/processing/tests/testdata/expected/polys_deleteholes.xsd
  101. +0 −43 python/plugins/processing/tests/testdata/expected/polys_to_lines.xsd
  102. +0 −23 python/plugins/processing/tests/testdata/expected/rectanglesovalsdiamondsfixed.xsd
  103. +133 −16 python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
  104. +10 −0 python/plugins/processing/tests/testdata/points.gfs
  105. +19 −1 python/plugins/processing/tests/testdata/points.gml
  106. +6 −10 python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
  107. BIN python/plugins/processing/tests/{data → testdata}/table.dbf
  108. +3 −8 python/plugins/processing/tools/dataobjects.py
  109. +7 −5 python/plugins/processing/tools/system.py
  110. +14 −39 python/plugins/processing/tools/vector.py
@@ -30,7 +30,6 @@
from processing.tools.vector import * # NOQA
from processing.tools.raster import * # NOQA
from processing.tools.system import * # NOQA
from processing.tests.TestData import loadTestData # NOQA


def classFactory(iface):
@@ -74,7 +74,6 @@ def processAlgorithm(self, progress):

def shortHelp(self):
return self._formatHelp('''This algorithm is based on the GDAL %s module.
For more info, see the <a href = 'http://www.gdal.org/%s.html'> module help</a>
''' % (self.commandName(), self.commandName()))

@@ -27,6 +27,7 @@

from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
@@ -46,8 +47,6 @@ class OffsetCurve(GdalAlgorithm):
INPUT_LAYER = 'INPUT_LAYER'
GEOMETRY = 'GEOMETRY'
RADIUS = 'RADIUS'
LEFTRIGHT = 'LEFTRIGHT'
LEFTRIGHTLIST = ['Right', 'Left']
DISSOLVEALL = 'DISSOLVEALL'
FIELD = 'FIELD'
MULTI = 'MULTI'
@@ -62,10 +61,10 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.GEOMETRY,
self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
'geometry', optional=False))
self.addParameter(ParameterString(self.RADIUS,
self.tr('Offset distance'), '1000', optional=False))
self.addParameter(ParameterSelection(self.LEFTRIGHT,
self.tr('Offset side'), self.LEFTRIGHTLIST, 0))
self.addParameter(ParameterNumber(self.RADIUS,
self.tr('Offset distance (positive value for left-sided and negative - for right-sided)'),
-99999999.999999, 99999999.999999, 1000.0,
optional=False))
self.addParameter(ParameterBoolean(self.DISSOLVEALL,
self.tr('Dissolve all results'), False))
self.addParameter(ParameterTableField(self.FIELD,
@@ -82,7 +81,6 @@ def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
geometry = self.getParameterValue(self.GEOMETRY)
distance = self.getParameterValue(self.RADIUS)
leftright = self.getParameterValue(self.LEFTRIGHT)
dissolveall = self.getParameterValue(self.DISSOLVEALL)
field = self.getParameterValue(self.FIELD)
multi = self.getParameterValue(self.MULTI)
@@ -100,15 +98,14 @@ def getConsoleCommands(self):
arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(layername)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

if dissolveall or field is not None:
sql = "SELECT ST_Union(ST_OffsetCurve({}, {}, {})) * FROM '{}'".format(geometry, distance, leftright, layername)
sql = "SELECT ST_Union(ST_OffsetCurve({}, {})) * FROM '{}'".format(geometry, distance, layername)
else:
sql = "SELECT ST_OffsetCurve({}, {}, {}), * FROM '{}'".format(geometry, distance, leftright, layername)
sql = "SELECT ST_OffsetCurve({}, {}), * FROM '{}'".format(geometry, distance, layername)

if field is not None:
sql = '"{} GROUP BY {}"'.format(sql, field)
@@ -118,7 +115,7 @@ def getConsoleCommands(self):
if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
if options is not None and len(options.strip()) > 0:
arguments.append(options)

commands = []
@@ -27,6 +27,7 @@

from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector
@@ -59,8 +60,10 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.GEOMETRY,
self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
'geometry', optional=False))
self.addParameter(ParameterString(self.DISTANCE,
self.tr('Buffer distance'), '1000', optional=False))
self.addParameter(ParameterNumber(self.DISTANCE,
self.tr('Buffer distance'),
0.0, 99999999.999999, 1000.0,
optional=False))
self.addParameter(ParameterBoolean(self.DISSOLVEALL,
self.tr('Dissolve all results'), False))
self.addParameter(ParameterTableField(self.FIELD,
@@ -93,7 +96,6 @@ def getConsoleCommands(self):
arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(ogrLayerName(inLayer))
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')
@@ -111,7 +113,7 @@ def getConsoleCommands(self):
if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
if options is not None and len(options) > 0:
arguments.append(options)

commands = []
@@ -124,4 +126,4 @@ def getConsoleCommands(self):
return commands

def commandName(self):
return "ogr2ogr"
return 'ogr2ogr'
@@ -85,52 +85,56 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
geometry = str(self.getParameterValue(self.GEOMETRY))
field = str(self.getParameterValue(self.FIELD))
statsatt = str(self.getParameterValue(self.STATSATT))
stats = self.getParameterValue(self.STATS)
area = self.getParameterValue(self.AREA)
geometry = self.getParameterValue(self.GEOMETRY)
field = self.getParameterValue(self.FIELD)
multi = self.getParameterValue(self.MULTI)
count = self.getParameterValue(self.COUNT)
fields = self.getParameterValue(self.FIELDS)
querystart = '-dialect sqlite -sql "SELECT ST_Union(' + geometry + ')'
queryend = ' FROM ' + layername + ' GROUP BY ' + field + '"'
if fields:
queryfields = ",*"
else:
queryfields = "," + field
if count:
querycount = ", COUNT(" + geometry + ") AS count"
else:
querycount = ""
if stats:
querystats = ", SUM(" + statsatt + ") AS sum_diss, MIN(" + statsatt + ") AS min_diss, MAX(" + statsatt + ") AS max_diss, AVG(" + statsatt + ") AS avg_diss"
else:
querystats = ""
if area:
queryarea = ", SUM(ST_area(" + geometry + ")) AS area_diss, ST_perimeter(ST_union(" + geometry + ")) AS peri_diss"
else:
queryarea = ""
count = self.getParameterValue(self.COUNT)
area = self.getParameterValue(self.AREA)
stats = self.getParameterValue(self.STATS)
statsatt = self.getParameterValue(self.STATSATT)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = ogrLayerName(inLayer)

query = querystart + queryfields + querycount + querystats + queryarea + queryend
output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
options = str(self.getParameterValue(self.OPTIONS))

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(ogrLayerName(inLayer))
arguments.append(query)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

sql = "SELECT ST_Union('{}')".format(geometry)

sqlOpts = ''
if fields:
sqlOpts += ',*'
else:
sqlOpts += ',{}'.format(field)

if count:
sqlOpts += ", COUNT('{}') AS count".format(geometry)

if stats:
sqlOpts += ", SUM('{0}') AS sum_diss, MIN('{0}') AS min_diss, MAX('{0}') AS max_diss, AVG('{0}') AS avg_diss".format(statsatt)

if area:
sqlOpts += ", SUM(ST_Area('{0}')) AS area_diss, ST_Perimeter(ST_Union('{0}')) AS peri_diss".format(geometry)

sql = '{}{} FROM {} GROUP BY {}'.format(sql, sqlOpts, layername, field)

arguments.append(sql)

if not multi:
arguments.append('-explodecollections')

if len(options) > 0:
if options is not None and len(options) > 0:
arguments.append(options)

commands = []
@@ -143,4 +147,4 @@ def getConsoleCommands(self):
return commands

def commandName(self):
return "ogr2ogr"
return 'ogr2ogr'
@@ -80,7 +80,6 @@ def getConsoleCommands(self):
arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(ogrLayerName(inLayer))

arguments.append('-dialect sqlite -sql "SELECT ST_Line_Interpolate_Point(')
arguments.append(geometry)
@@ -27,6 +27,7 @@

from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
@@ -62,8 +63,10 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.GEOMETRY,
self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
'geometry', optional=False))
self.addParameter(ParameterString(self.RADIUS,
self.tr('Buffer distance'), '1000', optional=False))
self.addParameter(ParameterNumber(self.RADIUS,
self.tr('Buffer distance'),
0.0, 99999999.999999, 1000.0,
optional=False))
self.addParameter(ParameterSelection(self.LEFTRIGHT,
self.tr('Buffer side'), self.LEFTRIGHTLIST, 0))
self.addParameter(ParameterBoolean(self.DISSOLVEALL,
@@ -100,7 +103,6 @@ def getConsoleCommands(self):
arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(layername)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')
@@ -118,7 +120,7 @@ def getConsoleCommands(self):
if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
if options is not None and len(options.strip()) > 0:
arguments.append(options)

commands = []
@@ -383,7 +383,7 @@ def checkGrassIsInstalled(ignorePreviousState=False):
points(),
False,
False,
'270778.60198,270855.745301,4458921.97814,4458983.8488',
'None',
-1,
0.0001,
0,
@@ -363,7 +363,7 @@ def checkGrass7IsInstalled(ignorePreviousState=False):
points(),
False,
False,
'270778.60198,270855.745301,4458921.97814,4458983.8488',
'None',
-1,
0.0001,
0,
@@ -75,7 +75,6 @@ def test_algorithms(self):
This is the main test function. All others will be executed based on the definitions in testdata/algorithm_tests.yaml
"""
ver = processing.version()
print("Processing {}.{}.{}".format(ver / 10000, ver / 100 % 100, ver % 100))
with open(os.path.join(processingTestDataPath(), self.test_definition_file()), 'r') as stream:
algorithm_tests = yaml.load(stream)

@@ -1,8 +1,8 @@
FILE(GLOB PY_FILES *.py)
FILE(GLOB TEST_DATA_FILES data/*)
FILE(GLOB TEST_DATA_FILES testdata/points.* testdata/table.dbf)

PLUGIN_INSTALL(processing tests ${PY_FILES})
PLUGIN_INSTALL(processing tests/data ${TEST_DATA_FILES})
PLUGIN_INSTALL(processing tests/testdata ${TEST_DATA_FILES})

IF(ENABLE_TESTS)
INCLUDE(UsePythonTest)
@@ -74,32 +74,32 @@ def test_getConnectionString(self):
cs = obj.getConnectionString()
# NOTE: defaults are debatable, see
# https://github.com/qgis/QGIS/pull/3607#issuecomment-253971020
self.assertEquals(obj.getConnectionString(),
"host=localhost port=5432 active_schema=public")
self.assertEqual(obj.getConnectionString(),
"host=localhost port=5432 active_schema=public")

obj.setParameterValue('HOST', 'remote')
self.assertEquals(obj.getConnectionString(),
"host=remote port=5432 active_schema=public")
self.assertEqual(obj.getConnectionString(),
"host=remote port=5432 active_schema=public")

obj.setParameterValue('HOST', '')
self.assertEquals(obj.getConnectionString(),
"port=5432 active_schema=public")
self.assertEqual(obj.getConnectionString(),
"port=5432 active_schema=public")

obj.setParameterValue('PORT', '5555')
self.assertEquals(obj.getConnectionString(),
"port=5555 active_schema=public")
self.assertEqual(obj.getConnectionString(),
"port=5555 active_schema=public")

obj.setParameterValue('PORT', '')
self.assertEquals(obj.getConnectionString(),
"active_schema=public")
self.assertEqual(obj.getConnectionString(),
"active_schema=public")

obj.setParameterValue('USER', 'usr')
self.assertEquals(obj.getConnectionString(),
"active_schema=public user=usr")
self.assertEqual(obj.getConnectionString(),
"active_schema=public user=usr")

obj.setParameterValue('PASSWORD', 'pwd')
self.assertEquals(obj.getConnectionString(),
"password=pwd active_schema=public user=usr")
self.assertEqual(obj.getConnectionString(),
"password=pwd active_schema=public user=usr")


if __name__ == '__main__':
@@ -44,7 +44,7 @@
ParameterExpression,
getParameterFromString)
from processing.tools import dataobjects
from processing.tests.TestData import points2
from processing.tests.TestData import points

from qgis.core import (QgsRasterLayer,
QgsVectorLayer)
@@ -608,7 +608,7 @@ class ParameterTableFieldTest(unittest.TestCase):

def testOptional(self):
parent_name = 'test_parent_layer'
test_data = points2()
test_data = points()
test_layer = QgsVectorLayer(test_data, parent_name, 'ogr')
parent = ParameterVector(parent_name, parent_name)
parent.setValue(test_layer)

0 comments on commit 6e9631e

Please sign in to comment.
You can’t perform that action at this time.