Skip to content

Commit

Permalink
fix some test cases of minOccurs=0 auto-fixed with defaultValue prese…
Browse files Browse the repository at this point in the history
…nt (relates to geopython/pywps#625)
  • Loading branch information
fmigneault committed Sep 14, 2021
1 parent ea88cf2 commit 574a57c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
38 changes: 24 additions & 14 deletions tests/functional/test_wps_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,28 +1817,32 @@ def test_enum_array_and_multi_format_inputs_from_wps_xml_reference(self):
assert "format" not in pkg["inputs"][0]
assert isinstance(pkg["inputs"][0]["type"], list)
# single entry of enum allowed values
assert len(pkg["inputs"][0]["type"]) == 2, "single type and array type of same base"
assert isinstance(pkg["inputs"][0]["type"][0], dict), "enum base type expected since allowed values"
assert pkg["inputs"][0]["type"][0]["type"] == "enum"
assert isinstance(pkg["inputs"][0]["type"][0]["symbols"], list)
assert len(pkg["inputs"][0]["type"][0]["symbols"]) == 220
assert all(isinstance(s, str) for s in pkg["inputs"][0]["type"][0]["symbols"])
assert len(pkg["inputs"][0]["type"]) == 3, "default value (null) + single type + array type of same base"
assert pkg["inputs"][0]["type"][0] == "null", "XML defaultValue should result in 'null' as valid unspecified"
assert "default" in pkg["inputs"][0]
assert pkg["inputs"][0]["default"] == "DEU", "CWL default value should match extracted defaultValue from XML"
assert isinstance(pkg["inputs"][0]["type"][1], dict), "enum base type expected since allowed values"
assert pkg["inputs"][0]["type"][1]["type"] == "enum"
assert isinstance(pkg["inputs"][0]["type"][1]["symbols"], list)
assert len(pkg["inputs"][0]["type"][1]["symbols"]) == 220
assert all(isinstance(s, str) for s in pkg["inputs"][0]["type"][1]["symbols"])
# array type of same enum allowed values
assert pkg["inputs"][0]["type"][1]["type"] == "array"
assert pkg["inputs"][0]["type"][1]["items"]["type"] == "enum"
assert isinstance(pkg["inputs"][0]["type"][1]["items"]["symbols"], list)
assert len(pkg["inputs"][0]["type"][1]["items"]["symbols"]) == 220
assert all(isinstance(s, str) for s in pkg["inputs"][0]["type"][1]["items"]["symbols"])
assert pkg["inputs"][0]["type"][2]["type"] == "array"
assert pkg["inputs"][0]["type"][2]["items"]["type"] == "enum"
assert isinstance(pkg["inputs"][0]["type"][2]["items"]["symbols"], list)
assert len(pkg["inputs"][0]["type"][2]["items"]["symbols"]) == 220
assert all(isinstance(s, str) for s in pkg["inputs"][0]["type"][2]["items"]["symbols"])
# second input
assert pkg["inputs"][1]["id"] == "mosaic"
assert pkg["inputs"][1]["default"] == "null"
assert "format" not in pkg["inputs"][1]
assert isinstance(pkg["inputs"][1]["type"], list), "default 'null' result type formed with it"
assert len(pkg["inputs"][1]["type"]) == 2
assert pkg["inputs"][1]["type"][0] == "null"
assert pkg["inputs"][1]["type"][0] == "null", "CWL omitted input expect from minOccurs=0 from WPS input"
assert pkg["inputs"][1]["type"][1] == "boolean"
assert pkg["inputs"][2]["id"] == "resource"
assert "default" not in pkg["inputs"][2]
assert "default" not in pkg["inputs"][2], \
"WPS 'default format media-type' with minOccurs=1 must not result in CWL input with 'default' value"
assert isinstance(pkg["inputs"][2]["type"], list), "single and array File"
assert len(pkg["inputs"][2]["type"]) == 2
assert pkg["inputs"][2]["type"][0] == "File", "single File type"
Expand All @@ -1861,8 +1865,14 @@ def test_enum_array_and_multi_format_inputs_from_wps_xml_reference(self):
assert proc["inputs"][0]["title"] == "Region"
assert "abstract" not in proc["inputs"][0], "Field 'abstract' should be replaced by 'description'."
assert proc["inputs"][0]["description"] == "Country code, see ISO-3166-3"
assert proc["inputs"][0]["minOccurs"] == 1
assert proc["inputs"][0]["minOccurs"] == 0, \
"Real XML indicates 'minOccurs=1' but also has 'defaultValue', Weaver should correct it."
assert proc["inputs"][0]["maxOccurs"] == 220
assert "literalDataDomains" in proc["inputs"][0]
assert "defaultValue" in proc["inputs"][0]["literalDataDomains"][0]
assert len(proc["inputs"][0]["literalDataDomains"][0]["valueDefinition"]) == 220, \
"List of all 220 region abbreviation explicitly provided is expected."
assert proc["inputs"][0]["literalDataDomains"][0]["defaultValue"] == "DEU"
assert "formats" not in proc["inputs"][0]
assert proc["inputs"][1]["id"] == "mosaic"
assert proc["inputs"][1]["title"] == "Union of multiple regions"
Expand Down
1 change: 1 addition & 0 deletions tests/processes/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from weaver.processes.convert import (
DEFAULT_FORMAT,
PACKAGE_ARRAY_MAX_SIZE,
any2cwl_io,
cwl2wps_io,
is_cwl_array_type,
is_cwl_enum_type,
Expand Down
4 changes: 2 additions & 2 deletions tests/processes/test_wps_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_stdout_stderr_logging_for_commandline_tool_success():
Execute a process and assert that stdout is correctly logged to log file upon successful process execution.
"""
with contextlib.ExitStack() as stack:
xml_file = stack.enter_context(tempfile.NamedTemporaryFile(suffix=".xml"))
xml_file = stack.enter_context(tempfile.NamedTemporaryFile(suffix=".xml")) # noqa
workdir = stack.enter_context(tempfile.TemporaryDirectory())
process = MockProcess(shell_command="echo")
wps_package_instance = MockWpsPackage(identifier=process["id"], title=process["title"],
Expand All @@ -273,7 +273,7 @@ def test_stdout_stderr_logging_for_commandline_tool_failure():
Execute a process and assert that stderr is correctly logged to log file upon failing process execution.
"""
with contextlib.ExitStack() as stack:
xml_file = stack.enter_context(tempfile.NamedTemporaryFile(suffix=".xml"))
xml_file = stack.enter_context(tempfile.NamedTemporaryFile(suffix=".xml")) # noqa
workdir = stack.enter_context(tempfile.TemporaryDirectory())
process = MockProcess(shell_command="not_existing_command")
wps_package_instance = MockWpsPackage(identifier=process["id"], title=process["title"],
Expand Down
6 changes: 3 additions & 3 deletions weaver/processes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def ows2json_io(ows_io):
if fmt["default"]:
break

# fix inconsistencies of some process descriptions, both with minOccurs=1 and default format
if fmt_default:
json_io["min_occurs"] = 0
# NOTE:
# Don't apply 'minOccurs=0' as in below literal case because default 'format' does not imply that unspecified
# input is valid, but rather that given an input without explicit 'format' specified, that 'default' is used.
return json_io

# add value contrains specifications if missing
Expand Down

0 comments on commit 574a57c

Please sign in to comment.