Add file comparison to processing tests

And a test for basic numeric statistics
This commit is contained in:
Matthias Kuhn 2016-02-21 13:15:21 +01:00
parent f6995646f2
commit 20fc30b0fe
3 changed files with 49 additions and 10 deletions

View File

@ -137,10 +137,10 @@ class TestAlgorithms(unittest.TestCase):
def load_result_param(self, param):
"""
Lodas 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.
"""
if param['type'] == 'vector':
if param['type'] in ['vector', 'file']:
outdir = tempfile.mkdtemp()
self.cleanup_paths.append(outdir)
basename = os.path.basename(param['name'])
@ -153,14 +153,7 @@ class TestAlgorithms(unittest.TestCase):
"""
Loads a layer which was specified as parameter.
"""
prefix = processingTestDataPath()
try:
if param['location'] == 'qgs':
prefix = unitTestDataPath()
except KeyError:
pass
filepath = os.path.join(prefix, param['name'])
filepath = self.filepath_from_param(param)
if param['type'] == 'vector':
lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
@ -171,6 +164,16 @@ class TestAlgorithms(unittest.TestCase):
QgsMapLayerRegistry.instance().addMapLayer(lyr)
return lyr
def filepath_from_param(self, param):
"""
Creates a filepath from a param
"""
prefix = processingTestDataPath()
if 'location' in param and param['location'] == 'qgs':
prefix = unitTestDataPath()
return os.path.join(prefix, param['name'])
def check_results(self, results, expected):
"""
Checks if result produced by an algorithm matches with the expected specification.
@ -197,6 +200,11 @@ class TestAlgorithms(unittest.TestCase):
strhash = hashlib.sha224(dataset.ReadAsArray(0).data).hexdigest()
self.assertEqual(strhash, expected_result['hash'])
elif 'file' == expected_result['type']:
expected_filepath = self.filepath_from_param(expected_result)
result_filepath = results[id]
self.assertFilesEqual(expected_filepath, result_filepath)
if __name__ == '__main__':

View File

@ -63,3 +63,13 @@ tests:
OUTPUT:
name: expected/polys_to_lines.gml
type: vector
- algorithm: qgis:basicstatisticsfornumericfields
name: Test (qgis:basicstatisticsfornumericfields)
params:
- name: multipolys.gml
type: vector
- 'Bfloatval'
results:
OUTPUT_HTML_FILE:
name: expected/basic_statistics_numeric_float.html
type: file

View File

@ -0,0 +1,21 @@
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>
<p>Analyzed layer: multipolys.gml</p>
<p>Analyzed field: Bfloatval</p>
<p>Count: 3</p>
<p>Unique values: 3</p>
<p>Minimum value: -0.123</p>
<p>Maximum value: 0.123</p>
<p>Range: 0.246</p>
<p>Sum: 0.0</p>
<p>Mean value: 0.0</p>
<p>Median value: 0.0</p>
<p>Standard deviation: 0.100429079454</p>
<p>Coefficient of Variation: 0</p>
<p>Minority (rarest occurring value): -0.123</p>
<p>Majority (most frequently occurring value): -0.123</p>
<p>First quartile: -0.0615</p>
<p>Third quartile: 0.0615</p>
<p>NULL (missed) values: 1</p>
<p>Interquartile Range (IQR): 0.123</p>
</body></html>