Skip to content

Commit

Permalink
Merge pull request #43 from pacificclimate/i40-refactor-run-wps-process
Browse files Browse the repository at this point in the history
Synchronize run_wps_process throughout all the test files
  • Loading branch information
sum1lim authored Jun 23, 2020
2 parents 375fb8a + 42c3525 commit 064d4ac
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 76 deletions.
17 changes: 16 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pkg_resources import resource_filename
from pywps import Service
from pywps.app.basic import get_xpath_ns
from pywps.tests import WpsClient, WpsTestResponse
from pywps.tests import WpsClient, WpsTestResponse, assert_response_success

import pkg_resources

Expand Down Expand Up @@ -86,3 +87,17 @@ def get_output(doc):
output[identifier_el.text] = data_el[0].text

return output


def run_wps_process(process, params):
client = client_for(Service(processes=[process]))
datainputs = params
resp = client.get(
service="wps",
request="Execute",
version="1.0.0",
identifier=process.identifier,
datainputs=datainputs,
)

assert_response_success(resp)
58 changes: 18 additions & 40 deletions tests/test_wps_generate_climos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
from pywps import Service
from pywps.tests import assert_response_success

from .common import client_for, TESTDATA
from .common import TESTDATA, run_wps_process
from thunderbird.processes.wps_generate_climos import GenerateClimos


def run_wps_generate_climos(netcdf, datainputs):
client = client_for(Service(processes=[GenerateClimos()]))

resp = client.get(
service="wps",
request="Execute",
version="1.0.0",
identifier="generate_climos",
datainputs=datainputs,
)
assert_response_success(resp)
def build_params(netcdf, kwargs):
return (
"netcdf=@xlink:href={0};"
"operation={operation};"
"climo={climo};"
"resolutions={resolutions};"
"convert_longitudes={convert_longitudes};"
"split_vars={split_vars};"
"split_intervals={split_intervals};"
"dry_run={dry_run};"
).format(netcdf, **kwargs)


@pytest.mark.online
Expand Down Expand Up @@ -52,18 +52,8 @@ def run_wps_generate_climos(netcdf, datainputs):
],
)
def test_wps_gen_climos_opendap(netcdf, kwargs):
datainputs = (
"netcdf=@xlink:href={0};"
"operation={operation};"
"climo={climo};"
"resolutions={resolutions};"
"convert_longitudes={convert_longitudes};"
"split_vars={split_vars};"
"split_intervals={split_intervals};"
"dry_run={dry_run};"
).format(netcdf, **kwargs)

run_wps_generate_climos(netcdf, datainputs)
params = build_params(netcdf, kwargs)
run_wps_process(GenerateClimos(), params)


# running generate_climos on climo files is againt the purpose of the program
Expand Down Expand Up @@ -103,18 +93,8 @@ def test_wps_gen_climos_opendap(netcdf, kwargs):
],
)
def test_wps_gen_climos_local_nc(netcdf, kwargs):
datainputs = (
"netcdf=@xlink:href={0};"
"operation={operation};"
"climo={climo};"
"resolutions={resolutions};"
"convert_longitudes={convert_longitudes};"
"split_vars={split_vars};"
"split_intervals={split_intervals};"
"dry_run={dry_run};"
).format(netcdf, **kwargs)

run_wps_generate_climos(netcdf, datainputs)
params = build_params(netcdf, kwargs)
run_wps_process(GenerateClimos(), params)


