Skip to content
Permalink
Browse files

Allow using gpkg in processing tests

  • Loading branch information
m-kuhn committed Oct 25, 2018
1 parent b64e72a commit 2a973fc0b681f71ba77be5705b949802fb5432a0
Showing with 28 additions and 9 deletions.
  1. +28 −9 python/plugins/processing/tests/AlgorithmsTestBase.py
@@ -36,6 +36,7 @@
import glob
import hashlib
import tempfile
import re

from osgeo.gdalconst import GA_ReadOnly
from numpy import nan_to_num
@@ -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()
@@ -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
@@ -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']:
@@ -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):
"""

0 comments on commit 2a973fc

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