Skip to content

Commit

Permalink
Add new test type "regex" to processing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Feb 23, 2016
1 parent e0ffd92 commit 3f10553
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 21 deletions.
10 changes: 8 additions & 2 deletions python/plugins/processing/tests/AlgorithmsTestBase.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@


import qgis import qgis
import os import os
import shutil
import yaml import yaml
import nose2 import nose2
import gdal import gdal
import hashlib import hashlib
import tempfile import tempfile
import re


from osgeo.gdalconst import GA_ReadOnly from osgeo.gdalconst import GA_ReadOnly


Expand Down Expand Up @@ -123,7 +123,7 @@ def load_result_param(self, param):
Loads a result parameter. Creates a temporary destination where the result should go to and returns this location Loads a result parameter. Creates a temporary destination where the result should go to and returns this location
so it can be sent to the algorithm as parameter. so it can be sent to the algorithm as parameter.
""" """
if param['type'] in ['vector', 'file']: if param['type'] in ['vector', 'file', 'regex']:
outdir = tempfile.mkdtemp() outdir = tempfile.mkdtemp()
self.cleanup_paths.append(outdir) self.cleanup_paths.append(outdir)
basename = os.path.basename(param['name']) basename = os.path.basename(param['name'])
Expand Down Expand Up @@ -191,6 +191,12 @@ def check_results(self, results, expected):
result_filepath = results[id] result_filepath = results[id]


self.assertFilesEqual(expected_filepath, result_filepath) self.assertFilesEqual(expected_filepath, result_filepath)
elif 'regex' == expected_result['type']:
with open(results[id], 'r') as file:
data = file.read()

for rule in expected_result.get('rules', []):
self.assertRegexpMatches(data, rule)




if __name__ == '__main__': if __name__ == '__main__':
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
<pre>Had to open data source read-only.
INFO: Open of `/home/mku/dev/cpp/qgis/QGIS/python/plugins/processing/tests/testdata/lines.gml'
using driver `GML' successful.

Layer name: lines
Geometry: Line String
Feature Count: 6
Extent: (-1.000000, -3.000000) - (11.000000, 5.000000)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
fid: String (0.0) NOT NULL
</pre>
54 changes: 35 additions & 19 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
Original file line number Original file line Diff line number Diff line change
@@ -1,27 +1,43 @@
# See ../README.md for a description of the file format # See ../README.md for a description of the file format


tests: tests:
- algorithm: gdalogr:rasterize # MK: 23.2.2016 / Fails on travis:OSX
name: Test (gdalogr:rasterize) # - algorithm: gdalogr:rasterize
# name: Test (gdalogr:rasterize)
# params:
# BIGTIFF: 0
# COMPRESS: 4
# DIMENSIONS: 0
# EXTRA: ""
# FIELD: "Bfloatval"
# HEIGHT: 100
# INPUT:
# name: multipolys.gml
# type: vector
# JPEGCOMPRESSION: 75
# NO_DATA: -9999
# PREDICTOR: 1
# RTYPE: 5
# TFW: False
# TILED: False
# WIDTH: 100
# ZLEVEL: 6
# results:
# OUTPUT:
# hash: f1fedeb6782f9389cf43590d4c85ada9155ab61fef6dc285aaeb54d6
# type: rasterhash
- algorithm: gdalogr:information
name: GDAL ogrinfo
params: params:
BIGTIFF: 0
COMPRESS: 4
DIMENSIONS: 0
EXTRA: ""
FIELD: "Bfloatval"
HEIGHT: 100
INPUT: INPUT:
name: multipolys.gml name: lines.gml
type: vector type: vector
JPEGCOMPRESSION: 75 SUMMARY_ONLY: 'True'
NO_DATA: -9999
PREDICTOR: 1
RTYPE: 5
TFW: False
TILED: False
WIDTH: 100
ZLEVEL: 6
results: results:
OUTPUT: OUTPUT:
hash: f1fedeb6782f9389cf43590d4c85ada9155ab61fef6dc285aaeb54d6 name: expected/gdal/layer_info.html
type: rasterhash type: regex
rules:
- 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
- 'Geometry: Line String'
- 'Feature Count: 6'

0 comments on commit 3f10553

Please sign in to comment.