@pytest.mark.parametrize(
Expand All @@ -124,9 +104,7 @@ def test_wps_gen_climos_local_nc(netcdf, kwargs):
("kwargs"), [({"operation": "mean", "dry_run": "False",}),],
)
def test_missing_arguments(netcdf, kwargs):
client = client_for(Service(processes=[GenerateClimos()]))
datainputs = (
params = (
"netcdf=@xlink:href={0};" "operation={operation};" "dry_run={dry_run};"
).format(netcdf, **kwargs)

run_wps_generate_climos(netcdf, datainputs)
run_wps_process(GenerateClimos(), params)
33 changes: 14 additions & 19 deletions tests/test_wps_generate_prsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
from pywps import Service
from pywps.tests import assert_response_success

from .common import client_for, TESTDATA
from .common import TESTDATA, run_wps_process
from thunderbird.processes.wps_generate_prsn import GeneratePrsn


def run_wps_process(kwargs):
"""Run generate_prsn process using data inputs given by kwargs"""
client = client_for(Service(processes=[GeneratePrsn()]))
def build_params(kwargs):
if (
"chunk_size" in kwargs.keys() and "output_file" in kwargs.keys()
): # Not using default values
datainputs = (
return (
"prec=@xlink:href={prec};"
"tasmin=@xlink:href={tasmin};"
"tasmax=@xlink:href={tasmax};"
Expand All @@ -22,20 +20,12 @@ def run_wps_process(kwargs):
"output_file={output_file};"
).format(**kwargs)
else:
datainputs = (
return (
"prec=@xlink:href={prec};"
"tasmin=@xlink:href={tasmin};"
"tasmax=@xlink:href={tasmax};"
"dry_run={dry_run};"
).format(**kwargs)
resp = client.get(
service="wps",
request="Execute",
version="1.0.0",
identifier="generate_prsn",
datainputs=datainputs,
)
assert_response_success(resp)


@pytest.mark.parametrize(
Expand All @@ -52,7 +42,8 @@ def run_wps_process(kwargs):
],
)
def test_default_local(kwargs):
run_wps_process(kwargs)
params = build_params(kwargs)
run_wps_process(GeneratePrsn(), params)


@pytest.mark.parametrize(
Expand All @@ -71,7 +62,8 @@ def test_default_local(kwargs):
],
)
def test_run_local(kwargs):
run_wps_process(kwargs)
params = build_params(kwargs)
run_wps_process(GeneratePrsn(), params)


@pytest.mark.online
Expand All @@ -89,7 +81,8 @@ def test_run_local(kwargs):
],
)
def test_default_opendap(kwargs):
run_wps_process(kwargs)
params = build_params(kwargs)
run_wps_process(GeneratePrsn(), params)


@pytest.mark.online
Expand All @@ -109,7 +102,8 @@ def test_default_opendap(kwargs):
],
)
def test_run_opendap(kwargs):
run_wps_process(kwargs)
params = build_params(kwargs)
run_wps_process(GeneratePrsn(), params)


@pytest.mark.online
Expand Down Expand Up @@ -139,4 +133,5 @@ def test_run_opendap(kwargs):
],
)
def test_run_mixed(kwargs):
run_wps_process(kwargs)
params = build_params(kwargs)
run_wps_process(GeneratePrsn(), params)
23 changes: 7 additions & 16 deletions tests/test_wps_update_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@
from pywps import Service
from pywps.tests import assert_response_success

from .common import client_for, TESTDATA
from .common import TESTDATA, run_wps_process
from thunderbird.processes.wps_update_metadata import UpdateMetadata
import owslib.wps
import os


def run_wps_update_metadata(netcdf, updates):
client = client_for(Service(processes=[UpdateMetadata()]))
datainputs = ("netcdf=@xlink:href={0};" "updates={1};").format(netcdf, updates)

resp = client.get(
service="wps",
request="Execute",
version="1.0.0",
identifier="update_metadata",
datainputs=datainputs,
)

assert_response_success(resp)
def build_params(netcdf, updates):
return ("netcdf=@xlink:href={0};" "updates={1};").format(netcdf, updates)


@pytest.mark.online
Expand All @@ -32,7 +21,8 @@ def run_wps_update_metadata(netcdf, updates):
("updates"), TESTDATA["test_yaml"],
)
def test_wps_update_metadata_opendap(netcdf, updates):
run_wps_update_metadata(netcdf, updates)
params = build_params(netcdf, updates)
run_wps_process(UpdateMetadata(), params)


@pytest.mark.parametrize(
Expand All @@ -42,4 +32,5 @@ def test_wps_update_metadata_opendap(netcdf, updates):
("updates"), TESTDATA["test_yaml"],
)
def test_wps_update_metadata_netcdf(netcdf, updates):
run_wps_update_metadata(netcdf, updates)
params = build_params(netcdf, updates)
run_wps_process(UpdateMetadata(), params)

0 comments on commit 064d4ac

Please sign in to comment.