When running algorithm tests, if two parameters share the same

layer source, ensure that the actual parameter values point
to the same layer
This commit is contained in:
Nyall Dawson 2017-07-01 15:43:47 +10:00
parent d9fca48217
commit 05364aa5f0
2 changed files with 7 additions and 2 deletions

View File

@ -77,8 +77,6 @@ def processingTestDataPath():
class AlgorithmsTest(object): class AlgorithmsTest(object):
in_place_layers = {}
def test_algorithms(self): def test_algorithms(self):
""" """
This is the main test function. All others will be executed based on the definitions in testdata/algorithm_tests.yaml This is the main test function. All others will be executed based on the definitions in testdata/algorithm_tests.yaml
@ -96,6 +94,7 @@ class AlgorithmsTest(object):
:param name: The identifier name used in the test output heading :param name: The identifier name used in the test output heading
:param defs: A python dict containing a test algorithm definition :param defs: A python dict containing a test algorithm definition
""" """
self.vector_layer_params = {}
QgsProject.instance().removeAllMapLayers() QgsProject.instance().removeAllMapLayers()
params = self.load_params(defs['params']) params = self.load_params(defs['params'])
@ -216,7 +215,11 @@ class AlgorithmsTest(object):
self.in_place_layers[id] = filepath self.in_place_layers[id] = filepath
if param['type'] in ('vector', 'table'): if param['type'] in ('vector', 'table'):
if filepath in self.vector_layer_params:
return self.vector_layer_params[filepath]
lyr = QgsVectorLayer(filepath, param['name'], 'ogr', False) lyr = QgsVectorLayer(filepath, param['name'], 'ogr', False)
self.vector_layer_params[filepath] = lyr
elif param['type'] == 'raster': elif param['type'] == 'raster':
lyr = QgsRasterLayer(filepath, param['name'], 'gdal', False) lyr = QgsRasterLayer(filepath, param['name'], 'gdal', False)

View File

@ -64,6 +64,8 @@ class TestQgisAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
from processing.core.Processing import Processing from processing.core.Processing import Processing
Processing.initialize() Processing.initialize()
cls.cleanup_paths = [] cls.cleanup_paths = []
cls.in_place_layers = {}
cls.vector_layer_params = {}
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):