Skip to content

Commit

Permalink
Allow using gpkg in processing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 31, 2018
1 parent b64e72a commit 2a973fc
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions python/plugins/processing/tests/AlgorithmsTestBase.py
Expand Up @@ -36,6 +36,7 @@
import glob
import hashlib
import tempfile
import re

from osgeo.gdalconst import GA_ReadOnly
from numpy import nan_to_num
Expand Down Expand Up @@ -199,7 +200,8 @@ def load_result_param(self, param):
basename = os.path.basename(param['name'])
else:
basename = os.path.basename(param['name'][0])
filepath = os.path.join(outdir, basename)

filepath = self.uri_path_join(outdir, basename)
return filepath
elif param['type'] == 'rasterhash':
outdir = tempfile.mkdtemp()
Expand All @@ -215,13 +217,14 @@ def load_result_param(self, param):

def load_layers(self, id, param):
layers = []
if param['type'] in ('vector', 'table') and isinstance(param['name'], str):
layers.append(self.load_layer(id, param))
elif param['type'] in ('vector', 'table'):
for n in param['name']:
layer_param = deepcopy(param)
layer_param['name'] = n
layers.append(self.load_layer(id, layer_param))
if param['type'] in ('vector', 'table'):
if isinstance(param['name'], str) or 'uri' in param:
layers.append(self.load_layer(id, param))
else:
for n in param['name']:
layer_param = deepcopy(param)
layer_param['name'] = n
layers.append(self.load_layer(id, layer_param))
else:
layers.append(self.load_layer(id, param))
return layers
Expand All @@ -230,6 +233,7 @@ def load_layer(self, id, param):
"""
Loads a layer which was specified as parameter.
"""

filepath = self.filepath_from_param(param)

if 'in_place' in param and param['in_place']:
Expand Down Expand Up @@ -268,7 +272,22 @@ def filepath_from_param(self, param):
if 'location' in param and param['location'] == 'qgs':
prefix = unitTestDataPath()

return os.path.join(prefix, param['name'])
if 'uri' in param:
path = param['uri']
else:
path = param['name']

return self.uri_path_join(prefix, path)

def uri_path_join(self, prefix, filepath):
if filepath.startswith('ogr:'):
if not prefix[-1] == os.path.sep:
prefix += os.path.sep
filepath = re.sub(r"dbname='", "dbname='{}".format(prefix), filepath)
else:
filepath = os.path.join(prefix, filepath)

return filepath

def check_results(self, results, context, params, expected):
"""
Expand Down

0 comments on commit 2a973fc

Please sign in to comment.